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

consul: add tests for meta/canarymeta interpolation #9130

Merged
merged 3 commits into from
Oct 20, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ BUG FIXES:
* core: Fixed a bug where blocking queries would not include the query's maximum wait time when calculating whether it was safe to retry. [[GH-8921](https://github.com/hashicorp/nomad/issues/8921)]
* config (Enterprise): Fixed default enterprise config merging. [[GH-9083](https://github.com/hashicorp/nomad/pull/9083)]
* consul: Fixed a bug to correctly validate task when using script-checks in group-level services [[GH-8952](https://github.com/hashicorp/nomad/issues/8952)]
* consul: Fixed a bug where canary_meta was not being interpolated with environment variables [[GH-9096](https://github.com/hashicorp/nomad/pull/9096)]
* consul/connect: Fixed a bug to correctly trigger updates on jobspec changes [[GH-9029](https://github.com/hashicorp/nomad/pull/9029)]
* csi: Fixed a bug where multi-writer volumes were allowed only 1 write claim. [[GH-9040](https://github.com/hashicorp/nomad/issues/9040)]
* csi: Fixed a bug where `nomad volume detach` would not accept prefixes for the node ID parameter. [[GH-9041](https://github.com/hashicorp/nomad/issues/9041)]
Expand Down
8 changes: 8 additions & 0 deletions client/taskenv/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ func InterpolateServices(taskEnv *TaskEnv, services []*structs.Service) []*struc
service.Meta = meta
}

if len(service.CanaryMeta) > 0 {
canaryMeta := make(map[string]string, len(service.CanaryMeta))
for k, v := range service.CanaryMeta {
canaryMeta[k] = taskEnv.ReplaceEnv(v)
}
service.CanaryMeta = canaryMeta
}

interpolated[i] = service
}

Expand Down
14 changes: 14 additions & 0 deletions client/taskenv/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ func TestInterpolateServices(t *testing.T) {
Name: "${name}",
PortLabel: "${portlabel}",
Tags: []string{"${tags}"},
Meta: map[string]string{
"meta-key": "${meta}",
},
CanaryMeta: map[string]string{
"canarymeta-key": "${canarymeta}",
},
Checks: []*structs.ServiceCheck{
{
Name: "${checkname}",
Expand All @@ -40,6 +46,8 @@ func TestInterpolateServices(t *testing.T) {
"name": "name",
"portlabel": "portlabel",
"tags": "tags",
"meta": "meta-value",
"canarymeta": "canarymeta-value",
"checkname": "checkname",
"checktype": "checktype",
"checkcmd": "checkcmd",
Expand All @@ -62,6 +70,12 @@ func TestInterpolateServices(t *testing.T) {
Name: "name",
PortLabel: "portlabel",
Tags: []string{"tags"},
Meta: map[string]string{
"meta-key": "meta-value",
},
CanaryMeta: map[string]string{
"canarymeta-key": "canarymeta-value",
},
Checks: []*structs.ServiceCheck{
{
Name: "checkname",
Expand Down