Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NET-7571] Ensure services function uses specified Consul namespace #1874

Merged
merged 6 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
NEW FEATURES:
* Add support for listing Consul peers [NET-6966](https://hashicorp.atlassian.net/browse/NET-6966)

BUG FIXES:
* Fetch services query not overriding opts correctly [NET-7571](https://hashicorp.atlassian.net/browse/NET-7571)

## v0.36.0 (January 3, 2024)

IMPROVEMENTS:
Expand Down
10 changes: 8 additions & 2 deletions dependency/catalog_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,17 @@ func (d *CatalogServicesQuery) Fetch(clients *ClientSet, opts *QueryOptions) (in
default:
}

opts = opts.Merge(&QueryOptions{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this was the problem, I think it was the String() function not being unique for different ns/partition queries. I think this function is only ever called here: https://github.com/hashicorp/consul-template/blob/main/watch/view.go#L218-L222 and so there's no issue with the merge order.

// this overrides the query params present in the query with ones present while creating the query
// see bug [https://github.com/hashicorp/consul-template/pull/1842#issuecomment-1915723565]
// default to the query params present while creating NewCatalogServicesQuery
// and then merge with the query params present in the query
defaultOpts := &QueryOptions{
Datacenter: d.dc,
ConsulPartition: d.partition,
ConsulNamespace: d.namespace,
})
}

opts = defaultOpts.Merge(opts)

log.Printf("[TRACE] %s: GET %s", d, &url.URL{
Path: "/v1/catalog/services",
Expand Down
13 changes: 11 additions & 2 deletions dependency/catalog_services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,14 @@ func TestCatalogServicesQuery_Fetch(t *testing.T) {
cases := []struct {
name string
i string
opts *QueryOptions
exp []*CatalogSnippet
err bool
}{
{
"all",
"",
nil,
[]*CatalogSnippet{
{
Name: "consul",
Expand All @@ -123,21 +126,27 @@ func TestCatalogServicesQuery_Fetch(t *testing.T) {
Tags: ServiceTags([]string{}),
},
},
false,
},
}

for i, tc := range cases {
t.Run(fmt.Sprintf("%d_%s", i, tc.name), func(t *testing.T) {

d, err := NewCatalogServicesQuery(tc.i)
if err != nil {
t.Fatal(err)
}

act, _, err := d.Fetch(testClients, nil)
if err != nil {
act, _, err := d.Fetch(testClients, tc.opts)
if (err != nil) != tc.err {
t.Fatal(err)
}

if act == nil && tc.err {
return
}

assert.Equal(t, tc.exp, act)
})
}
Expand Down
Loading