Skip to content

Commit

Permalink
Backport of Fixes tolerations not working into release/1.6.x (#4361)
Browse files Browse the repository at this point in the history
Fixes tolerations not working for API Gateways (#4315)
  • Loading branch information
hc-github-team-consul-core authored Sep 24, 2024
1 parent d3add34 commit f4dcfde
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .changelog/4315.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
helm: fix issue where the API Gateway GatewayClassConfig tolerations can not be parsed by the Helm chart.
```
3 changes: 2 additions & 1 deletion charts/consul/templates/gateway-resources-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 27 additions & 17 deletions charts/consul/test/unit/gateway-resources-job.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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' \
Expand All @@ -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" {
Expand Down Expand Up @@ -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" ]
}
11 changes: 8 additions & 3 deletions control-plane/subcommand/gateway-resources/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down

0 comments on commit f4dcfde

Please sign in to comment.