From 50ec7b7d02170f1e978a87e81fec662bce4e1928 Mon Sep 17 00:00:00 2001 From: Andrew Stucki Date: Wed, 16 Nov 2022 20:14:12 -0500 Subject: [PATCH 1/3] Add opt-in server discovery --- .../api-gateway-controller-deployment.yaml | 4 ++++ .../api-gateway-controller-deployment.bats | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/charts/consul/templates/api-gateway-controller-deployment.yaml b/charts/consul/templates/api-gateway-controller-deployment.yaml index 84ba22dd5c..56d9d14d94 100644 --- a/charts/consul/templates/api-gateway-controller-deployment.yaml +++ b/charts/consul/templates/api-gateway-controller-deployment.yaml @@ -119,6 +119,10 @@ spec: value: {{ .Values.global.adminPartitions.name }} {{- end }} {{- end }} + {{- if not .Values.client.enabled }} + - name: CONSUL_DYNAMIC_SERVER_DISCOVERY + value: "true" + {{- end }} command: - "/bin/sh" - "-ec" diff --git a/charts/consul/test/unit/api-gateway-controller-deployment.bats b/charts/consul/test/unit/api-gateway-controller-deployment.bats index c97a671c5f..8fe34d2bce 100755 --- a/charts/consul/test/unit/api-gateway-controller-deployment.bats +++ b/charts/consul/test/unit/api-gateway-controller-deployment.bats @@ -1346,3 +1346,27 @@ load _helpers yq '.spec.template.spec.containers[0].env[6].value == "hashi"' | tee /dev/stderr) [ "${actual}" = "true" ] } + +@test "apiGateway/Deployment: CONSUL_DYNAMIC_SERVER_DISCOVERY is set when not using clients" { + cd `chart_dir` + local actual=$(helm template \ + -s templates/api-gateway-controller-deployment.yaml \ + --set 'apiGateway.enabled=true' \ + --set 'apiGateway.image=bar' \ + --set 'client.enabled=false' \ + . | tee /dev/stderr | + yq '.spec.template.spec.containers[0].env[3].value == "true"' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "apiGateway/Deployment: CONSUL_DYNAMIC_SERVER_DISCOVERY is not set when not using clients" { + cd `chart_dir` + local actual=$(helm template \ + -s templates/api-gateway-controller-deployment.yaml \ + --set 'apiGateway.enabled=true' \ + --set 'apiGateway.image=bar' \ + --set 'client.enabled=true' \ + . | tee /dev/stderr | + yq '.spec.template.spec.containers[0].env[3]' | tee /dev/stderr) + [ "${actual}" = "null" ] +} From df15d279844e3b2619b1eae10bd7372eea8950ed Mon Sep 17 00:00:00 2001 From: Andrew Stucki Date: Wed, 16 Nov 2022 20:25:40 -0500 Subject: [PATCH 2/3] typo --- charts/consul/test/unit/api-gateway-controller-deployment.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/consul/test/unit/api-gateway-controller-deployment.bats b/charts/consul/test/unit/api-gateway-controller-deployment.bats index 8fe34d2bce..d376026ae0 100755 --- a/charts/consul/test/unit/api-gateway-controller-deployment.bats +++ b/charts/consul/test/unit/api-gateway-controller-deployment.bats @@ -1359,7 +1359,7 @@ load _helpers [ "${actual}" = "true" ] } -@test "apiGateway/Deployment: CONSUL_DYNAMIC_SERVER_DISCOVERY is not set when not using clients" { +@test "apiGateway/Deployment: CONSUL_DYNAMIC_SERVER_DISCOVERY is not set when using clients" { cd `chart_dir` local actual=$(helm template \ -s templates/api-gateway-controller-deployment.yaml \ From de70298d6fd721832dfdbfe0ee213f16d5870833 Mon Sep 17 00:00:00 2001 From: Andrew Stucki Date: Wed, 16 Nov 2022 20:39:04 -0500 Subject: [PATCH 3/3] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 404e5425c8..0c3b8e24fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ IMPROVEMENTS: * Allow addition of extra labels to Connect Inject pods. [[GH-1678](https://github.com/hashicorp/consul-k8s/pull/1678)] * Add fields `localConnectTimeoutMs` and `localRequestTimeoutMs` to the `ServiceDefaults` CRD. [[GH-1647](https://github.com/hashicorp/consul-k8s/pull/1647)] * API Gateway: Enable API Gateways to directly connect to Consul servers when running in the agentless configuration. [[GH-1694](https://github.com/hashicorp/consul-k8s/pull/1694)] + * API Gateway: Add support for using dynamic server discovery strings when running without agents. [[GH-1732](https://github.com/hashicorp/consul-k8s/pull/1732)] BUG FIXES: * Peering