From bb8f239fc775a429b3d5e0576330cef835c4ffad Mon Sep 17 00:00:00 2001 From: Jorge Marey Date: Thu, 15 Oct 2020 08:08:06 +0200 Subject: [PATCH 1/3] Add interpolation on service canarymeta --- client/taskenv/services.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/client/taskenv/services.go b/client/taskenv/services.go index 74bf673b18d..5c9029c4ada 100644 --- a/client/taskenv/services.go +++ b/client/taskenv/services.go @@ -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 } From 3b55c2fc0193b32ce944b6fc0f6c8f4553875a49 Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Tue, 20 Oct 2020 12:50:29 -0500 Subject: [PATCH 2/3] client: add tests around meta and canarymeta interpolation Expanding on #9096, add tests for making sure service.Meta and service.CanaryMeta are interpolated from environment variables. --- client/taskenv/services_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/client/taskenv/services_test.go b/client/taskenv/services_test.go index 88577d6de37..e50d612376a 100644 --- a/client/taskenv/services_test.go +++ b/client/taskenv/services_test.go @@ -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}", @@ -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", @@ -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", From 25dd3cccf15c14e747d41c6b531c5ba1283abbfc Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Tue, 20 Oct 2020 12:54:30 -0500 Subject: [PATCH 3/3] docs: update changelog for canary meta --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0eb0d19d10d..3553f35a9b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)]