From f4dcfde29fdb6154d7e6c8c7ac49aa37b4a95c80 Mon Sep 17 00:00:00 2001 From: hc-github-team-consul-core Date: Tue, 24 Sep 2024 13:37:39 -0400 Subject: [PATCH] Backport of Fixes tolerations not working into release/1.6.x (#4361) Fixes tolerations not working for API Gateways (#4315) --- .changelog/4315.txt | 3 ++ .../templates/gateway-resources-job.yaml | 3 +- .../test/unit/gateway-resources-job.bats | 44 ++++++++++++------- .../gateway-resources/command_test.go | 11 +++-- 4 files changed, 40 insertions(+), 21 deletions(-) create mode 100644 .changelog/4315.txt diff --git a/.changelog/4315.txt b/.changelog/4315.txt new file mode 100644 index 0000000000..05b7fb01da --- /dev/null +++ b/.changelog/4315.txt @@ -0,0 +1,3 @@ +```release-note:bug +helm: fix issue where the API Gateway GatewayClassConfig tolerations can not be parsed by the Helm chart. +``` diff --git a/charts/consul/templates/gateway-resources-job.yaml b/charts/consul/templates/gateway-resources-job.yaml index 5f3110479c..ff53129eb3 100644 --- a/charts/consul/templates/gateway-resources-job.yaml +++ b/charts/consul/templates/gateway-resources-job.yaml @@ -69,7 +69,8 @@ spec: - {{- toYaml .Values.connectInject.apiGateway.managedGatewayClass.nodeSelector | nindent 14 -}} {{- end }} {{- if .Values.connectInject.apiGateway.managedGatewayClass.tolerations }} - - -tolerations={{ .Values.connectInject.apiGateway.managedGatewayClass.tolerations }} + - -tolerations + - {{- toYaml .Values.connectInject.apiGateway.managedGatewayClass.tolerations | nindent 14 -}} {{- end }} {{- if .Values.connectInject.apiGateway.managedGatewayClass.copyAnnotations.service }} - -service-annotations diff --git a/charts/consul/test/unit/gateway-resources-job.bats b/charts/consul/test/unit/gateway-resources-job.bats index 32173838fe..fd64acac02 100644 --- a/charts/consul/test/unit/gateway-resources-job.bats +++ b/charts/consul/test/unit/gateway-resources-job.bats @@ -71,7 +71,6 @@ target=templates/gateway-resources-job.yaml --set 'connectInject.apiGateway.managedGatewayClass.deployment.minInstances=1' \ --set 'connectInject.apiGateway.managedGatewayClass.deployment.maxInstances=3' \ --set 'connectInject.apiGateway.managedGatewayClass.nodeSelector=foo: bar' \ - --set 'connectInject.apiGateway.managedGatewayClass.tolerations=- key: bar' \ --set 'connectInject.apiGateway.managedGatewayClass.copyAnnotations.service.annotations=- bingo' \ --set 'connectInject.apiGateway.managedGatewayClass.serviceType=Foo' \ --set 'connectInject.apiGateway.managedGatewayClass.openshiftSCCName=hello' \ @@ -90,23 +89,11 @@ target=templates/gateway-resources-job.yaml local actual=$(echo "$spec" | jq 'any(index("-service-type=Foo"))') [ "${actual}" = "true" ] - local actual=$(echo "$spec" | jq '.[12]') - [ "${actual}" = "\"-node-selector\"" ] - - local actual=$(echo "$spec" | jq '.[13]') - [ "${actual}" = "\"foo: bar\"" ] - - local actual=$(echo "$spec" | jq '.[14] | ."-tolerations=- key"') - [ "${actual}" = "\"bar\"" ] - - local actual=$(echo "$spec" | jq '.[15]') - [ "${actual}" = "\"-service-annotations\"" ] - - local actual=$(echo "$spec" | jq '.[16]') - [ "${actual}" = "\"- bingo\"" ] + local actual=$(echo $spec | yq 'contains(["-node-selector", "foo: bar"])') + [ "${actual}" = "true" ] - local actual=$(echo "$spec" | jq '.[17]') - [ "${actual}" = "\"-service-type=Foo\"" ] + local actual=$(echo $spec | yq 'contains(["-service-annotations", "- bingo"])') + [ "${actual}" = "true" ] } @test "apiGateway/GatewayClassConfig: custom configuration openshift enabled" { @@ -138,3 +125,26 @@ target=templates/gateway-resources-job.yaml tee /dev/stderr) [ "${actual}" = "{}" ] } + + +#-------------------------------------------------------------------- +# tolerations + +@test "apiGateway/GatewayClassConfig: tolerations" { + cd `chart_dir` + local tolerations=$(helm template \ + -s $target \ + --set 'connectInject.apiGateway.managedGatewayClass.tolerations=- "operator": "Equal" \ +"effect": "NoSchedule" \ +"key": "node" \ +"value": "clients" \ +- "operator": "Equal" \ +"effect": "NoSchedule" \ +"key": "node2" \ +"value": "clients2"' \ + . | tee /dev/stderr | + yq '.spec.template.spec.containers[0].args' | tee /dev/stderr) + + local actual=$(echo $tolerations | yq 'contains(["tolerations","- \"operator\": \"Equal\" \n\"effect\": \"NoSchedule\" \n\"key\": \"node\" \n\"value\": \"clients\" \n- \"operator\": \"Equal\" \n\"effect\": \"NoSchedule\" \n\"key\": \"node2\" \n\"value\": \"clients2\"" ])') + [ "${actual}" = "true" ] +} \ No newline at end of file diff --git a/control-plane/subcommand/gateway-resources/command_test.go b/control-plane/subcommand/gateway-resources/command_test.go index 6e8230102c..ef88886004 100644 --- a/control-plane/subcommand/gateway-resources/command_test.go +++ b/control-plane/subcommand/gateway-resources/command_test.go @@ -161,9 +161,14 @@ func TestRun_flagValidation(t *testing.T) { flagNodeSelector: ` foo: 1 bar: 2`, - flagTolerations: ` -- value: foo -- value: bar`, + flagTolerations: `- "operator": "Equal" + "effect": "NoSchedule" + "key": "node" + "value": "clients" +- "operator": "Equal" + "effect": "NoSchedule" + "key": "node2" + "value": "clients2"`, flagServiceAnnotations: ` - foo - bar`,