From edd0f7394427f64c6fc9de7aa74dd6bac9c32f80 Mon Sep 17 00:00:00 2001 From: John Murret Date: Mon, 3 Jun 2024 15:48:59 -0600 Subject: [PATCH] fixing PR suggestions. --- dependency/dependency_test.go | 15 ++++----------- dependency/health_service.go | 8 ++++---- dependency/health_service_test.go | 2 +- go.mod | 4 ++++ 4 files changed, 13 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) diff --git a/go.mod b/go.mod index 79536ffe8..28b8bef6b 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,10 @@ module github.com/hashicorp/consul-template go 1.22 +// used to test locally +replace ( + github.com/hashicorp/consul/api => ../consul/api +) require ( dario.cat/mergo v1.0.0 github.com/BurntSushi/toml v1.3.2