From b3ab68c31f6c8bc4decb2f23e35b252b87c77100 Mon Sep 17 00:00:00 2001 From: Hans Hasselberg Date: Mon, 8 May 2023 13:20:13 +0200 Subject: [PATCH 1/7] update hcp-sdk-go --- go.mod | 2 +- go.sum | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 333b699300f..2b672b7de12 100644 --- a/go.mod +++ b/go.mod @@ -61,7 +61,7 @@ require ( github.com/hashicorp/golang-lru v0.5.4 github.com/hashicorp/hcl v1.0.0 github.com/hashicorp/hcp-scada-provider v0.2.3 - github.com/hashicorp/hcp-sdk-go v0.40.1-0.20230404193545-846aea419cd1 + github.com/hashicorp/hcp-sdk-go v0.44.1-0.20230508124639-28da4c5b03f3 github.com/hashicorp/hil v0.0.0-20200423225030-a18a1cd20038 github.com/hashicorp/memberlist v0.5.0 github.com/hashicorp/raft v1.5.0 diff --git a/go.sum b/go.sum index 2bb892bc9ca..34ebe9b4160 100644 --- a/go.sum +++ b/go.sum @@ -606,6 +606,10 @@ github.com/hashicorp/hcp-scada-provider v0.2.3 h1:AarYR+/Pcv+cMvPdAlb92uOBmZfEH6 github.com/hashicorp/hcp-scada-provider v0.2.3/go.mod h1:ZFTgGwkzNv99PLQjTsulzaCplCzOTBh0IUQsPKzrQFo= github.com/hashicorp/hcp-sdk-go v0.40.1-0.20230404193545-846aea419cd1 h1:C1des4/oIeUqQJVUWypnZth19Kg+k01q+V59OVNMB+Q= github.com/hashicorp/hcp-sdk-go v0.40.1-0.20230404193545-846aea419cd1/go.mod h1:hZqky4HEzsKwvLOt4QJlZUrjeQmb4UCZUhDP2HyQFfc= +github.com/hashicorp/hcp-sdk-go v0.44.0 h1:PT5J1g2/wIUxP1C9vY0jyjoEIsduYQD9QYiQagq/iEs= +github.com/hashicorp/hcp-sdk-go v0.44.0/go.mod h1:hZqky4HEzsKwvLOt4QJlZUrjeQmb4UCZUhDP2HyQFfc= +github.com/hashicorp/hcp-sdk-go v0.44.1-0.20230508124639-28da4c5b03f3 h1:9QstZdsLIS6iPyYxQoyymRz8nBw9jMdEbGy29gtgzVQ= +github.com/hashicorp/hcp-sdk-go v0.44.1-0.20230508124639-28da4c5b03f3/go.mod h1:hZqky4HEzsKwvLOt4QJlZUrjeQmb4UCZUhDP2HyQFfc= github.com/hashicorp/hil v0.0.0-20200423225030-a18a1cd20038 h1:n9J0rwVWXDpNd5iZnwY7w4WZyq53/rROeI7OVvLW8Ok= github.com/hashicorp/hil v0.0.0-20200423225030-a18a1cd20038/go.mod h1:n2TSygSNwsLJ76m8qFXTSc7beTb+auJxYdqrnoqwZWE= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= From 9144ed8661036390d483b7da1189b02d5be4abfe Mon Sep 17 00:00:00 2001 From: Hans Hasselberg Date: Tue, 9 May 2023 14:12:11 +0200 Subject: [PATCH 2/7] add version, datacenter and acl info --- agent/consul/server.go | 3 +++ agent/hcp/client.go | 29 ++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/agent/consul/server.go b/agent/consul/server.go index 52236e8b5d0..d3c3044121b 100644 --- a/agent/consul/server.go +++ b/agent/consul/server.go @@ -1995,6 +1995,7 @@ func (s *Server) hcpServerStatus(deps Deps) hcp.StatusCallback { status.LanAddress = s.config.RPCAdvertise.IP.String() status.GossipPort = s.config.SerfLANConfig.MemberlistConfig.AdvertisePort status.RPCPort = s.config.RPCAddr.Port + status.Datacenter = s.config.Datacenter tlsCert := s.tlsConfigurator.Cert() if tlsCert != nil { @@ -2036,6 +2037,8 @@ func (s *Server) hcpServerStatus(deps Deps) hcp.StatusCallback { status.ScadaStatus = deps.HCP.Provider.SessionStatus() } + status.ACL.Enabled = s.config.ACLsEnabled + return status, nil } } diff --git a/agent/hcp/client.go b/agent/hcp/client.go index c28e1b9c7f0..c22469eb052 100644 --- a/agent/hcp/client.go +++ b/agent/hcp/client.go @@ -18,6 +18,7 @@ import ( "github.com/hashicorp/consul/agent/hcp/config" "github.com/hashicorp/consul/version" + consulversion "github.com/hashicorp/consul/version" ) // Client interface exposes HCP operations that can be invoked by Consul @@ -41,15 +42,17 @@ type BootstrapConfig struct { } type hcpClient struct { - hc *httptransport.Runtime - cfg config.CloudConfig - gnm hcpgnm.ClientService - resource resource.Resource + hc *httptransport.Runtime + cfg config.CloudConfig + gnm hcpgnm.ClientService + resource resource.Resource + consulVersion string } func NewClient(cfg config.CloudConfig) (Client, error) { client := &hcpClient{ - cfg: cfg, + cfg: cfg, + consulVersion: consulversion.GetHumanVersion(), } var err error @@ -83,7 +86,8 @@ func (c *hcpClient) FetchBootstrap(ctx context.Context) (*BootstrapConfig, error params := hcpgnm.NewAgentBootstrapConfigParamsWithContext(ctx). WithID(c.resource.ID). WithLocationOrganizationID(c.resource.Organization). - WithLocationProjectID(c.resource.Project) + WithLocationProjectID(c.resource.Project). + WithConsulVersion(&c.consulVersion) resp, err := c.gnm.AgentBootstrapConfig(params, nil) if err != nil { @@ -132,10 +136,12 @@ type ServerStatus struct { LanAddress string GossipPort int RPCPort int + Datacenter string Autopilot ServerAutopilot Raft ServerRaft TLS ServerTLSInfo + ACL ServerACLInfo ScadaStatus string } @@ -155,6 +161,10 @@ type ServerRaft struct { TimeSinceLastContact time.Duration } +type ServerACLInfo struct { + Enabled bool +} + type ServerTLSInfo struct { Enabled bool CertExpiry time.Time @@ -169,7 +179,7 @@ func serverStatusToHCP(s *ServerStatus) *gnmmod.HashicorpCloudGlobalNetworkManag if s == nil { return nil } - return &gnmmod.HashicorpCloudGlobalNetworkManager20220215ServerState{ + state := &gnmmod.HashicorpCloudGlobalNetworkManager20220215ServerState{ Autopilot: &gnmmod.HashicorpCloudGlobalNetworkManager20220215AutoPilotInfo{ FailureTolerance: int32(s.Autopilot.FailureTolerance), Healthy: s.Autopilot.Healthy, @@ -199,7 +209,12 @@ func serverStatusToHCP(s *ServerStatus) *gnmmod.HashicorpCloudGlobalNetworkManag }, Version: s.Version, ScadaStatus: s.ScadaStatus, + ACL: &gnmmod.HashicorpCloudGlobalNetworkManager20220215ACLInfo{ + Enabled: s.ACL.Enabled, + }, + Datacenter: s.Datacenter, } + return state } func (c *hcpClient) DiscoverServers(ctx context.Context) ([]string, error) { From f947167e9459467b76a45083b6effe3077a1f9c0 Mon Sep 17 00:00:00 2001 From: Hans Hasselberg Date: Wed, 10 May 2023 22:48:11 +0200 Subject: [PATCH 3/7] fewer changes --- agent/hcp/client.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/agent/hcp/client.go b/agent/hcp/client.go index c22469eb052..71a2d83cfb8 100644 --- a/agent/hcp/client.go +++ b/agent/hcp/client.go @@ -46,13 +46,11 @@ type hcpClient struct { cfg config.CloudConfig gnm hcpgnm.ClientService resource resource.Resource - consulVersion string } func NewClient(cfg config.CloudConfig) (Client, error) { client := &hcpClient{ cfg: cfg, - consulVersion: consulversion.GetHumanVersion(), } var err error @@ -83,11 +81,12 @@ func httpClient(c config.CloudConfig) (*httptransport.Runtime, error) { } func (c *hcpClient) FetchBootstrap(ctx context.Context) (*BootstrapConfig, error) { + version := consulversion.GetHumanVersion() params := hcpgnm.NewAgentBootstrapConfigParamsWithContext(ctx). WithID(c.resource.ID). WithLocationOrganizationID(c.resource.Organization). WithLocationProjectID(c.resource.Project). - WithConsulVersion(&c.consulVersion) + WithConsulVersion(&version) resp, err := c.gnm.AgentBootstrapConfig(params, nil) if err != nil { From 85f27f56717a8d9b439e5a3488e7c876503a8483 Mon Sep 17 00:00:00 2001 From: Hans Hasselberg Date: Wed, 10 May 2023 22:51:22 +0200 Subject: [PATCH 4/7] go mod tidy and lint --- agent/hcp/client.go | 12 ++++++------ go.sum | 4 ---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/agent/hcp/client.go b/agent/hcp/client.go index 71a2d83cfb8..d2e99c60910 100644 --- a/agent/hcp/client.go +++ b/agent/hcp/client.go @@ -42,15 +42,15 @@ type BootstrapConfig struct { } type hcpClient struct { - hc *httptransport.Runtime - cfg config.CloudConfig - gnm hcpgnm.ClientService - resource resource.Resource + hc *httptransport.Runtime + cfg config.CloudConfig + gnm hcpgnm.ClientService + resource resource.Resource } func NewClient(cfg config.CloudConfig) (Client, error) { client := &hcpClient{ - cfg: cfg, + cfg: cfg, } var err error @@ -81,7 +81,7 @@ func httpClient(c config.CloudConfig) (*httptransport.Runtime, error) { } func (c *hcpClient) FetchBootstrap(ctx context.Context) (*BootstrapConfig, error) { - version := consulversion.GetHumanVersion() + version := consulversion.GetHumanVersion() params := hcpgnm.NewAgentBootstrapConfigParamsWithContext(ctx). WithID(c.resource.ID). WithLocationOrganizationID(c.resource.Organization). diff --git a/go.sum b/go.sum index 34ebe9b4160..127c1350bfb 100644 --- a/go.sum +++ b/go.sum @@ -604,10 +604,6 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/hcp-scada-provider v0.2.3 h1:AarYR+/Pcv+cMvPdAlb92uOBmZfEH6ny4+DT+4NY2VQ= github.com/hashicorp/hcp-scada-provider v0.2.3/go.mod h1:ZFTgGwkzNv99PLQjTsulzaCplCzOTBh0IUQsPKzrQFo= -github.com/hashicorp/hcp-sdk-go v0.40.1-0.20230404193545-846aea419cd1 h1:C1des4/oIeUqQJVUWypnZth19Kg+k01q+V59OVNMB+Q= -github.com/hashicorp/hcp-sdk-go v0.40.1-0.20230404193545-846aea419cd1/go.mod h1:hZqky4HEzsKwvLOt4QJlZUrjeQmb4UCZUhDP2HyQFfc= -github.com/hashicorp/hcp-sdk-go v0.44.0 h1:PT5J1g2/wIUxP1C9vY0jyjoEIsduYQD9QYiQagq/iEs= -github.com/hashicorp/hcp-sdk-go v0.44.0/go.mod h1:hZqky4HEzsKwvLOt4QJlZUrjeQmb4UCZUhDP2HyQFfc= github.com/hashicorp/hcp-sdk-go v0.44.1-0.20230508124639-28da4c5b03f3 h1:9QstZdsLIS6iPyYxQoyymRz8nBw9jMdEbGy29gtgzVQ= github.com/hashicorp/hcp-sdk-go v0.44.1-0.20230508124639-28da4c5b03f3/go.mod h1:hZqky4HEzsKwvLOt4QJlZUrjeQmb4UCZUhDP2HyQFfc= github.com/hashicorp/hil v0.0.0-20200423225030-a18a1cd20038 h1:n9J0rwVWXDpNd5iZnwY7w4WZyq53/rROeI7OVvLW8Ok= From 694d065af1a0ca0d0b2d405c6a9afaaa01b7368a Mon Sep 17 00:00:00 2001 From: Hans Hasselberg Date: Thu, 11 May 2023 11:50:03 +0200 Subject: [PATCH 5/7] less code --- agent/hcp/client.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/agent/hcp/client.go b/agent/hcp/client.go index d2e99c60910..058871f0ce9 100644 --- a/agent/hcp/client.go +++ b/agent/hcp/client.go @@ -178,7 +178,7 @@ func serverStatusToHCP(s *ServerStatus) *gnmmod.HashicorpCloudGlobalNetworkManag if s == nil { return nil } - state := &gnmmod.HashicorpCloudGlobalNetworkManager20220215ServerState{ + return &gnmmod.HashicorpCloudGlobalNetworkManager20220215ServerState{ Autopilot: &gnmmod.HashicorpCloudGlobalNetworkManager20220215AutoPilotInfo{ FailureTolerance: int32(s.Autopilot.FailureTolerance), Healthy: s.Autopilot.Healthy, @@ -213,7 +213,6 @@ func serverStatusToHCP(s *ServerStatus) *gnmmod.HashicorpCloudGlobalNetworkManag }, Datacenter: s.Datacenter, } - return state } func (c *hcpClient) DiscoverServers(ctx context.Context) ([]string, error) { From a8ad9a3801ee75f20f97e73723a1ce966a0f137c Mon Sep 17 00:00:00 2001 From: Hans Hasselberg Date: Thu, 11 May 2023 14:13:48 +0200 Subject: [PATCH 6/7] remove duplicated dep --- agent/hcp/client.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/agent/hcp/client.go b/agent/hcp/client.go index 058871f0ce9..4b68774cb3b 100644 --- a/agent/hcp/client.go +++ b/agent/hcp/client.go @@ -18,7 +18,6 @@ import ( "github.com/hashicorp/consul/agent/hcp/config" "github.com/hashicorp/consul/version" - consulversion "github.com/hashicorp/consul/version" ) // Client interface exposes HCP operations that can be invoked by Consul @@ -81,7 +80,7 @@ func httpClient(c config.CloudConfig) (*httptransport.Runtime, error) { } func (c *hcpClient) FetchBootstrap(ctx context.Context) (*BootstrapConfig, error) { - version := consulversion.GetHumanVersion() + version := version.GetHumanVersion() params := hcpgnm.NewAgentBootstrapConfigParamsWithContext(ctx). WithID(c.resource.ID). WithLocationOrganizationID(c.resource.Organization). From 5ad357051bc860f6fd4d21a3514851239e429604 Mon Sep 17 00:00:00 2001 From: Hans Hasselberg Date: Fri, 12 May 2023 16:36:43 +0200 Subject: [PATCH 7/7] fmt --- agent/hcp/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/hcp/client.go b/agent/hcp/client.go index 4b68774cb3b..bd6679a3312 100644 --- a/agent/hcp/client.go +++ b/agent/hcp/client.go @@ -80,7 +80,7 @@ func httpClient(c config.CloudConfig) (*httptransport.Runtime, error) { } func (c *hcpClient) FetchBootstrap(ctx context.Context) (*BootstrapConfig, error) { - version := version.GetHumanVersion() + version := version.GetHumanVersion() params := hcpgnm.NewAgentBootstrapConfigParamsWithContext(ctx). WithID(c.resource.ID). WithLocationOrganizationID(c.resource.Organization).