From d5fcee294d23ca5c39655489cc781a6611703366 Mon Sep 17 00:00:00 2001 From: John Murret Date: Tue, 19 Mar 2024 15:01:54 -0600 Subject: [PATCH 01/16] NET-5879 - consul-template support for sameness groups --- .golangci.yml | 2 +- dependency/dependency.go | 28 ++-- dependency/dependency_test.go | 150 +++++++++++++----- dependency/health_service.go | 71 +++++---- dependency/health_service_test.go | 243 +++++++++++++++++++++++++++--- go.mod | 14 +- go.sum | 40 ++--- template/funcs.go | 2 +- test/helpers.go | 8 + 9 files changed, 428 insertions(+), 130 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index ee9028d50..11aec7c27 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -78,7 +78,7 @@ linters-settings: - github.com/hashicorp/logutils - github.com/hashicorp/nomad/api - github.com/hashicorp/vault/api - - github.com/imdario/mergo + - dario.cat/mergo - github.com/mitchellh/go-homedir - github.com/mitchellh/hashstructure - github.com/mitchellh/mapstructure diff --git a/dependency/dependency.go b/dependency/dependency.go index 72ebb50c6..4a6146a09 100644 --- a/dependency/dependency.go +++ b/dependency/dependency.go @@ -75,18 +75,19 @@ type ServiceTags []string // client-agnostic, and the dependency determines which, if any, of the options // to use. type QueryOptions struct { - AllowStale bool - Datacenter string - Region string - Near string - Choose string - RequireConsistent bool - VaultGrace time.Duration - WaitIndex uint64 - WaitTime time.Duration - ConsulPeer string - ConsulPartition string - ConsulNamespace string + AllowStale bool + Datacenter string + Region string + Near string + Choose string + RequireConsistent bool + VaultGrace time.Duration + WaitIndex uint64 + WaitTime time.Duration + ConsulPeer string + ConsulPartition string + ConsulNamespace string + ConsulSamenessGroup string } func (q *QueryOptions) Merge(o *QueryOptions) *QueryOptions { @@ -184,7 +185,8 @@ func GetConsulQueryOpts(queryMap map[string]string, endpointLabel string) (url.V switch key { case QueryNamespace, QueryPeer, - QueryPartition: + QueryPartition, + QuerySamenessGroup: default: return nil, fmt.Errorf("%s: invalid query parameter key %q in query %q: supported keys: %s,%s,%s", endpointLabel, key, queryRaw, QueryNamespace, QueryPeer, QueryPartition) diff --git a/dependency/dependency_test.go b/dependency/dependency_test.go index 210f7c6eb..4f6fc9336 100644 --- a/dependency/dependency_test.go +++ b/dependency/dependency_test.go @@ -61,15 +61,11 @@ func TestMain(m *testing.M) { Address: testConsul.HTTPAddr, }); err != nil { testConsul.Stop() - testVault.Stop() - testNomad.Stop() Fatalf("failed to create consul client: %v\n", err) } if t, err := test.NewTenancyHelper(clients.Consul()); err != nil { - testConsul.Stop() - testVault.Stop() - testNomad.Stop() + stopTestClients() Fatalf("failed to create tenancy helper: %v\n", err) } else { tenancyHelper = t @@ -86,55 +82,62 @@ func TestMain(m *testing.M) { if err := clients.CreateNomadClient(&CreateNomadClientInput{ Address: "http://127.0.0.1:4646", }); err != nil { - testConsul.Stop() - testVault.Stop() - testNomad.Stop() + stopTestClients() Fatalf("failed to create nomad client: %v\n", err) } testClients = clients if err := testClients.createConsulPartitions(); err != nil { - testConsul.Stop() - testVault.Stop() - testNomad.Stop() + stopTestClients() Fatalf("failed to create consul partitions: %v\n", err) } if err := testClients.createConsulNs(); err != nil { - testConsul.Stop() - testVault.Stop() - testNomad.Stop() + stopTestClients() Fatalf("failed to create consul namespaces: %v\n", err) } setupVaultPKI(clients) if err := testClients.createConsulTestResources(); err != nil { - testConsul.Stop() - testVault.Stop() - testNomad.Stop() + stopTestClients() Fatalf("failed to create consul test resources: %v\n", err) } + if err := testClients.createConsulSamenessGroups(); err != nil { + stopTestClients() + Fatalf("failed to create consul test sameness groups: %v\n", err) + } + // Wait for Nomad initialization to finish if err := <-nomadFuture; err != nil { - testConsul.Stop() - testNomad.Stop() - testVault.Stop() + stopTestClients() Fatalf("failed to start Nomad: %v\n", err) } exit := m.Run() tb.DoCleanup() + stopTestClients() + os.Exit(exit) +} + +func stopTestClients() { testConsul.Stop() testVault.Stop() testNomad.Stop() - os.Exit(exit) } func (c *ClientSet) createConsulTestResources() error { + err := c.createConsulResourcesForTenancies(false) + if err != nil { + return err + } + return c.createConsulResourcesForTenancies(true) +} + +func (c *ClientSet) createConsulResourcesForTenancies(forSamenessGroups bool) error { catalog := testClients.Consul().Catalog() for _, tenancy := range tenancyHelper.TestTenancies() { partition := "" @@ -143,11 +146,16 @@ func (c *ClientSet) createConsulTestResources() error { partition = tenancy.Partition namespace = tenancy.Namespace } + if forSamenessGroups && partition == "" { + continue + } + node := "node" + tenancy.Partition // service with meta data + metaServiceName := getConsulServiceName("service-meta", tenancy, forSamenessGroups) serviceMetaService := &api.AgentService{ - ID: fmt.Sprintf("service-meta-%s-%s", tenancy.Partition, tenancy.Namespace), - Service: fmt.Sprintf("service-meta-%s-%s", tenancy.Partition, tenancy.Namespace), + ID: metaServiceName, + Service: metaServiceName, Tags: []string{"tag1"}, Meta: map[string]string{ "meta1": "value1", @@ -164,9 +172,10 @@ func (c *ClientSet) createConsulTestResources() error { return err } // service with serviceTaggedAddresses + taggedAddressServiceName := getConsulServiceName("service-taggedAddresses", tenancy, forSamenessGroups) serviceTaggedAddressesService := &api.AgentService{ - ID: fmt.Sprintf("service-taggedAddresses-%s-%s", tenancy.Partition, tenancy.Namespace), - Service: fmt.Sprintf("service-taggedAddresses-%s-%s", tenancy.Partition, tenancy.Namespace), + ID: taggedAddressServiceName, + Service: taggedAddressServiceName, TaggedAddresses: map[string]api.ServiceAddress{ "lan": { Address: "192.0.2.1", @@ -190,9 +199,10 @@ func (c *ClientSet) createConsulTestResources() error { } // connect enabled service + testServiceName := getConsulServiceName("conn-enabled-service", tenancy, forSamenessGroups) testService := &api.AgentService{ - ID: fmt.Sprintf("conn-enabled-service-%s-%s", tenancy.Partition, tenancy.Namespace), - Service: fmt.Sprintf("conn-enabled-service-%s-%s", tenancy.Partition, tenancy.Namespace), + ID: testServiceName, + Service: testServiceName, Port: 12345, Connect: &api.AgentServiceConnect{}, Partition: partition, @@ -200,38 +210,43 @@ func (c *ClientSet) createConsulTestResources() error { } // this is based on what `consul connect proxy` command does at // consul/command/connect/proxy/register.go (register method) + testConnectName := getConsulServiceName("conn-enabled-service-proxy", tenancy, forSamenessGroups) testConnect := &api.AgentService{ Kind: api.ServiceKindConnectProxy, - ID: fmt.Sprintf("conn-enabled-service-proxy-%s-%s", tenancy.Partition, tenancy.Namespace), - Service: fmt.Sprintf("conn-enabled-service-proxy-%s-%s", tenancy.Partition, tenancy.Namespace), + ID: testConnectName, + Service: testConnectName, Port: 21999, Proxy: &api.AgentServiceConnectProxyConfig{ - DestinationServiceName: fmt.Sprintf("conn-enabled-service-%s-%s", tenancy.Partition, tenancy.Namespace), + DestinationServiceName: getConsulServiceName("conn-enabled-service", tenancy, forSamenessGroups), }, Partition: partition, Namespace: namespace, } - if _, err := catalog.Register(&api.CatalogRegistration{ + testServiceRegistration := &api.CatalogRegistration{ Service: testService, Partition: partition, Node: node, Address: "127.0.0.1", - }, nil); err != nil { + } + if _, err := catalog.Register(testServiceRegistration, nil); err != nil { return err } - if _, err := catalog.Register(&api.CatalogRegistration{ + testConnectRegistration := &api.CatalogRegistration{ Service: testConnect, Partition: partition, Node: node, Address: "127.0.0.1", - }, nil); err != nil { + } + if _, err := catalog.Register(testConnectRegistration, nil); err != nil { return err } - if err := testClients.createConsulPeerings(tenancy); err != nil { - return err + if !forSamenessGroups { + if err := testClients.createConsulPeerings(tenancy); err != nil { + return err + } } time.Sleep(200 * time.Millisecond) } @@ -239,6 +254,69 @@ func (c *ClientSet) createConsulTestResources() error { return nil } +func getConsulServiceName(name string, tenancy *test.Tenancy, forSamenessGroups bool) string { + if forSamenessGroups { + return name + } + return fmt.Sprintf("%s-%s-%s", name, tenancy.Partition, tenancy.Namespace) +} + +func (c *ClientSet) createConsulSamenessGroups() error { + uniquePartitions := tenancyHelper.GetUniquePartitions() + + for partition := range uniquePartitions { + members := []api.SamenessGroupMember{} + // add local partition first + members = append(members, api.SamenessGroupMember{ + Partition: partition.Name, + }) + //then add the others + for p := range uniquePartitions { + if p.Name != partition.Name { + members = append(members, api.SamenessGroupMember{ + Partition: p.Name, + }) + } + } + + sg := &api.SamenessGroupConfigEntry{ + Kind: QuerySamenessGroup, + Name: "test-sameness-group", + Partition: partition.Name, + DefaultForFailover: true, + Members: members, + } + log.Printf("sameness group: %+v", sg) + _, _, err := c.consul.client.ConfigEntries().Set(sg, &api.WriteOptions{}) + if err != nil { + return err + } + + _, _, err = c.consul.client.ConfigEntries().Set(&api.ServiceIntentionsConfigEntry{ + Kind: api.ServiceIntentions, + Name: "foo", + Sources: []*api.SourceIntention{ + { + Name: "bar", + SamenessGroup: "group-1", + Action: api.IntentionActionAllow, + }, + }, + }, &api.WriteOptions{}) + if err != nil { + return err + } + } + + sgs, _, err := c.consul.client.ConfigEntries().List(QuerySamenessGroup, &api.QueryOptions{}) + if err != nil { + return err + } + log.Printf("sameness groups: %+v", sgs) + + return nil +} + func (c *ClientSet) createConsulPeerings(tenancy *test.Tenancy) error { generateReq := api.PeeringGenerateTokenRequest{PeerName: "foo", Partition: tenancy.Partition} _, _, err := c.consul.client.Peerings().GenerateToken(context.Background(), generateReq, &api.WriteOptions{}) diff --git a/dependency/health_service.go b/dependency/health_service.go index 7728615dd..ed9f714f6 100644 --- a/dependency/health_service.go +++ b/dependency/health_service.go @@ -23,9 +23,10 @@ const ( HealthCritical = "critical" HealthMaint = "maintenance" - QueryNamespace = "ns" - QueryPartition = "partition" - QueryPeer = "peer" + QueryNamespace = "ns" + QueryPartition = "partition" + QueryPeer = "peer" + QuerySamenessGroup = "sameness-group" NodeMaint = "_node_maintenance" ServiceMaint = "_service_maintenance:" @@ -66,15 +67,16 @@ type HealthService struct { type HealthServiceQuery struct { stopCh chan struct{} - dc string - filters []string - name string - near string - tag string - connect bool - partition string - peer string - namespace string + dc string + filters []string + name string + near string + tag string + connect bool + partition string + peer string + namespace string + samenessGroup string } // NewHealthServiceQuery processes the strings to build a service dependency. @@ -122,18 +124,25 @@ func healthServiceQuery(s string, connect bool) (*HealthServiceQuery, error) { return nil, err } - return &HealthServiceQuery{ - stopCh: make(chan struct{}, 1), - dc: m["dc"], - filters: filters, - name: m["name"], - near: m["near"], - tag: m["tag"], - connect: connect, - namespace: queryParams.Get(QueryNamespace), - peer: queryParams.Get(QueryPeer), - partition: queryParams.Get(QueryPartition), - }, nil + qry := &HealthServiceQuery{ + stopCh: make(chan struct{}, 1), + dc: m["dc"], + filters: filters, + name: m["name"], + near: m["near"], + tag: m["tag"], + connect: connect, + namespace: queryParams.Get(QueryNamespace), + peer: queryParams.Get(QueryPeer), + partition: queryParams.Get(QueryPartition), + samenessGroup: queryParams.Get(QuerySamenessGroup), + } + + if qry.samenessGroup != "" && qry.peer != "" { + return nil, fmt.Errorf("health.service: cannot specify both peer and sameness-group") + } + + return qry, nil } // Fetch queries the Consul API defined by the given client and returns a slice @@ -146,11 +155,12 @@ func (d *HealthServiceQuery) Fetch(clients *ClientSet, opts *QueryOptions) (inte } opts = opts.Merge(&QueryOptions{ - Datacenter: d.dc, - Near: d.near, - ConsulNamespace: d.namespace, - ConsulPartition: d.partition, - ConsulPeer: d.peer, + Datacenter: d.dc, + Near: d.near, + ConsulNamespace: d.namespace, + ConsulPartition: d.partition, + ConsulPeer: d.peer, + ConsulSamenessGroup: d.samenessGroup, }) u := &url.URL{ @@ -261,6 +271,9 @@ func (d *HealthServiceQuery) String() string { if d.peer != "" { name = name + "@peer=" + d.peer } + if d.samenessGroup != "" { + name = name + "@samenessGroup=" + d.samenessGroup + } if d.near != "" { name = name + "~" + d.near } diff --git a/dependency/health_service_test.go b/dependency/health_service_test.go index a5d1bd02d..eca3a3b8b 100644 --- a/dependency/health_service_test.go +++ b/dependency/health_service_test.go @@ -20,7 +20,7 @@ func TestNewHealthServiceQuery(t *testing.T) { name string i string exp *HealthServiceQuery - err bool + err error } cases := tenancyHelper.GenerateTenancyTests(func(tenancy *test.Tenancy) []interface{} { return []interface{}{ @@ -28,37 +28,37 @@ func TestNewHealthServiceQuery(t *testing.T) { tenancyHelper.AppendTenancyInfo("empty", tenancy), "", nil, - true, + fmt.Errorf(`health.service: invalid format: ""`), }, testCase{ tenancyHelper.AppendTenancyInfo("dc_only", tenancy), "@dc1", nil, - true, + fmt.Errorf(`health.service: invalid format: "@dc1"`), }, testCase{ tenancyHelper.AppendTenancyInfo("near_only", tenancy), "~near", nil, - true, + fmt.Errorf(`health.service: invalid format: "~near"`), }, testCase{ tenancyHelper.AppendTenancyInfo("tag_only", tenancy), "tag.", nil, - true, + fmt.Errorf(`health.service: invalid format: "tag."`), }, testCase{ tenancyHelper.AppendTenancyInfo("query_only", tenancy), fmt.Sprintf("?ns=%s", tenancy.Namespace), nil, - true, + fmt.Errorf(`health.service: invalid format: "?ns=default"`), }, testCase{ tenancyHelper.AppendTenancyInfo("invalid query param (unsupported key)", tenancy), "name?unsupported=test", nil, - true, + fmt.Errorf(`health.service: invalid query parameter key "unsupported" in query "unsupported=test": supported keys: ns,peer,partition`), }, testCase{ tenancyHelper.AppendTenancyInfo("name", tenancy), @@ -67,7 +67,7 @@ func TestNewHealthServiceQuery(t *testing.T) { filters: []string{"passing"}, name: "name", }, - false, + nil, }, testCase{ tenancyHelper.AppendTenancyInfo("name_dc", tenancy), @@ -77,7 +77,7 @@ func TestNewHealthServiceQuery(t *testing.T) { filters: []string{"passing"}, name: "name", }, - false, + nil, }, testCase{ tenancyHelper.AppendTenancyInfo("name_dc_near", tenancy), @@ -88,7 +88,7 @@ func TestNewHealthServiceQuery(t *testing.T) { name: "name", near: "near", }, - false, + nil, }, testCase{ tenancyHelper.AppendTenancyInfo("name_near", tenancy), @@ -98,7 +98,7 @@ func TestNewHealthServiceQuery(t *testing.T) { name: "name", near: "near", }, - false, + nil, }, testCase{ tenancyHelper.AppendTenancyInfo("tag_name", tenancy), @@ -108,7 +108,7 @@ func TestNewHealthServiceQuery(t *testing.T) { name: "name", tag: "tag", }, - false, + nil, }, testCase{ tenancyHelper.AppendTenancyInfo("tag_name_dc", tenancy), @@ -119,7 +119,7 @@ func TestNewHealthServiceQuery(t *testing.T) { name: "name", tag: "tag", }, - false, + nil, }, testCase{ tenancyHelper.AppendTenancyInfo("tag_name_near", tenancy), @@ -130,7 +130,7 @@ func TestNewHealthServiceQuery(t *testing.T) { near: "near", tag: "tag", }, - false, + nil, }, testCase{ tenancyHelper.AppendTenancyInfo("tag_name_dc_near", tenancy), @@ -142,7 +142,7 @@ func TestNewHealthServiceQuery(t *testing.T) { near: "near", tag: "tag", }, - false, + nil, }, testCase{ tenancyHelper.AppendTenancyInfo("name_partition", tenancy), @@ -152,7 +152,7 @@ func TestNewHealthServiceQuery(t *testing.T) { name: "name", partition: tenancy.Partition, }, - false, + nil, }, testCase{ tenancyHelper.AppendTenancyInfo("name_peer", tenancy), @@ -162,7 +162,7 @@ func TestNewHealthServiceQuery(t *testing.T) { name: "name", peer: "foo", }, - false, + nil, }, testCase{ tenancyHelper.AppendTenancyInfo("name_ns", tenancy), @@ -172,7 +172,7 @@ func TestNewHealthServiceQuery(t *testing.T) { name: "name", namespace: tenancy.Namespace, }, - false, + nil, }, testCase{ tenancyHelper.AppendTenancyInfo("name_ns_peer_partition", tenancy), @@ -184,7 +184,23 @@ func TestNewHealthServiceQuery(t *testing.T) { peer: "bar", partition: tenancy.Partition, }, - false, + nil, + }, + testCase{ + tenancyHelper.AppendTenancyInfo("name_samenessgroup", tenancy), + "name?sameness-group=sg1", + &HealthServiceQuery{ + filters: []string{"passing"}, + name: "name", + samenessGroup: "sg1", + }, + nil, + }, + testCase{ + tenancyHelper.AppendTenancyInfo("samenessgroup and peer should return error if both set", tenancy), + "name?sameness-group=sg1&peer=peer1", + nil, + fmt.Errorf("health.service: cannot specify both peer and sameness-group"), }, testCase{ tenancyHelper.AppendTenancyInfo("namespace set twice should use first", tenancy), @@ -194,7 +210,7 @@ func TestNewHealthServiceQuery(t *testing.T) { name: "name", namespace: tenancy.Namespace, }, - false, + nil, }, testCase{ tenancyHelper.AppendTenancyInfo("empty value in query param", tenancy), @@ -206,7 +222,7 @@ func TestNewHealthServiceQuery(t *testing.T) { peer: "", partition: "", }, - false, + nil, }, testCase{ tenancyHelper.AppendTenancyInfo("query with other parameters", tenancy), @@ -221,7 +237,7 @@ func TestNewHealthServiceQuery(t *testing.T) { namespace: tenancy.Namespace, partition: tenancy.Partition, }, - false, + nil, }, } }) @@ -230,9 +246,7 @@ func TestNewHealthServiceQuery(t *testing.T) { tc := test.(testCase) t.Run(fmt.Sprintf("%d_%s", i, tc.name), func(t *testing.T) { act, err := NewHealthServiceQuery(tc.i) - if (err != nil) != tc.err { - t.Fatal(err) - } + assert.Equal(t, err, tc.err) if act != nil { act.stopCh = nil @@ -641,6 +655,35 @@ func TestHealthServiceQuery_Fetch(t *testing.T) { }, }, }, + testCase{ + fmt.Sprintf(`service-meta for sameness group "%s" in partition "%s"`, "service-meta-sameness-group", tenancy.Partition), + fmt.Sprintf("service-meta?sameness-group=%s&partition=%s", "service-meta-sameness-group", tenancy.Partition), + []*HealthService{ + { + Node: "node" + tenancy.Partition, + NodeAddress: testConsul.Config.Bind, + NodeTaggedAddresses: map[string]string{ + //"lan": "127.0.0.1", + //"wan": "127.0.0.1", + }, + NodeMeta: map[string]string{ + //"consul-network-segment": "", + }, + ServiceMeta: map[string]string{ + "meta1": "value1", + }, + Address: testConsul.Config.Bind, + ID: "service-meta", + Name: "service-meta", + Tags: []string{"tag1"}, + Status: "passing", + Weights: api.AgentWeights{ + Passing: 1, + Warning: 1, + }, + }, + }, + }, } })...) @@ -675,6 +718,156 @@ func TestHealthServiceQuery_Fetch(t *testing.T) { } } +func TestHealthServiceQuery_Fetch_SamenessGroup(t *testing.T) { + // Arrange - set up test data + catalog := testClients.Consul().Catalog() + + fooPartition := "foo" + defaultPartition := "default" + nodeDefault := "node" + defaultPartition + nodeFoo := "node" + fooPartition + + // Register services in foo partition as critical so they will fall back to default partition service + testServiceName := "conn-enabled-service" + testServiceCheckName := fmt.Sprintf("%s:%s", testServiceName, nodeFoo) + testServiceRegistration := &api.CatalogRegistration{ + Service: &api.AgentService{ + ID: testServiceName, + Service: testServiceName, + Port: 12345, + Partition: fooPartition, + Namespace: "default", + Connect: &api.AgentServiceConnect{}, + }, + Partition: fooPartition, + Node: nodeFoo, + Address: "127.0.0.1", + Checks: api.HealthChecks{ + &api.HealthCheck{ + Node: nodeFoo, + CheckID: testServiceCheckName, + Name: testServiceCheckName, + Status: HealthCritical, + ServiceID: testServiceName, + ServiceName: testServiceName, + }, + }, + } + + testConnectName := "conn-enabled-service-proxy" + testConnectCheckName := fmt.Sprintf("%s:%s", testConnectName, nodeFoo) + testConnectRegistration := &api.CatalogRegistration{ + Service: &api.AgentService{ + Kind: api.ServiceKindConnectProxy, + ID: testConnectName, + Service: testConnectName, + Port: 21999, + Proxy: &api.AgentServiceConnectProxyConfig{ + DestinationServiceName: testServiceName, + }, + Partition: fooPartition, + Namespace: "default", + }, + Partition: fooPartition, + Node: nodeFoo, + Address: "127.0.0.1", + Checks: api.HealthChecks{ + &api.HealthCheck{ + Node: nodeFoo, + CheckID: testConnectCheckName, + Name: testConnectCheckName, + Status: HealthCritical, + ServiceID: testConnectName, + ServiceName: testConnectName, + }, + }, + } + + _, err := catalog.Register(testServiceRegistration, nil) + if err != nil { + t.Fatal(err) + } + + _, err = catalog.Register(testConnectRegistration, nil) + if err != nil { + t.Fatal(err) + } + + // Register in default partition as passing so it can fall back + testServiceRegistration.Service.Partition = defaultPartition + testServiceRegistration.Partition = defaultPartition + testServiceRegistration.Node = nodeDefault + testServiceRegistration.Checks[0].Node = nodeDefault + testServiceRegistration.Checks[0].CheckID = fmt.Sprintf("%s:%s", testServiceName, nodeDefault) + testServiceRegistration.Checks[0].Name = fmt.Sprintf("%s:%s", testServiceName, nodeDefault) + testServiceRegistration.Checks[0].Status = HealthPassing + + _, err = catalog.Register(testServiceRegistration, nil) + if err != nil { + t.Fatal(err) + } + + testConnectRegistration.Service.Partition = defaultPartition + testConnectRegistration.Partition = defaultPartition + testConnectRegistration.Node = nodeDefault + testConnectRegistration.Checks[0].Node = nodeDefault + testConnectRegistration.Checks[0].CheckID = fmt.Sprintf("%s:%s", testServiceName, nodeDefault) + testConnectRegistration.Checks[0].Name = fmt.Sprintf("%s:%s", testServiceName, nodeDefault) + testConnectRegistration.Checks[0].Status = HealthPassing + _, err = catalog.Register(testConnectRegistration, nil) + if err != nil { + t.Fatal(err) + } + + // Act - fetch the service + query := fmt.Sprintf("service-meta?sameness-group=%s&partition=%s", "service-meta-sameness-group", fooPartition) + d, err := NewHealthServiceQuery(query) + if err != nil { + t.Fatal(err) + } + + act, _, err := d.Fetch(testClients, nil) + if err != nil { + t.Fatal(err) + } + + if act != nil { + for _, v := range act.([]*HealthService) { + v.NodeID = "" + v.Checks = nil + // delete any version data from ServiceMeta + v.ServiceMeta = filterVersionMeta(v.ServiceMeta) + v.NodeTaggedAddresses = filterAddresses( + v.NodeTaggedAddresses) + v.NodeMeta = filterVersionMeta(v.NodeMeta) + + } + } + + // Assert - verify the results + expectedResult := []*HealthService{ + { + Node: "node" + defaultPartition, + NodeAddress: testConsul.Config.Bind, + ServiceMeta: map[string]string{ + "meta1": "value1", + }, + Address: testConsul.Config.Bind, + NodeTaggedAddresses: map[string]string{}, + NodeMeta: map[string]string{}, + ID: "service-meta", + Name: "service-meta", + Tags: []string{"tag1"}, + Status: "passing", + Weights: api.AgentWeights{ + Passing: 1, + Warning: 1, + }, + }, + } + assert.Equal(t, expectedResult, act) +} + func TestHealthServiceQuery_String(t *testing.T) { type testCase struct { name string diff --git a/go.mod b/go.mod index 89cba799d..c216978f5 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,13 @@ -module github.com/hashicorp/consul-template +module consul-template go 1.22 toolchain go1.22.4 require ( + dario.cat/mergo v1.0.0 github.com/BurntSushi/toml v1.3.2 + github.com/Masterminds/sprig/v3 v3.2.3 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/hashicorp/consul/api v1.28.3 github.com/hashicorp/consul/sdk v0.15.0 @@ -17,15 +19,14 @@ require ( github.com/hashicorp/go-syslog v1.0.0 github.com/hashicorp/hcl v1.0.0 github.com/hashicorp/logutils v1.0.0 - github.com/hashicorp/nomad/api v0.0.0-20230103221135-ce00d683f9be - github.com/hashicorp/serf v0.10.1 // indirect - github.com/hashicorp/vault/api v1.10.0 - github.com/imdario/mergo v0.3.13 + github.com/hashicorp/nomad/api v0.0.0-20240306165712-3193ac204f65 + github.com/hashicorp/vault/api v1.12.0 + github.com/hashicorp/vault/api/auth/kubernetes v0.6.0 github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/hashstructure v1.1.0 github.com/mitchellh/mapstructure v1.5.0 github.com/pkg/errors v0.9.1 - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 golang.org/x/crypto v0.22.0 // indirect golang.org/x/sys v0.20.0 gopkg.in/yaml.v2 v2.4.0 @@ -59,6 +60,7 @@ require ( github.com/hashicorp/go-version v1.6.0 // indirect github.com/hashicorp/golang-lru v1.0.2 // indirect github.com/huandu/xstrings v1.4.0 // indirect + github.com/imdario/mergo v0.3.13 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/miekg/dns v1.1.50 // indirect diff --git a/go.sum b/go.sum index f73590890..2bf1cc6bf 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= +dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= @@ -137,14 +139,14 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO github.com/hashicorp/mdns v1.0.4/go.mod h1:mtBihi+LeNXGtG8L9dX59gAEa12BDtBQSp4v/YAJqrc= github.com/hashicorp/memberlist v0.5.0 h1:EtYPN8DpAURiapus508I4n9CzHs2W+8NZGbmmR/prTM= github.com/hashicorp/memberlist v0.5.0/go.mod h1:yvyXLpo0QaGE59Y7hDTsTzDD25JYBZ4mHgHUZ8lrOI0= -github.com/hashicorp/nomad/api v0.0.0-20230103221135-ce00d683f9be h1:bJ/jBA5pt/5OT1oaApx8B5g/nRyohn61Q8TyUp4PoEI= -github.com/hashicorp/nomad/api v0.0.0-20230103221135-ce00d683f9be/go.mod h1:EM/2XaEwHziSB4NdWZ6MfE65TcvgWwVawOUBT8kVRqE= +github.com/hashicorp/nomad/api v0.0.0-20240306165712-3193ac204f65 h1:bqSioPvnVoWlDnlsY1sXPW+ts8ywxD/Qz89lJZgwubA= +github.com/hashicorp/nomad/api v0.0.0-20240306165712-3193ac204f65/go.mod h1:z71gkJdrkAt/Rl6C7Q79VE7AwJ5lUF+M+fzFTyIHYB0= github.com/hashicorp/serf v0.10.1 h1:Z1H2J60yRKvfDYAOZLd2MU0ND4AH/WDz7xYHDWQsIPY= github.com/hashicorp/serf v0.10.1/go.mod h1:yL2t6BqATOLGc5HF7qbFkTfXoPIY0WZdWHfEvMqbG+4= -github.com/hashicorp/vault/api v1.10.0 h1:/US7sIjWN6Imp4o/Rj1Ce2Nr5bki/AXi9vAW3p2tOJQ= -github.com/hashicorp/vault/api v1.10.0/go.mod h1:jo5Y/ET+hNyz+JnKDt8XLAdKs+AM0G5W0Vp1IrFI8N8= -github.com/hashicorp/vault/api/auth/kubernetes v0.5.0 h1:CXO0fD7M3iCGovP/UApeHhPcH4paDFKcu7AjEXi94rI= -github.com/hashicorp/vault/api/auth/kubernetes v0.5.0/go.mod h1:afrElBIO9Q4sHFVuVWgNevG4uAs1bT2AZFA9aEiI608= +github.com/hashicorp/vault/api v1.12.0 h1:meCpJSesvzQyao8FCOgk2fGdoADAnbDu2WPJN1lDLJ4= +github.com/hashicorp/vault/api v1.12.0/go.mod h1:si+lJCYO7oGkIoNPAN8j3azBLTn9SjMGS+jFaHd1Cck= +github.com/hashicorp/vault/api/auth/kubernetes v0.6.0 h1:K8sKGhtTAqGKfzaaYvUSIOAqTOIn3Gk1EsCEAMzZHtM= +github.com/hashicorp/vault/api/auth/kubernetes v0.6.0/go.mod h1:Htwcjez5J9PwAHaZ1EYMBlgGq3/in5ajUV4+WCPihPE= github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU= github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= @@ -181,6 +183,7 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= +github.com/miekg/dns v1.1.41 h1:WMszZWJG0XmzbK9FEmzH2TVcqYzFesusSIB41b8KHxY= github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= github.com/miekg/dns v1.1.50 h1:DQUfb9uc6smULcREF09Uc+/Gd46YWqJd5DbpPE9xkcA= github.com/miekg/dns v1.1.50/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME= @@ -239,8 +242,8 @@ github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkB github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= -github.com/shoenig/test v0.5.2 h1:ELZ7qZ/6CPrT71PXrSe2TFzLs4/cGCqqU5lZ5RhZ+B8= -github.com/shoenig/test v0.5.2/go.mod h1:xYtyGBC5Q3kzCNyJg/SjgNpfAa2kvmgA0i5+lQso8x0= +github.com/shoenig/test v1.7.1 h1:UJcjSAI3aUKx52kfcfhblgyhZceouhvvs3OYdWgn+PY= +github.com/shoenig/test v1.7.1/go.mod h1:UxJ6u/x2v/TNs/LoLxBNJRV9DiwBBKYxXSyczsBHFoI= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= @@ -251,25 +254,28 @@ github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= -github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= @@ -289,13 +295,10 @@ golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8= -golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= @@ -325,8 +328,6 @@ golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -347,6 +348,8 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= +golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= @@ -356,6 +359,7 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -364,13 +368,11 @@ golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw= golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 h1:KpwkzHKEF7B9Zxg18WzOa7djJ+Ha5DzthMyZYQfEn2A= diff --git a/template/funcs.go b/template/funcs.go index c8066f785..d3270cc11 100644 --- a/template/funcs.go +++ b/template/funcs.go @@ -25,11 +25,11 @@ import ( "text/template" "time" + "dario.cat/mergo" "github.com/BurntSushi/toml" spewLib "github.com/davecgh/go-spew/spew" "github.com/hashicorp/consul/api" socktmpl "github.com/hashicorp/go-sockaddr/template" - "github.com/imdario/mergo" "github.com/pkg/errors" "golang.org/x/text/cases" "golang.org/x/text/language" diff --git a/test/helpers.go b/test/helpers.go index d056f3017..f270a4d49 100644 --- a/test/helpers.go +++ b/test/helpers.go @@ -113,3 +113,11 @@ func (t *TestingTB) Cleanup(f func()) { } } } +func (*TestingTB) Error(...any) {} +func (*TestingTB) Errorf(string, ...any) {} +func (*TestingTB) Fail() {} +func (*TestingTB) FailNow() {} +func (*TestingTB) Fatal(...any) {} +func (*TestingTB) Log(...any) {} +func (*TestingTB) Setenv(string, string) {} +func (*TestingTB) TempDir() string { return "" } From 3c320c179dcb703480031423c12303223395d9c6 Mon Sep 17 00:00:00 2001 From: John Murret Date: Wed, 20 Mar 2024 17:20:08 -0600 Subject: [PATCH 02/16] Get TestHealthServiceQuery_Fetch_SamenessGroup working --- dependency/dependency.go | 1 + dependency/dependency_test.go | 140 +++++++++------------------ dependency/health_service_test.go | 151 ++++++++++-------------------- 3 files changed, 96 insertions(+), 196 deletions(-) diff --git a/dependency/dependency.go b/dependency/dependency.go index 4a6146a09..941877779 100644 --- a/dependency/dependency.go +++ b/dependency/dependency.go @@ -160,6 +160,7 @@ func (q *QueryOptions) ToConsulOpts() *consulapi.QueryOptions { Datacenter: q.Datacenter, Namespace: q.ConsulNamespace, Partition: q.ConsulPartition, + SamenessGroup: q.ConsulSamenessGroup, Peer: q.ConsulPeer, Near: q.Near, RequireConsistent: q.RequireConsistent, diff --git a/dependency/dependency_test.go b/dependency/dependency_test.go index 4f6fc9336..d83e77547 100644 --- a/dependency/dependency_test.go +++ b/dependency/dependency_test.go @@ -105,11 +105,6 @@ func TestMain(m *testing.M) { Fatalf("failed to create consul test resources: %v\n", err) } - if err := testClients.createConsulSamenessGroups(); err != nil { - stopTestClients() - Fatalf("failed to create consul test sameness groups: %v\n", err) - } - // Wait for Nomad initialization to finish if err := <-nomadFuture; err != nil { stopTestClients() @@ -130,14 +125,6 @@ func stopTestClients() { } func (c *ClientSet) createConsulTestResources() error { - err := c.createConsulResourcesForTenancies(false) - if err != nil { - return err - } - return c.createConsulResourcesForTenancies(true) -} - -func (c *ClientSet) createConsulResourcesForTenancies(forSamenessGroups bool) error { catalog := testClients.Consul().Catalog() for _, tenancy := range tenancyHelper.TestTenancies() { partition := "" @@ -146,16 +133,11 @@ func (c *ClientSet) createConsulResourcesForTenancies(forSamenessGroups bool) er partition = tenancy.Partition namespace = tenancy.Namespace } - if forSamenessGroups && partition == "" { - continue - } - node := "node" + tenancy.Partition // service with meta data - metaServiceName := getConsulServiceName("service-meta", tenancy, forSamenessGroups) serviceMetaService := &api.AgentService{ - ID: metaServiceName, - Service: metaServiceName, + ID: fmt.Sprintf("service-meta-%s-%s", tenancy.Partition, tenancy.Namespace), + Service: fmt.Sprintf("service-meta-%s-%s", tenancy.Partition, tenancy.Namespace), Tags: []string{"tag1"}, Meta: map[string]string{ "meta1": "value1", @@ -172,10 +154,9 @@ func (c *ClientSet) createConsulResourcesForTenancies(forSamenessGroups bool) er return err } // service with serviceTaggedAddresses - taggedAddressServiceName := getConsulServiceName("service-taggedAddresses", tenancy, forSamenessGroups) serviceTaggedAddressesService := &api.AgentService{ - ID: taggedAddressServiceName, - Service: taggedAddressServiceName, + ID: fmt.Sprintf("service-taggedAddresses-%s-%s", tenancy.Partition, tenancy.Namespace), + Service: fmt.Sprintf("service-taggedAddresses-%s-%s", tenancy.Partition, tenancy.Namespace), TaggedAddresses: map[string]api.ServiceAddress{ "lan": { Address: "192.0.2.1", @@ -199,10 +180,9 @@ func (c *ClientSet) createConsulResourcesForTenancies(forSamenessGroups bool) er } // connect enabled service - testServiceName := getConsulServiceName("conn-enabled-service", tenancy, forSamenessGroups) testService := &api.AgentService{ - ID: testServiceName, - Service: testServiceName, + ID: fmt.Sprintf("conn-enabled-service-%s-%s", tenancy.Partition, tenancy.Namespace), + Service: fmt.Sprintf("conn-enabled-service-%s-%s", tenancy.Partition, tenancy.Namespace), Port: 12345, Connect: &api.AgentServiceConnect{}, Partition: partition, @@ -210,43 +190,38 @@ func (c *ClientSet) createConsulResourcesForTenancies(forSamenessGroups bool) er } // this is based on what `consul connect proxy` command does at // consul/command/connect/proxy/register.go (register method) - testConnectName := getConsulServiceName("conn-enabled-service-proxy", tenancy, forSamenessGroups) testConnect := &api.AgentService{ Kind: api.ServiceKindConnectProxy, - ID: testConnectName, - Service: testConnectName, + ID: fmt.Sprintf("conn-enabled-service-proxy-%s-%s", tenancy.Partition, tenancy.Namespace), + Service: fmt.Sprintf("conn-enabled-service-proxy-%s-%s", tenancy.Partition, tenancy.Namespace), Port: 21999, Proxy: &api.AgentServiceConnectProxyConfig{ - DestinationServiceName: getConsulServiceName("conn-enabled-service", tenancy, forSamenessGroups), + DestinationServiceName: fmt.Sprintf("conn-enabled-service-%s-%s", tenancy.Partition, tenancy.Namespace), }, Partition: partition, Namespace: namespace, } - testServiceRegistration := &api.CatalogRegistration{ + if _, err := catalog.Register(&api.CatalogRegistration{ Service: testService, Partition: partition, Node: node, Address: "127.0.0.1", - } - if _, err := catalog.Register(testServiceRegistration, nil); err != nil { + }, nil); err != nil { return err } - testConnectRegistration := &api.CatalogRegistration{ + if _, err := catalog.Register(&api.CatalogRegistration{ Service: testConnect, Partition: partition, Node: node, Address: "127.0.0.1", - } - if _, err := catalog.Register(testConnectRegistration, nil); err != nil { + }, nil); err != nil { return err } - if !forSamenessGroups { - if err := testClients.createConsulPeerings(tenancy); err != nil { - return err - } + if err := testClients.createConsulPeerings(tenancy); err != nil { + return err } time.Sleep(200 * time.Millisecond) } @@ -254,58 +229,23 @@ func (c *ClientSet) createConsulResourcesForTenancies(forSamenessGroups bool) er return nil } -func getConsulServiceName(name string, tenancy *test.Tenancy, forSamenessGroups bool) string { - if forSamenessGroups { - return name - } - return fmt.Sprintf("%s-%s-%s", name, tenancy.Partition, tenancy.Namespace) -} - -func (c *ClientSet) createConsulSamenessGroups() error { - uniquePartitions := tenancyHelper.GetUniquePartitions() - - for partition := range uniquePartitions { - members := []api.SamenessGroupMember{} - // add local partition first - members = append(members, api.SamenessGroupMember{ - Partition: partition.Name, - }) - //then add the others - for p := range uniquePartitions { - if p.Name != partition.Name { - members = append(members, api.SamenessGroupMember{ - Partition: p.Name, - }) - } - } - - sg := &api.SamenessGroupConfigEntry{ - Kind: QuerySamenessGroup, - Name: "test-sameness-group", - Partition: partition.Name, - DefaultForFailover: true, - Members: members, - } - log.Printf("sameness group: %+v", sg) - _, _, err := c.consul.client.ConfigEntries().Set(sg, &api.WriteOptions{}) - if err != nil { - return err - } - - _, _, err = c.consul.client.ConfigEntries().Set(&api.ServiceIntentionsConfigEntry{ - Kind: api.ServiceIntentions, - Name: "foo", - Sources: []*api.SourceIntention{ - { - Name: "bar", - SamenessGroup: "group-1", - Action: api.IntentionActionAllow, - }, - }, - }, &api.WriteOptions{}) - if err != nil { - return err - } +func (c *ClientSet) createConsulSamenessGroups(name, partition, failoverPartition string) error { + members := append([]api.SamenessGroupMember{}, api.SamenessGroupMember{ + Partition: partition, + }, api.SamenessGroupMember{ + Partition: failoverPartition, + }) + sg := &api.SamenessGroupConfigEntry{ + Kind: QuerySamenessGroup, + Name: name, + Partition: partition, + DefaultForFailover: true, + Members: members, + } + log.Printf("sameness group: %+v", sg) + _, _, err := c.consul.client.ConfigEntries().Set(sg, &api.WriteOptions{}) + if err != nil { + return err } sgs, _, err := c.consul.client.ConfigEntries().List(QuerySamenessGroup, &api.QueryOptions{}) @@ -623,10 +563,9 @@ func (v *nomadServer) DeleteVariable(path string, opts *nomadapi.WriteOptions) e func (c *ClientSet) createConsulPartitions() error { for p := range tenancyHelper.GetUniquePartitions() { if p.Name != "" && p.Name != "default" { - partition := &api.Partition{Name: p.Name} - _, _, err := c.Consul().Partitions().Create(context.Background(), partition, nil) - if err != nil { - return err + err2 := c.createConsulPartition(p.Name) + if err2 != nil { + return err2 } } } @@ -634,6 +573,15 @@ func (c *ClientSet) createConsulPartitions() error { return nil } +func (c *ClientSet) createConsulPartition(name string) error { + partition := &api.Partition{Name: name} + _, _, err := c.Consul().Partitions().Create(context.Background(), partition, nil) + if err != nil { + return err + } + return nil +} + func (c *ClientSet) createConsulNs() error { for _, tenancy := range tenancyHelper.TestTenancies() { if tenancy.Namespace != "" && tenancy.Namespace != "default" { diff --git a/dependency/health_service_test.go b/dependency/health_service_test.go index eca3a3b8b..946a224d2 100644 --- a/dependency/health_service_test.go +++ b/dependency/health_service_test.go @@ -5,6 +5,7 @@ package dependency import ( "fmt" + "github.com/stretchr/testify/require" "reflect" "testing" "unsafe" @@ -722,105 +723,56 @@ func TestHealthServiceQuery_Fetch_SamenessGroup(t *testing.T) { // Arrange - set up test data catalog := testClients.Consul().Catalog() - fooPartition := "foo" - defaultPartition := "default" - nodeDefault := "node" + defaultPartition - nodeFoo := "node" + fooPartition + partitionOne := "sg-partition-1" + partitionTwo := "sg-partition-2" + nodeOne := "node" + partitionOne + nodeTwo := "node" + partitionTwo + samenessGroup := "test-sameness-group" - // Register services in foo partition as critical so they will fall back to default partition service - testServiceName := "conn-enabled-service" - testServiceCheckName := fmt.Sprintf("%s:%s", testServiceName, nodeFoo) - testServiceRegistration := &api.CatalogRegistration{ - Service: &api.AgentService{ - ID: testServiceName, - Service: testServiceName, - Port: 12345, - Partition: fooPartition, - Namespace: "default", - Connect: &api.AgentServiceConnect{}, - }, - Partition: fooPartition, - Node: nodeFoo, - Address: "127.0.0.1", - Checks: api.HealthChecks{ - &api.HealthCheck{ - Node: nodeFoo, - CheckID: testServiceCheckName, - Name: testServiceCheckName, - Status: HealthCritical, - ServiceID: testServiceName, - ServiceName: testServiceName, - }, - }, - } + require.NoError(t, testClients.createConsulPartition(partitionOne)) + require.NoError(t, testClients.createConsulPartition(partitionTwo)) + require.NoError(t, testClients.createConsulSamenessGroups(samenessGroup, partitionOne, partitionTwo)) - testConnectName := "conn-enabled-service-proxy" - testConnectCheckName := fmt.Sprintf("%s:%s", testConnectName, nodeFoo) - testConnectRegistration := &api.CatalogRegistration{ - Service: &api.AgentService{ - Kind: api.ServiceKindConnectProxy, - ID: testConnectName, - Service: testConnectName, - Port: 21999, - Proxy: &api.AgentServiceConnectProxyConfig{ - DestinationServiceName: testServiceName, - }, - Partition: fooPartition, - Namespace: "default", - }, - Partition: fooPartition, - Node: nodeFoo, - Address: "127.0.0.1", - Checks: api.HealthChecks{ - &api.HealthCheck{ - Node: nodeFoo, - CheckID: testConnectCheckName, - Name: testConnectCheckName, - Status: HealthCritical, - ServiceID: testConnectName, - ServiceName: testConnectName, + // Register services in foo partition as critical so they will fall back to default partition service + svcName := "sameness-group-service" + registerSvc := func(service, node, partition, status string) { + checkName := fmt.Sprintf("%s:%s", service, node) + svcRegistration := &api.CatalogRegistration{ + Service: &api.AgentService{ + ID: service, + Service: service, + Port: 12345, + Partition: partition, + Namespace: "default", + Connect: &api.AgentServiceConnect{}, + }, + Partition: partition, + Node: node, + Address: "127.0.0.1", + Checks: api.HealthChecks{ + &api.HealthCheck{ + Node: node, + CheckID: checkName, + Name: checkName, + Status: status, + ServiceID: svcName, + ServiceName: svcName, + }, }, - }, - } - - _, err := catalog.Register(testServiceRegistration, nil) - if err != nil { - t.Fatal(err) - } - - _, err = catalog.Register(testConnectRegistration, nil) - if err != nil { - t.Fatal(err) - } - - // Register in default partition as passing so it can fall back - testServiceRegistration.Service.Partition = defaultPartition - testServiceRegistration.Partition = defaultPartition - testServiceRegistration.Node = nodeDefault - testServiceRegistration.Checks[0].Node = nodeDefault - testServiceRegistration.Checks[0].CheckID = fmt.Sprintf("%s:%s", testServiceName, nodeDefault) - testServiceRegistration.Checks[0].Name = fmt.Sprintf("%s:%s", testServiceName, nodeDefault) - testServiceRegistration.Checks[0].Status = HealthPassing + } - _, err = catalog.Register(testServiceRegistration, nil) - if err != nil { - t.Fatal(err) + _, err := catalog.Register(svcRegistration, nil) + if err != nil { + t.Fatal(err) + } } - testConnectRegistration.Service.Partition = defaultPartition - testConnectRegistration.Partition = defaultPartition - testConnectRegistration.Node = nodeDefault - testConnectRegistration.Checks[0].Node = nodeDefault - testConnectRegistration.Checks[0].CheckID = fmt.Sprintf("%s:%s", testServiceName, nodeDefault) - testConnectRegistration.Checks[0].Name = fmt.Sprintf("%s:%s", testServiceName, nodeDefault) - testConnectRegistration.Checks[0].Status = HealthPassing - _, err = catalog.Register(testConnectRegistration, nil) - if err != nil { - t.Fatal(err) - } + // set up partition one to be unhealthy so that it will fall back to partition two + registerSvc(svcName, nodeOne, partitionOne, "critical") + registerSvc(svcName, nodeTwo, partitionTwo, "passing") // Act - fetch the service - query := fmt.Sprintf("service-meta?sameness-group=%s&partition=%s", "service-meta-sameness-group", fooPartition) + query := fmt.Sprintf("%s?sameness-group=%s&partition=%s", svcName, samenessGroup, partitionOne) d, err := NewHealthServiceQuery(query) if err != nil { t.Fatal(err) @@ -847,18 +799,17 @@ func TestHealthServiceQuery_Fetch_SamenessGroup(t *testing.T) { // Assert - verify the results expectedResult := []*HealthService{ { - Node: "node" + defaultPartition, - NodeAddress: testConsul.Config.Bind, - ServiceMeta: map[string]string{ - "meta1": "value1", - }, + Node: nodeTwo, + NodeAddress: testConsul.Config.Bind, + ServiceMeta: map[string]string{}, Address: testConsul.Config.Bind, NodeTaggedAddresses: map[string]string{}, NodeMeta: map[string]string{}, - ID: "service-meta", - Name: "service-meta", - Tags: []string{"tag1"}, - Status: "passing", + Port: 12345, + ID: svcName, + Name: svcName, + Tags: []string{}, + Status: HealthPassing, Weights: api.AgentWeights{ Passing: 1, Warning: 1, From b182e68e7b5cd24d15b129d848bb10fd53fde41b Mon Sep 17 00:00:00 2001 From: John Murret Date: Wed, 24 Apr 2024 12:33:57 -0600 Subject: [PATCH 03/16] add SamenessGroup to Merge() --- dependency/dependency.go | 4 ++++ go.mod | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dependency/dependency.go b/dependency/dependency.go index 941877779..692616ab1 100644 --- a/dependency/dependency.go +++ b/dependency/dependency.go @@ -151,6 +151,10 @@ func (q *QueryOptions) Merge(o *QueryOptions) *QueryOptions { r.ConsulPeer = o.ConsulPeer } + if o.ConsulSamenessGroup != "" { + r.ConsulSamenessGroup = o.ConsulSamenessGroup + } + return &r } diff --git a/go.mod b/go.mod index c216978f5..ef423ee92 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module consul-template +module github.com/hashicorp/consul-template go 1.22 From cf00e10ca27186cfc84087ed2720ff286e0430ac Mon Sep 17 00:00:00 2001 From: John Murret Date: Wed, 24 Apr 2024 12:43:38 -0600 Subject: [PATCH 04/16] update deprecated golangci setting --- .golangci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 11aec7c27..279714be4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -22,6 +22,7 @@ issues: exclude-rules: - text: 'shadow: declaration of "(err|ctx)" shadows declaration at' linters: [ govet ] + exclude-dirs-use-default: false linters-settings: govet: @@ -88,5 +89,4 @@ linters-settings: run: timeout: 10m - concurrency: 4 - skip-dirs-use-default: false \ No newline at end of file + concurrency: 4 \ No newline at end of file From f9ff0d8582134bf82117e2a01e8d95d89006cf0f Mon Sep 17 00:00:00 2001 From: John Murret Date: Wed, 24 Apr 2024 13:01:56 -0600 Subject: [PATCH 05/16] fix linting error --- dependency/health_service_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependency/health_service_test.go b/dependency/health_service_test.go index 946a224d2..edf37500f 100644 --- a/dependency/health_service_test.go +++ b/dependency/health_service_test.go @@ -247,7 +247,7 @@ func TestNewHealthServiceQuery(t *testing.T) { tc := test.(testCase) t.Run(fmt.Sprintf("%d_%s", i, tc.name), func(t *testing.T) { act, err := NewHealthServiceQuery(tc.i) - assert.Equal(t, err, tc.err) + assert.Equal(t, tc.err, err) if act != nil { act.stopCh = nil From 1317ef7a78ee1fb6cb7ab592527469d4d7334715 Mon Sep 17 00:00:00 2001 From: John Murret Date: Wed, 24 Apr 2024 15:39:41 -0600 Subject: [PATCH 06/16] fixing failing test --- dependency/health_service_test.go | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/dependency/health_service_test.go b/dependency/health_service_test.go index edf37500f..0c69d4d9d 100644 --- a/dependency/health_service_test.go +++ b/dependency/health_service_test.go @@ -53,7 +53,7 @@ func TestNewHealthServiceQuery(t *testing.T) { tenancyHelper.AppendTenancyInfo("query_only", tenancy), fmt.Sprintf("?ns=%s", tenancy.Namespace), nil, - fmt.Errorf(`health.service: invalid format: "?ns=default"`), + fmt.Errorf(`health.service: invalid format: "?ns=%s"`, tenancy.Namespace), }, testCase{ tenancyHelper.AppendTenancyInfo("invalid query param (unsupported key)", tenancy), @@ -656,35 +656,6 @@ func TestHealthServiceQuery_Fetch(t *testing.T) { }, }, }, - testCase{ - fmt.Sprintf(`service-meta for sameness group "%s" in partition "%s"`, "service-meta-sameness-group", tenancy.Partition), - fmt.Sprintf("service-meta?sameness-group=%s&partition=%s", "service-meta-sameness-group", tenancy.Partition), - []*HealthService{ - { - Node: "node" + tenancy.Partition, - NodeAddress: testConsul.Config.Bind, - NodeTaggedAddresses: map[string]string{ - //"lan": "127.0.0.1", - //"wan": "127.0.0.1", - }, - NodeMeta: map[string]string{ - //"consul-network-segment": "", - }, - ServiceMeta: map[string]string{ - "meta1": "value1", - }, - Address: testConsul.Config.Bind, - ID: "service-meta", - Name: "service-meta", - Tags: []string{"tag1"}, - Status: "passing", - Weights: api.AgentWeights{ - Passing: 1, - Warning: 1, - }, - }, - }, - }, } })...) From 31448b40c31341d93a9cf5a9ddf9b3d127c64380 Mon Sep 17 00:00:00 2001 From: John Murret Date: Mon, 6 May 2024 11:15:13 -0600 Subject: [PATCH 07/16] add blocking query tests for sameness groups. --- dependency/health_service_test.go | 97 ++++++++++++++++++++----------- go.mod | 5 +- go.sum | 23 ++++++-- 3 files changed, 84 insertions(+), 41 deletions(-) diff --git a/dependency/health_service_test.go b/dependency/health_service_test.go index 0c69d4d9d..8dbc276d9 100644 --- a/dependency/health_service_test.go +++ b/dependency/health_service_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" "reflect" "testing" + "time" "unsafe" "github.com/hashicorp/consul-template/test" @@ -690,6 +691,9 @@ func TestHealthServiceQuery_Fetch(t *testing.T) { } } +// TestHealthServiceQuery_Fetch_SamenessGroup tests fetching services with sameness group +// and asserts that failover works when a service in the sameness group fails and consul-template +// reacts to the change. func TestHealthServiceQuery_Fetch_SamenessGroup(t *testing.T) { // Arrange - set up test data catalog := testClients.Consul().Catalog() @@ -738,8 +742,8 @@ func TestHealthServiceQuery_Fetch_SamenessGroup(t *testing.T) { } } - // set up partition one to be unhealthy so that it will fall back to partition two - registerSvc(svcName, nodeOne, partitionOne, "critical") + // set up service in each partition + registerSvc(svcName, nodeOne, partitionOne, "passing") registerSvc(svcName, nodeTwo, partitionTwo, "passing") // Act - fetch the service @@ -749,45 +753,72 @@ func TestHealthServiceQuery_Fetch_SamenessGroup(t *testing.T) { t.Fatal(err) } - act, _, err := d.Fetch(testClients, nil) + svcs, meta, err := d.Fetch(testClients, nil) if err != nil { t.Fatal(err) } - if act != nil { - for _, v := range act.([]*HealthService) { - v.NodeID = "" - v.Checks = nil - // delete any version data from ServiceMeta - v.ServiceMeta = filterVersionMeta(v.ServiceMeta) - v.NodeTaggedAddresses = filterAddresses( - v.NodeTaggedAddresses) - v.NodeMeta = filterVersionMeta(v.NodeMeta) + healthServices := svcs.([]*HealthService) + require.True(t, len(healthServices) == 1) + require.Equal(t, "node"+partitionOne, healthServices[0].Node) + // set up blocking query with last index + dataCh := make(chan interface{}, 1) + errCh := make(chan error, 1) + go func() { + data, _, err := d.Fetch(testClients, &QueryOptions{WaitIndex: meta.LastIndex}) + if err != nil { + errCh <- err + return } - } + dataCh <- data + }() - // Assert - verify the results - expectedResult := []*HealthService{ - { - Node: nodeTwo, - NodeAddress: testConsul.Config.Bind, - ServiceMeta: map[string]string{}, - Address: testConsul.Config.Bind, - NodeTaggedAddresses: map[string]string{}, - NodeMeta: map[string]string{}, - Port: 12345, - ID: svcName, - Name: svcName, - Tags: []string{}, - Status: HealthPassing, - Weights: api.AgentWeights{ - Passing: 1, - Warning: 1, - }, - }, + // update partition one to initiate failover + registerSvc(svcName, nodeOne, partitionOne, "critical") + + select { + case err := <-errCh: + if err != ErrStopped { + t.Fatal(err) + } + case <-time.After(1 * time.Minute): + t.Errorf("did not stop") + case val := <-dataCh: + if val != nil { + for _, v := range val.([]*HealthService) { + v.NodeID = "" + v.Checks = nil + // delete any version data from ServiceMeta + v.ServiceMeta = filterVersionMeta(v.ServiceMeta) + v.NodeTaggedAddresses = filterAddresses( + v.NodeTaggedAddresses) + v.NodeMeta = filterVersionMeta(v.NodeMeta) + } + } + + // Assert - verify the results + expectedResult := []*HealthService{ + { + Node: nodeTwo, + NodeAddress: testConsul.Config.Bind, + ServiceMeta: map[string]string{}, + Address: testConsul.Config.Bind, + NodeTaggedAddresses: map[string]string{}, + NodeMeta: map[string]string{}, + Port: 12345, + ID: svcName, + Name: svcName, + Tags: []string{}, + Status: HealthPassing, + Weights: api.AgentWeights{ + Passing: 1, + Warning: 1, + }, + }, + } + assert.Equal(t, expectedResult, val) } - assert.Equal(t, expectedResult, act) } func TestHealthServiceQuery_String(t *testing.T) { diff --git a/go.mod b/go.mod index ef423ee92..eb36dd6a7 100644 --- a/go.mod +++ b/go.mod @@ -33,8 +33,6 @@ require ( ) require ( - github.com/Masterminds/sprig/v3 v3.2.3 - github.com/hashicorp/vault/api/auth/kubernetes v0.5.0 golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 golang.org/x/text v0.14.0 ) @@ -49,7 +47,7 @@ require ( github.com/google/uuid v1.3.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/hashicorp/consul/proto-public v0.6.1 // indirect - github.com/hashicorp/cronexpr v1.1.1 // indirect + github.com/hashicorp/cronexpr v1.1.2 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect @@ -59,6 +57,7 @@ require ( github.com/hashicorp/go-uuid v1.0.3 // indirect github.com/hashicorp/go-version v1.6.0 // indirect github.com/hashicorp/golang-lru v1.0.2 // indirect + github.com/hashicorp/serf v0.10.1 // indirect github.com/huandu/xstrings v1.4.0 // indirect github.com/imdario/mergo v0.3.13 // indirect github.com/mattn/go-colorable v0.1.13 // indirect diff --git a/go.sum b/go.sum index 2bf1cc6bf..ec79ab556 100644 --- a/go.sum +++ b/go.sum @@ -40,9 +40,11 @@ github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= +github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk= +github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= -github.com/go-jose/go-jose/v3 v3.0.0/go.mod h1:RNkWWRld676jZEYoV3+XK8L2ZnNSvIsxFMht0mSX+u8= +github.com/go-jose/go-jose/v3 v3.0.1/go.mod h1:RNkWWRld676jZEYoV3+XK8L2ZnNSvIsxFMht0mSX+u8= github.com/go-jose/go-jose/v3 v3.0.3 h1:fFKWeig/irsp7XD2zBxvnmA/XaRWp5V3CBsZXJF7G7k= github.com/go-jose/go-jose/v3 v3.0.3/go.mod h1:5b+7YgP7ZICgJDBdfjZaIt+H/9L9T/YQrVfLAMboGkQ= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= @@ -80,8 +82,8 @@ github.com/hashicorp/consul/proto-public v0.6.1 h1:+uzH3olCrksXYWAYHKqK782CtK9sc github.com/hashicorp/consul/proto-public v0.6.1/go.mod h1:cXXbOg74KBNGajC+o8RlA502Esf0R9prcoJgiOX/2Tg= github.com/hashicorp/consul/sdk v0.15.0 h1:2qK9nDrr4tiJKRoxPGhm6B7xJjLVIQqkjiab2M4aKjU= github.com/hashicorp/consul/sdk v0.15.0/go.mod h1:r/OmRRPbHOe0yxNahLw7G9x5WG17E1BIECMtCjcPSNo= -github.com/hashicorp/cronexpr v1.1.1 h1:NJZDd87hGXjoZBdvyCF9mX4DCq5Wy7+A/w+A7q0wn6c= -github.com/hashicorp/cronexpr v1.1.1/go.mod h1:P4wA0KBl9C5q2hABiMO7cp6jcIg96CDh1Efb3g1PWA4= +github.com/hashicorp/cronexpr v1.1.2 h1:wG/ZYIKT+RT3QkOdgYc+xsKWVRgnxJ1OJtjjy84fJ9A= +github.com/hashicorp/cronexpr v1.1.2/go.mod h1:P4wA0KBl9C5q2hABiMO7cp6jcIg96CDh1Efb3g1PWA4= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -183,7 +185,6 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= -github.com/miekg/dns v1.1.41 h1:WMszZWJG0XmzbK9FEmzH2TVcqYzFesusSIB41b8KHxY= github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= github.com/miekg/dns v1.1.50 h1:DQUfb9uc6smULcREF09Uc+/Gd46YWqJd5DbpPE9xkcA= github.com/miekg/dns v1.1.50/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME= @@ -271,14 +272,17 @@ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= -golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= @@ -295,11 +299,14 @@ golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8= +golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -328,6 +335,8 @@ golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -340,6 +349,8 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= @@ -368,11 +379,13 @@ golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw= golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 h1:KpwkzHKEF7B9Zxg18WzOa7djJ+Ha5DzthMyZYQfEn2A= From 64b76c0114396f3c7e31b972b798d54c15ed3a88 Mon Sep 17 00:00:00 2001 From: John Murret Date: Mon, 3 Jun 2024 11:22:35 -0600 Subject: [PATCH 08/16] add docs --- docs/templating-language.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/templating-language.md b/docs/templating-language.md index 4892e5489..4bbf94ea7 100644 --- a/docs/templating-language.md +++ b/docs/templating-language.md @@ -775,12 +775,16 @@ Query [Consul][consul] for services based on their health. The `` attribute is optional; if omitted, all nodes will be queried. -The `` attribute is optional; if omitted, the `default` Consul namespace, `default` partition will be queried. `` can be used to set the Consul [namespace](https://developer.hashicorp.com/consul/api-docs/health#ns-2), partition, or [peer](https://developer.hashicorp.com/consul/api-docs/health#peer). `` accepts a url query-parameter format, e.g.: +The `` attribute is optional; if omitted, the `default` Consul namespace, `default` partition will be queried. `` can be used to set the Consul [namespace](https://developer.hashicorp.com/consul/api-docs/health#ns-2), partition, sameness group, or [peer](https://developer.hashicorp.com/consul/api-docs/health#peer). `` accepts a url query-parameter format, e.g.: ```golang {{ service "service-name?ns=namespace-name&peer=peer-name&partition=partition-name" }} ``` +```golang +{{ service "service-name?sameness-group=sameness-group-name" }} +``` + The `` attribute is optional; if omitted, the local datacenter is used. @@ -872,7 +876,7 @@ Query [Consul][consul] for all services in the catalog. {{ services "?@" }} ``` -The `` attribute is optional; if omitted, the `default` Consul namespace, `default` partition will be queried. `` can be used to set the Consul [namespace](https://developer.hashicorp.com/consul/api-docs/health#ns-2) or partition. `` accepts a url query-parameter format, e.g.: +The `` attribute is optional; if omitted, the `default` Consul namespace, `default` partition will be queried. `` can be used to set the Consul [namespace](https://developer.hashicorp.com/consul/api-docs/health#ns-2), sameness-group, or partition. `` accepts a url query-parameter format, e.g.: ```golang {{ range services "?ns=default&partition=default" }} @@ -880,6 +884,12 @@ The `` attribute is optional; if omitted, the `default` Consul namespace, {{ end }} ``` +```golang +{{ range services "?sameness-group=sameness-group-name" }} + {{ .Name }} +{{ end }} +``` + The `` attribute is optional; if omitted, the local datacenter is used. From 9f3c1380055d904d3bbeedf1f715c110f76e3525 Mon Sep 17 00:00:00 2001 From: John Murret Date: Mon, 3 Jun 2024 15:48:42 -0600 Subject: [PATCH 09/16] Apply suggestions from code review Co-authored-by: Luke Kysow <1034429+lkysow@users.noreply.github.com> --- dependency/health_service_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dependency/health_service_test.go b/dependency/health_service_test.go index 8dbc276d9..40a093525 100644 --- a/dependency/health_service_test.go +++ b/dependency/health_service_test.go @@ -758,6 +758,9 @@ func TestHealthServiceQuery_Fetch_SamenessGroup(t *testing.T) { t.Fatal(err) } + // Assert that the service instance returned is from the first listed partition. + // This is expected because the service is healthy so it shouldn't failover + // to other partitions. healthServices := svcs.([]*HealthService) require.True(t, len(healthServices) == 1) require.Equal(t, "node"+partitionOne, healthServices[0].Node) @@ -800,6 +803,7 @@ func TestHealthServiceQuery_Fetch_SamenessGroup(t *testing.T) { // Assert - verify the results expectedResult := []*HealthService{ { + // The instance should now be from the failover partition. Node: nodeTwo, NodeAddress: testConsul.Config.Bind, ServiceMeta: map[string]string{}, From c9ea6a9103e8c34c58609d82800d266cd7eff9c4 Mon Sep 17 00:00:00 2001 From: John Murret Date: Mon, 3 Jun 2024 15:48:59 -0600 Subject: [PATCH 10/16] fixing PR suggestions. --- dependency/dependency_test.go | 15 ++++----------- dependency/health_service.go | 8 ++++---- dependency/health_service_test.go | 2 +- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/dependency/dependency_test.go b/dependency/dependency_test.go index d83e77547..f5acf1c91 100644 --- a/dependency/dependency_test.go +++ b/dependency/dependency_test.go @@ -236,24 +236,17 @@ func (c *ClientSet) createConsulSamenessGroups(name, partition, failoverPartitio Partition: failoverPartition, }) sg := &api.SamenessGroupConfigEntry{ - Kind: QuerySamenessGroup, + Kind: api.SamenessGroup, Name: name, Partition: partition, DefaultForFailover: true, Members: members, } - log.Printf("sameness group: %+v", sg) _, _, err := c.consul.client.ConfigEntries().Set(sg, &api.WriteOptions{}) if err != nil { return err } - sgs, _, err := c.consul.client.ConfigEntries().List(QuerySamenessGroup, &api.QueryOptions{}) - if err != nil { - return err - } - log.Printf("sameness groups: %+v", sgs) - return nil } @@ -563,9 +556,9 @@ func (v *nomadServer) DeleteVariable(path string, opts *nomadapi.WriteOptions) e func (c *ClientSet) createConsulPartitions() error { for p := range tenancyHelper.GetUniquePartitions() { if p.Name != "" && p.Name != "default" { - err2 := c.createConsulPartition(p.Name) - if err2 != nil { - return err2 + err := c.createConsulPartition(p.Name) + if err != nil { + return err } } } diff --git a/dependency/health_service.go b/dependency/health_service.go index ed9f714f6..708347e05 100644 --- a/dependency/health_service.go +++ b/dependency/health_service.go @@ -124,6 +124,10 @@ func healthServiceQuery(s string, connect bool) (*HealthServiceQuery, error) { return nil, err } + if queryParams.Get(QuerySamenessGroup) != "" && queryParams.Get(QueryPeer) != "" { + return nil, fmt.Errorf("health.service: cannot specify both peer and sameness-group") + } + qry := &HealthServiceQuery{ stopCh: make(chan struct{}, 1), dc: m["dc"], @@ -138,10 +142,6 @@ func healthServiceQuery(s string, connect bool) (*HealthServiceQuery, error) { samenessGroup: queryParams.Get(QuerySamenessGroup), } - if qry.samenessGroup != "" && qry.peer != "" { - return nil, fmt.Errorf("health.service: cannot specify both peer and sameness-group") - } - return qry, nil } diff --git a/dependency/health_service_test.go b/dependency/health_service_test.go index 40a093525..cc55b22f8 100644 --- a/dependency/health_service_test.go +++ b/dependency/health_service_test.go @@ -708,7 +708,7 @@ func TestHealthServiceQuery_Fetch_SamenessGroup(t *testing.T) { require.NoError(t, testClients.createConsulPartition(partitionTwo)) require.NoError(t, testClients.createConsulSamenessGroups(samenessGroup, partitionOne, partitionTwo)) - // Register services in foo partition as critical so they will fall back to default partition service + // Register services with the same name in partionOne and partitionTwo and them to a sameness group so that we can test failover. svcName := "sameness-group-service" registerSvc := func(service, node, partition, status string) { checkName := fmt.Sprintf("%s:%s", service, node) From 83566365f857baedbd840f7ccdb50b8682532f18 Mon Sep 17 00:00:00 2001 From: John Murret Date: Mon, 3 Jun 2024 16:38:43 -0600 Subject: [PATCH 11/16] adding sameness-group to validation for query params for service calls --- dependency/dependency.go | 2 +- dependency/health_service_test.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dependency/dependency.go b/dependency/dependency.go index 692616ab1..29ed744ad 100644 --- a/dependency/dependency.go +++ b/dependency/dependency.go @@ -194,7 +194,7 @@ func GetConsulQueryOpts(queryMap map[string]string, endpointLabel string) (url.V QuerySamenessGroup: default: return nil, - fmt.Errorf("%s: invalid query parameter key %q in query %q: supported keys: %s,%s,%s", endpointLabel, key, queryRaw, QueryNamespace, QueryPeer, QueryPartition) + fmt.Errorf("%s: invalid query parameter key %q in query %q: supported keys: %s,%s,%s,%s", endpointLabel, key, queryRaw, QueryNamespace, QueryPeer, QueryPartition, QuerySamenessGroup) } } } diff --git a/dependency/health_service_test.go b/dependency/health_service_test.go index cc55b22f8..677b836b9 100644 --- a/dependency/health_service_test.go +++ b/dependency/health_service_test.go @@ -60,7 +60,7 @@ func TestNewHealthServiceQuery(t *testing.T) { tenancyHelper.AppendTenancyInfo("invalid query param (unsupported key)", tenancy), "name?unsupported=test", nil, - fmt.Errorf(`health.service: invalid query parameter key "unsupported" in query "unsupported=test": supported keys: ns,peer,partition`), + fmt.Errorf(`health.service: invalid query parameter key "unsupported" in query "unsupported=test": supported keys: ns,peer,partition,sameness-group`), }, testCase{ tenancyHelper.AppendTenancyInfo("name", tenancy), @@ -758,9 +758,9 @@ func TestHealthServiceQuery_Fetch_SamenessGroup(t *testing.T) { t.Fatal(err) } - // Assert that the service instance returned is from the first listed partition. - // This is expected because the service is healthy so it shouldn't failover - // to other partitions. + // Assert that the service instance returned is from the first listed partition. + // This is expected because the service is healthy so it shouldn't failover + // to other partitions. healthServices := svcs.([]*HealthService) require.True(t, len(healthServices) == 1) require.Equal(t, "node"+partitionOne, healthServices[0].Node) @@ -803,7 +803,7 @@ func TestHealthServiceQuery_Fetch_SamenessGroup(t *testing.T) { // Assert - verify the results expectedResult := []*HealthService{ { - // The instance should now be from the failover partition. + // The instance should now be from the failover partition. Node: nodeTwo, NodeAddress: testConsul.Config.Bind, ServiceMeta: map[string]string{}, From 897d087e8cc311509e0edb57f79caaae9b52809a Mon Sep 17 00:00:00 2001 From: John Murret Date: Mon, 3 Jun 2024 16:43:59 -0600 Subject: [PATCH 12/16] Update dependency/health_service.go Co-authored-by: Luke Kysow <1034429+lkysow@users.noreply.github.com> --- dependency/health_service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependency/health_service.go b/dependency/health_service.go index 708347e05..ab0ad3924 100644 --- a/dependency/health_service.go +++ b/dependency/health_service.go @@ -125,7 +125,7 @@ func healthServiceQuery(s string, connect bool) (*HealthServiceQuery, error) { } if queryParams.Get(QuerySamenessGroup) != "" && queryParams.Get(QueryPeer) != "" { - return nil, fmt.Errorf("health.service: cannot specify both peer and sameness-group") + return nil, fmt.Errorf("health.service: cannot specify both %s and %s", QueryPeer, QuerySamenessGroup) } qry := &HealthServiceQuery{ From efa1f0d1efb9223a11ea845682b67e7e2aa27d16 Mon Sep 17 00:00:00 2001 From: John Murret Date: Mon, 3 Jun 2024 16:47:47 -0600 Subject: [PATCH 13/16] change @samenessGroup to @sameness-group --- dependency/health_service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependency/health_service.go b/dependency/health_service.go index ab0ad3924..7c4517a57 100644 --- a/dependency/health_service.go +++ b/dependency/health_service.go @@ -272,7 +272,7 @@ func (d *HealthServiceQuery) String() string { name = name + "@peer=" + d.peer } if d.samenessGroup != "" { - name = name + "@samenessGroup=" + d.samenessGroup + name = name + "@sameness-group=" + d.samenessGroup } if d.near != "" { name = name + "~" + d.near From 15dd6c0f9e83705d905424db8d43fe2545248f6f Mon Sep 17 00:00:00 2001 From: John Murret Date: Mon, 3 Jun 2024 16:55:43 -0600 Subject: [PATCH 14/16] updated docstring for TestHealthServiceQuery_Fetch_SamenessGroup to note that full behavior for sameness groups is asserted in the consul code base. --- dependency/health_service_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dependency/health_service_test.go b/dependency/health_service_test.go index 677b836b9..2f1c7a0f9 100644 --- a/dependency/health_service_test.go +++ b/dependency/health_service_test.go @@ -691,9 +691,9 @@ func TestHealthServiceQuery_Fetch(t *testing.T) { } } -// TestHealthServiceQuery_Fetch_SamenessGroup tests fetching services with sameness group -// and asserts that failover works when a service in the sameness group fails and consul-template -// reacts to the change. +// TestHealthServiceQuery_Fetch_SamenessGroup ensures that consul-template re-runs when the blocking query updates. +// The different behaviors of the blocking query, e.g. "when a service becomes unhealthy it should failover, +// when it becomes healthy again it should fail back", are tested in the Consul codebase. func TestHealthServiceQuery_Fetch_SamenessGroup(t *testing.T) { // Arrange - set up test data catalog := testClients.Consul().Catalog() From afdafc8122fa37c4226546f2bfbac16b30467947 Mon Sep 17 00:00:00 2001 From: John Murret Date: Tue, 4 Jun 2024 16:26:47 -0600 Subject: [PATCH 15/16] update documentation for sameness group behavior --- docs/templating-language.md | 21 +++++++++----- go.mod | 23 ++++++++-------- go.sum | 55 ++++++++++++++----------------------- 3 files changed, 45 insertions(+), 54 deletions(-) diff --git a/docs/templating-language.md b/docs/templating-language.md index 4bbf94ea7..387bcb976 100644 --- a/docs/templating-language.md +++ b/docs/templating-language.md @@ -781,9 +781,22 @@ The `` attribute is optional; if omitted, the `default` Consul namespace, {{ service "service-name?ns=namespace-name&peer=peer-name&partition=partition-name" }} ``` +When using the `sameness-group` query parameter, the following rules are applied to use with other query parameters: +- `partition` is used to denote where the Sameness Group Config Entry is stored. +- `ns` is ignored. +- Either `peer` or `partition` can be used, but not both. + ```golang {{ service "service-name?sameness-group=sameness-group-name" }} ``` +When using the `sameness-group` query parameter, the result will be based on the following rules: +- The Sameness Group Config Entry will be retrieved using the `partition` and the `sameness-group` parameters. +- The `` attribute is optional; if omitted, the local datacenter is used. @@ -876,7 +889,7 @@ Query [Consul][consul] for all services in the catalog. {{ services "?@" }} ``` -The `` attribute is optional; if omitted, the `default` Consul namespace, `default` partition will be queried. `` can be used to set the Consul [namespace](https://developer.hashicorp.com/consul/api-docs/health#ns-2), sameness-group, or partition. `` accepts a url query-parameter format, e.g.: +The `` attribute is optional; if omitted, the `default` Consul namespace, `default` partition will be queried. `` can be used to set the Consul [namespace](https://developer.hashicorp.com/consul/api-docs/health#ns-2) or partition. `` accepts a url query-parameter format, e.g.: ```golang {{ range services "?ns=default&partition=default" }} @@ -884,12 +897,6 @@ The `` attribute is optional; if omitted, the `default` Consul namespace, {{ end }} ``` -```golang -{{ range services "?sameness-group=sameness-group-name" }} - {{ .Name }} -{{ end }} -``` - The `` attribute is optional; if omitted, the local datacenter is used. diff --git a/go.mod b/go.mod index eb36dd6a7..2fbb488f0 100644 --- a/go.mod +++ b/go.mod @@ -5,12 +5,10 @@ go 1.22 toolchain go1.22.4 require ( - dario.cat/mergo v1.0.0 github.com/BurntSushi/toml v1.3.2 - github.com/Masterminds/sprig/v3 v3.2.3 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc - github.com/hashicorp/consul/api v1.28.3 - github.com/hashicorp/consul/sdk v0.15.0 + github.com/hashicorp/consul/api v1.29.1 + github.com/hashicorp/consul/sdk v0.16.1 github.com/hashicorp/go-gatedio v0.5.0 github.com/hashicorp/go-hclog v1.6.3 github.com/hashicorp/go-multierror v1.1.1 @@ -19,20 +17,23 @@ require ( github.com/hashicorp/go-syslog v1.0.0 github.com/hashicorp/hcl v1.0.0 github.com/hashicorp/logutils v1.0.0 - github.com/hashicorp/nomad/api v0.0.0-20240306165712-3193ac204f65 - github.com/hashicorp/vault/api v1.12.0 - github.com/hashicorp/vault/api/auth/kubernetes v0.6.0 + github.com/hashicorp/nomad/api v0.0.0-20230103221135-ce00d683f9be + github.com/hashicorp/serf v0.10.1 // indirect + github.com/hashicorp/vault/api v1.10.0 github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/hashstructure v1.1.0 github.com/mitchellh/mapstructure v1.5.0 github.com/pkg/errors v0.9.1 - github.com/stretchr/testify v1.9.0 + github.com/stretchr/testify v1.8.4 golang.org/x/crypto v0.22.0 // indirect golang.org/x/sys v0.20.0 gopkg.in/yaml.v2 v2.4.0 ) require ( + dario.cat/mergo v1.0.0 + github.com/Masterminds/sprig/v3 v3.2.3 + github.com/hashicorp/vault/api/auth/kubernetes v0.5.0 golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 golang.org/x/text v0.14.0 ) @@ -46,8 +47,7 @@ require ( github.com/go-jose/go-jose/v3 v3.0.3 // indirect github.com/google/uuid v1.3.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect - github.com/hashicorp/consul/proto-public v0.6.1 // indirect - github.com/hashicorp/cronexpr v1.1.2 // indirect + github.com/hashicorp/cronexpr v1.1.1 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect @@ -57,9 +57,8 @@ require ( github.com/hashicorp/go-uuid v1.0.3 // indirect github.com/hashicorp/go-version v1.6.0 // indirect github.com/hashicorp/golang-lru v1.0.2 // indirect - github.com/hashicorp/serf v0.10.1 // indirect github.com/huandu/xstrings v1.4.0 // indirect - github.com/imdario/mergo v0.3.13 // indirect + github.com/imdario/mergo v0.3.11 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/miekg/dns v1.1.50 // indirect diff --git a/go.sum b/go.sum index ec79ab556..6aed2eb3c 100644 --- a/go.sum +++ b/go.sum @@ -40,11 +40,9 @@ github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= -github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk= -github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= -github.com/go-jose/go-jose/v3 v3.0.1/go.mod h1:RNkWWRld676jZEYoV3+XK8L2ZnNSvIsxFMht0mSX+u8= +github.com/go-jose/go-jose/v3 v3.0.0/go.mod h1:RNkWWRld676jZEYoV3+XK8L2ZnNSvIsxFMht0mSX+u8= github.com/go-jose/go-jose/v3 v3.0.3 h1:fFKWeig/irsp7XD2zBxvnmA/XaRWp5V3CBsZXJF7G7k= github.com/go-jose/go-jose/v3 v3.0.3/go.mod h1:5b+7YgP7ZICgJDBdfjZaIt+H/9L9T/YQrVfLAMboGkQ= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= @@ -76,14 +74,14 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/hashicorp/consul/api v1.28.3 h1:IE06LST/knnCQ+cxcvzyXRF/DetkgGhJoaOFd4l9xkk= -github.com/hashicorp/consul/api v1.28.3/go.mod h1:7AGcUFu28HkgOKD/GmsIGIFzRTmN0L02AE9Thsr2OhU= +github.com/hashicorp/consul/api v1.29.1 h1:UEwOjYJrd3lG1x5w7HxDRMGiAUPrb3f103EoeKuuEcc= +github.com/hashicorp/consul/api v1.29.1/go.mod h1:lumfRkY/coLuqMICkI7Fh3ylMG31mQSRZyef2c5YvJI= github.com/hashicorp/consul/proto-public v0.6.1 h1:+uzH3olCrksXYWAYHKqK782CtK9scfqH+Unlw3UHhCg= github.com/hashicorp/consul/proto-public v0.6.1/go.mod h1:cXXbOg74KBNGajC+o8RlA502Esf0R9prcoJgiOX/2Tg= -github.com/hashicorp/consul/sdk v0.15.0 h1:2qK9nDrr4tiJKRoxPGhm6B7xJjLVIQqkjiab2M4aKjU= -github.com/hashicorp/consul/sdk v0.15.0/go.mod h1:r/OmRRPbHOe0yxNahLw7G9x5WG17E1BIECMtCjcPSNo= -github.com/hashicorp/cronexpr v1.1.2 h1:wG/ZYIKT+RT3QkOdgYc+xsKWVRgnxJ1OJtjjy84fJ9A= -github.com/hashicorp/cronexpr v1.1.2/go.mod h1:P4wA0KBl9C5q2hABiMO7cp6jcIg96CDh1Efb3g1PWA4= +github.com/hashicorp/consul/sdk v0.16.1 h1:V8TxTnImoPD5cj0U9Spl0TUxcytjcbbJeADFF07KdHg= +github.com/hashicorp/consul/sdk v0.16.1/go.mod h1:fSXvwxB2hmh1FMZCNl6PwX0Q/1wdWtHJcZ7Ea5tns0s= +github.com/hashicorp/cronexpr v1.1.1 h1:NJZDd87hGXjoZBdvyCF9mX4DCq5Wy7+A/w+A7q0wn6c= +github.com/hashicorp/cronexpr v1.1.1/go.mod h1:P4wA0KBl9C5q2hABiMO7cp6jcIg96CDh1Efb3g1PWA4= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -141,20 +139,19 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO github.com/hashicorp/mdns v1.0.4/go.mod h1:mtBihi+LeNXGtG8L9dX59gAEa12BDtBQSp4v/YAJqrc= github.com/hashicorp/memberlist v0.5.0 h1:EtYPN8DpAURiapus508I4n9CzHs2W+8NZGbmmR/prTM= github.com/hashicorp/memberlist v0.5.0/go.mod h1:yvyXLpo0QaGE59Y7hDTsTzDD25JYBZ4mHgHUZ8lrOI0= -github.com/hashicorp/nomad/api v0.0.0-20240306165712-3193ac204f65 h1:bqSioPvnVoWlDnlsY1sXPW+ts8ywxD/Qz89lJZgwubA= -github.com/hashicorp/nomad/api v0.0.0-20240306165712-3193ac204f65/go.mod h1:z71gkJdrkAt/Rl6C7Q79VE7AwJ5lUF+M+fzFTyIHYB0= +github.com/hashicorp/nomad/api v0.0.0-20230103221135-ce00d683f9be h1:bJ/jBA5pt/5OT1oaApx8B5g/nRyohn61Q8TyUp4PoEI= +github.com/hashicorp/nomad/api v0.0.0-20230103221135-ce00d683f9be/go.mod h1:EM/2XaEwHziSB4NdWZ6MfE65TcvgWwVawOUBT8kVRqE= github.com/hashicorp/serf v0.10.1 h1:Z1H2J60yRKvfDYAOZLd2MU0ND4AH/WDz7xYHDWQsIPY= github.com/hashicorp/serf v0.10.1/go.mod h1:yL2t6BqATOLGc5HF7qbFkTfXoPIY0WZdWHfEvMqbG+4= -github.com/hashicorp/vault/api v1.12.0 h1:meCpJSesvzQyao8FCOgk2fGdoADAnbDu2WPJN1lDLJ4= -github.com/hashicorp/vault/api v1.12.0/go.mod h1:si+lJCYO7oGkIoNPAN8j3azBLTn9SjMGS+jFaHd1Cck= -github.com/hashicorp/vault/api/auth/kubernetes v0.6.0 h1:K8sKGhtTAqGKfzaaYvUSIOAqTOIn3Gk1EsCEAMzZHtM= -github.com/hashicorp/vault/api/auth/kubernetes v0.6.0/go.mod h1:Htwcjez5J9PwAHaZ1EYMBlgGq3/in5ajUV4+WCPihPE= +github.com/hashicorp/vault/api v1.10.0 h1:/US7sIjWN6Imp4o/Rj1Ce2Nr5bki/AXi9vAW3p2tOJQ= +github.com/hashicorp/vault/api v1.10.0/go.mod h1:jo5Y/ET+hNyz+JnKDt8XLAdKs+AM0G5W0Vp1IrFI8N8= +github.com/hashicorp/vault/api/auth/kubernetes v0.5.0 h1:CXO0fD7M3iCGovP/UApeHhPcH4paDFKcu7AjEXi94rI= +github.com/hashicorp/vault/api/auth/kubernetes v0.5.0/go.mod h1:afrElBIO9Q4sHFVuVWgNevG4uAs1bT2AZFA9aEiI608= github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU= github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= +github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA= github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= -github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= -github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= @@ -243,8 +240,8 @@ github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkB github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= -github.com/shoenig/test v1.7.1 h1:UJcjSAI3aUKx52kfcfhblgyhZceouhvvs3OYdWgn+PY= -github.com/shoenig/test v1.7.1/go.mod h1:UxJ6u/x2v/TNs/LoLxBNJRV9DiwBBKYxXSyczsBHFoI= +github.com/shoenig/test v0.5.2 h1:ELZ7qZ/6CPrT71PXrSe2TFzLs4/cGCqqU5lZ5RhZ+B8= +github.com/shoenig/test v0.5.2/go.mod h1:xYtyGBC5Q3kzCNyJg/SjgNpfAa2kvmgA0i5+lQso8x0= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= @@ -255,22 +252,17 @@ github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= @@ -281,8 +273,7 @@ golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3 golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= -golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= -golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= @@ -305,8 +296,8 @@ golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -349,8 +340,6 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= @@ -359,8 +348,6 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= -golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= -golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= @@ -370,7 +357,6 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -407,6 +393,5 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From b725045452c8ffcc9fa681146ab865aa96e96fd4 Mon Sep 17 00:00:00 2001 From: John Murret Date: Tue, 18 Jun 2024 14:04:20 -0600 Subject: [PATCH 16/16] skip sameness test if not consul enterprise --- dependency/health_service_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dependency/health_service_test.go b/dependency/health_service_test.go index 2f1c7a0f9..fb6c1cf65 100644 --- a/dependency/health_service_test.go +++ b/dependency/health_service_test.go @@ -695,6 +695,9 @@ func TestHealthServiceQuery_Fetch(t *testing.T) { // The different behaviors of the blocking query, e.g. "when a service becomes unhealthy it should failover, // when it becomes healthy again it should fail back", are tested in the Consul codebase. func TestHealthServiceQuery_Fetch_SamenessGroup(t *testing.T) { + if !tenancyHelper.IsConsulEnterprise() { + t.Skip("Enterprise only test") + } // Arrange - set up test data catalog := testClients.Consul().Catalog()