From eb10dcdc3245247f2736a68445f71732432a8319 Mon Sep 17 00:00:00 2001 From: Mark <47016163+mark-vw@users.noreply.github.com> Date: Wed, 29 Sep 2021 14:06:02 -0700 Subject: [PATCH 1/7] Add resource settings for service-init --- charts/consul/values.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/charts/consul/values.yaml b/charts/consul/values.yaml index 9105565572..a8eaff4cd5 100644 --- a/charts/consul/values.yaml +++ b/charts/consul/values.yaml @@ -2009,6 +2009,18 @@ meshGateway: memory: "150Mi" cpu: "50m" + # Resource settings for the `service-init` init container. + # @recurse: false + # @type: map + initServiceInitContainer: + resources: + requests: + memory: "25Mi" + cpu: "50m" + limits: + memory: "150Mi" + cpu: "50m" + # By default, we set an anti-affinity so that two gateway pods won't be # on the same node. NOTE: Gateways require that Consul client agents are # also running on the nodes alongside each gateway pod. From 1874ad917c5dc09be06ac33a3cc34f83857393f5 Mon Sep 17 00:00:00 2001 From: Mark <47016163+mark-vw@users.noreply.github.com> Date: Wed, 29 Sep 2021 14:11:20 -0700 Subject: [PATCH 2/7] Configure resources on service-init container --- .../consul/templates/mesh-gateway-deployment.yaml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/charts/consul/templates/mesh-gateway-deployment.yaml b/charts/consul/templates/mesh-gateway-deployment.yaml index de3f0ff689..72bbcb96ea 100644 --- a/charts/consul/templates/mesh-gateway-deployment.yaml +++ b/charts/consul/templates/mesh-gateway-deployment.yaml @@ -225,13 +225,14 @@ spec: mountPath: /consul/tls/ca readOnly: true {{- end }} + {{- if .Values.meshGateway.initServiceInitContainer.resources }} resources: - requests: - memory: "50Mi" - cpu: "50m" - limits: - memory: "50Mi" - cpu: "50m" + {{- if eq (typeOf .Values.meshGateway.initServiceInitContainer.resources) "string" }} + {{ tpl .Values.meshGateway.initServiceInitContainer.resources . | nindent 12 | trim }} + {{- else }} + {{- toYaml .Values.meshGateway.initServiceInitContainer.resources | nindent 12 }} + {{- end }} + {{- end }} containers: - name: mesh-gateway image: {{ .Values.global.imageEnvoy | quote }} From c1da8e7cf8539844b6193a0f02c7d76c69a6ad54 Mon Sep 17 00:00:00 2001 From: Mark <47016163+mark-vw@users.noreply.github.com> Date: Wed, 29 Sep 2021 14:26:44 -0700 Subject: [PATCH 3/7] unit tests for service-init resources --- .../test/unit/mesh-gateway-deployment.bats | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/charts/consul/test/unit/mesh-gateway-deployment.bats b/charts/consul/test/unit/mesh-gateway-deployment.bats index 4e12efa89d..abee6df3cb 100755 --- a/charts/consul/test/unit/mesh-gateway-deployment.bats +++ b/charts/consul/test/unit/mesh-gateway-deployment.bats @@ -437,6 +437,50 @@ key2: value2' \ [ "${actual}" = "cpu2" ] } +#-------------------------------------------------------------------- +# service-init container resources + +@test "meshGateway/Deployment: init service-init container has default resources" { + cd `chart_dir` + local actual=$(helm template \ + -s templates/mesh-gateway-deployment.yaml \ + --set 'meshGateway.enabled=true' \ + --set 'connectInject.enabled=true' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.initServiceInitContainer[0].resources' | tee /dev/stderr) + + [ $(echo "${actual}" | yq -r '.requests.memory') = "25Mi" ] + [ $(echo "${actual}" | yq -r '.requests.cpu') = "50m" ] + [ $(echo "${actual}" | yq -r '.limits.memory') = "150Mi" ] + [ $(echo "${actual}" | yq -r '.limits.cpu') = "50m" ] +} + +@test "meshGateway/Deployment: init service-init container resources can be set" { + cd `chart_dir` + local object=$(helm template \ + -s templates/mesh-gateway-deployment.yaml \ + --set 'meshGateway.enabled=true' \ + --set 'connectInject.enabled=true' \ + --set 'meshGateway.initServiceInitContainer.resources.requests.memory=memory' \ + --set 'meshGateway.initServiceInitContainer.resources.requests.cpu=cpu' \ + --set 'meshGateway.initServiceInitContainer.resources.limits.memory=memory2' \ + --set 'meshGateway.initServiceInitContainer.resources.limits.cpu=cpu2' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.initServiceInitContainer[0].resources' | tee /dev/stderr) + + local actual=$(echo $object | yq -r '.requests.memory' | tee /dev/stderr) + [ "${actual}" = "memory" ] + + local actual=$(echo $object | yq -r '.requests.cpu' | tee /dev/stderr) + [ "${actual}" = "cpu" ] + + local actual=$(echo $object | yq -r '.limits.memory' | tee /dev/stderr) + [ "${actual}" = "memory2" ] + + local actual=$(echo $object | yq -r '.limits.cpu' | tee /dev/stderr) + [ "${actual}" = "cpu2" ] +} + #-------------------------------------------------------------------- # consul sidecar resources From 5c7f111574e3c1a307450e540f9fbe229bf482cf Mon Sep 17 00:00:00 2001 From: Mark <47016163+mark-vw@users.noreply.github.com> Date: Mon, 4 Oct 2021 16:38:15 -0700 Subject: [PATCH 4/7] fix unit tests yq selector was incorrect --- charts/consul/test/unit/mesh-gateway-deployment.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/consul/test/unit/mesh-gateway-deployment.bats b/charts/consul/test/unit/mesh-gateway-deployment.bats index abee6df3cb..40a61ecd2a 100755 --- a/charts/consul/test/unit/mesh-gateway-deployment.bats +++ b/charts/consul/test/unit/mesh-gateway-deployment.bats @@ -447,7 +447,7 @@ key2: value2' \ --set 'meshGateway.enabled=true' \ --set 'connectInject.enabled=true' \ . | tee /dev/stderr | - yq -r '.spec.template.spec.initServiceInitContainer[0].resources' | tee /dev/stderr) + yq -r '.spec.template.spec.initContainers[1].resources' | tee /dev/stderr) [ $(echo "${actual}" | yq -r '.requests.memory') = "25Mi" ] [ $(echo "${actual}" | yq -r '.requests.cpu') = "50m" ] @@ -466,7 +466,7 @@ key2: value2' \ --set 'meshGateway.initServiceInitContainer.resources.limits.memory=memory2' \ --set 'meshGateway.initServiceInitContainer.resources.limits.cpu=cpu2' \ . | tee /dev/stderr | - yq -r '.spec.template.spec.initServiceInitContainer[0].resources' | tee /dev/stderr) + yq -r '.spec.template.spec.initContainers[1].resources' | tee /dev/stderr) local actual=$(echo $object | yq -r '.requests.memory' | tee /dev/stderr) [ "${actual}" = "memory" ] From ad8a11e2508065e24ff3f356e75415b706ffb949 Mon Sep 17 00:00:00 2001 From: Mark <47016163+mark-vw@users.noreply.github.com> Date: Tue, 5 Oct 2021 09:53:12 -0700 Subject: [PATCH 5/7] Update default resource values on service-init Update default values to the original values defined in mesh-gateway-deployment.yaml --- charts/consul/values.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/consul/values.yaml b/charts/consul/values.yaml index a8eaff4cd5..12bf638629 100644 --- a/charts/consul/values.yaml +++ b/charts/consul/values.yaml @@ -2015,10 +2015,10 @@ meshGateway: initServiceInitContainer: resources: requests: - memory: "25Mi" + memory: "50Mi" cpu: "50m" limits: - memory: "150Mi" + memory: "50Mi" cpu: "50m" # By default, we set an anti-affinity so that two gateway pods won't be From a02313ec58913fdceaee26e5b5b2a4f41c853ff2 Mon Sep 17 00:00:00 2001 From: Mark <47016163+mark-vw@users.noreply.github.com> Date: Tue, 5 Oct 2021 09:58:13 -0700 Subject: [PATCH 6/7] Update test values with new defaults --- charts/consul/test/unit/mesh-gateway-deployment.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/consul/test/unit/mesh-gateway-deployment.bats b/charts/consul/test/unit/mesh-gateway-deployment.bats index 40a61ecd2a..aab58a8413 100755 --- a/charts/consul/test/unit/mesh-gateway-deployment.bats +++ b/charts/consul/test/unit/mesh-gateway-deployment.bats @@ -449,9 +449,9 @@ key2: value2' \ . | tee /dev/stderr | yq -r '.spec.template.spec.initContainers[1].resources' | tee /dev/stderr) - [ $(echo "${actual}" | yq -r '.requests.memory') = "25Mi" ] + [ $(echo "${actual}" | yq -r '.requests.memory') = "50Mi" ] [ $(echo "${actual}" | yq -r '.requests.cpu') = "50m" ] - [ $(echo "${actual}" | yq -r '.limits.memory') = "150Mi" ] + [ $(echo "${actual}" | yq -r '.limits.memory') = "50Mi" ] [ $(echo "${actual}" | yq -r '.limits.cpu') = "50m" ] } From a0c7052e6d7440a39ca793a00d40eb28756547a7 Mon Sep 17 00:00:00 2001 From: Mark <47016163+mark-vw@users.noreply.github.com> Date: Tue, 5 Oct 2021 14:03:20 -0700 Subject: [PATCH 7/7] Remove support for unnecessary string-based config No need for string-based config support as this is a new setting --- charts/consul/templates/mesh-gateway-deployment.yaml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/charts/consul/templates/mesh-gateway-deployment.yaml b/charts/consul/templates/mesh-gateway-deployment.yaml index 72bbcb96ea..4d87baf678 100644 --- a/charts/consul/templates/mesh-gateway-deployment.yaml +++ b/charts/consul/templates/mesh-gateway-deployment.yaml @@ -226,12 +226,7 @@ spec: readOnly: true {{- end }} {{- if .Values.meshGateway.initServiceInitContainer.resources }} - resources: - {{- if eq (typeOf .Values.meshGateway.initServiceInitContainer.resources) "string" }} - {{ tpl .Values.meshGateway.initServiceInitContainer.resources . | nindent 12 | trim }} - {{- else }} - {{- toYaml .Values.meshGateway.initServiceInitContainer.resources | nindent 12 }} - {{- end }} + resources: {{ toYaml .Values.meshGateway.initServiceInitContainer.resources | nindent 12 }} {{- end }} containers: - name: mesh-gateway