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 f61204f2a3..7f0d3719fb 100644 --- a/charts/consul/templates/gateway-resources-job.yaml +++ b/charts/consul/templates/gateway-resources-job.yaml @@ -90,7 +90,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 e38397231b..063b6e0052 100644 --- a/charts/consul/test/unit/gateway-resources-job.bats +++ b/charts/consul/test/unit/gateway-resources-job.bats @@ -89,7 +89,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' \ @@ -108,23 +107,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" { @@ -156,3 +143,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 8455c1a315..c887cde41a 100644 --- a/control-plane/subcommand/gateway-resources/command_test.go +++ b/control-plane/subcommand/gateway-resources/command_test.go @@ -158,9 +158,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`,