diff --git a/templates/client-daemonset.yaml b/templates/client-daemonset.yaml index 754183278d96..9d0dddb1bdbb 100644 --- a/templates/client-daemonset.yaml +++ b/templates/client-daemonset.yaml @@ -145,6 +145,8 @@ spec: - | curl http://127.0.0.1:8500/v1/status/leader 2>/dev/null | \ grep -E '".+"' + {{- if .Values.client.resources }} resources: -{{ toYaml .Values.client.resources | indent 12 }} + {{ tpl .Values.client.resources . | nindent 12 | trim }} + {{- end }} {{- end }} diff --git a/templates/server-statefulset.yaml b/templates/server-statefulset.yaml index 6e6aea8a8336..5427cbd52478 100644 --- a/templates/server-statefulset.yaml +++ b/templates/server-statefulset.yaml @@ -146,8 +146,10 @@ spec: periodSeconds: 3 successThreshold: 1 timeoutSeconds: 5 + {{- if .Values.server.resources }} resources: -{{ toYaml .Values.server.resources | indent 12 }} + {{ tpl .Values.server.resources . | nindent 12 | trim }} + {{- end }} volumeClaimTemplates: - metadata: name: data diff --git a/test/unit/client-daemonset.yaml b/test/unit/client-daemonset.bats similarity index 90% rename from test/unit/client-daemonset.yaml rename to test/unit/client-daemonset.bats index 2b9dbdc53e93..9544d55ff348 100755 --- a/test/unit/client-daemonset.yaml +++ b/test/unit/client-daemonset.bats @@ -94,6 +94,28 @@ load _helpers [ "${actual}" = "true" ] } +#-------------------------------------------------------------------- +# resources + +@test "client/DaemonSet: no resources defined by default" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/client-daemonset.yaml \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.containers[0].resources' | tee /dev/stderr) + [ "${actual}" = "null" ] +} + +@test "client/DaemonSet: resources can be set" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/client-daemonset.yaml \ + --set 'client.resources=foo' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.containers[0].resources' | tee /dev/stderr) + [ "${actual}" = "foo" ] +} + #-------------------------------------------------------------------- # extraVolumes diff --git a/test/unit/connect-inject-mutatingwebhook.yaml b/test/unit/connect-inject-mutatingwebhook.bats similarity index 100% rename from test/unit/connect-inject-mutatingwebhook.yaml rename to test/unit/connect-inject-mutatingwebhook.bats diff --git a/test/unit/connect-inject-service.yaml b/test/unit/connect-inject-service.bats similarity index 100% rename from test/unit/connect-inject-service.yaml rename to test/unit/connect-inject-service.bats diff --git a/test/unit/server-statefulset.bats b/test/unit/server-statefulset.bats index f1bc2c9d1d71..db1a31cbcdc2 100755 --- a/test/unit/server-statefulset.bats +++ b/test/unit/server-statefulset.bats @@ -42,6 +42,9 @@ load _helpers [ "${actual}" = "false" ] } +#-------------------------------------------------------------------- +# image + @test "server/StatefulSet: image defaults to global.image" { cd `chart_dir` local actual=$(helm template \ @@ -64,7 +67,29 @@ load _helpers } #-------------------------------------------------------------------- -# updateStrategy +# resources + +@test "server/StatefulSet: no resources defined by default" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/server-statefulset.yaml \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.containers[0].resources' | tee /dev/stderr) + [ "${actual}" = "null" ] +} + +@test "server/StatefulSet: resources can be set" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/server-statefulset.yaml \ + --set 'server.resources=foo' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.containers[0].resources' | tee /dev/stderr) + [ "${actual}" = "foo" ] +} + +#-------------------------------------------------------------------- +# updateStrategy (derived from updatePartition) @test "server/StatefulSet: no updateStrategy when not updating" { cd `chart_dir` @@ -93,25 +118,25 @@ load _helpers } #-------------------------------------------------------------------- -# affinity +# storageClass -@test "server/StatefulSet: affinity not set with server.affinity" { +@test "server/StatefulSet: no storageClass on claim by default" { cd `chart_dir` local actual=$(helm template \ -x templates/server-statefulset.yaml \ - --set 'server.affinity=null' \ . | tee /dev/stderr | - yq '.spec.template.spec | .affinity? == null' | tee /dev/stderr) - [ "${actual}" = "true" ] + yq -r '.spec.volumeClaimTemplates[0].spec.storageClassName' | tee /dev/stderr) + [ "${actual}" = "null" ] } -@test "server/StatefulSet: affinity set by default" { +@test "server/StatefulSet: can set storageClass" { cd `chart_dir` local actual=$(helm template \ -x templates/server-statefulset.yaml \ + --set 'server.storageClass=foo' \ . | tee /dev/stderr | - yq '.spec.template.spec.affinity | .podAntiAffinity? != null' | tee /dev/stderr) - [ "${actual}" = "true" ] + yq -r '.spec.volumeClaimTemplates[0].spec.storageClassName' | tee /dev/stderr) + [ "${actual}" = "foo" ] } #-------------------------------------------------------------------- @@ -220,25 +245,23 @@ load _helpers } #-------------------------------------------------------------------- -# updateStrategy +# affinity -@test "server/StatefulSet: no storageClass on claim by default" { +@test "server/StatefulSet: affinity not set with server.affinity=null" { cd `chart_dir` local actual=$(helm template \ -x templates/server-statefulset.yaml \ + --set 'server.affinity=null' \ . | tee /dev/stderr | - yq -r '.spec.volumeClaimTemplates[0].spec.storageClassName' | tee /dev/stderr) - [ "${actual}" = "null" ] + yq '.spec.template.spec | .affinity? == null' | tee /dev/stderr) + [ "${actual}" = "true" ] } - -@test "server/StatefulSet: can set storageClass" { +@test "server/StatefulSet: affinity set by default" { cd `chart_dir` local actual=$(helm template \ -x templates/server-statefulset.yaml \ - --set 'server.storageClass=foo' \ . | tee /dev/stderr | - yq -r '.spec.volumeClaimTemplates[0].spec.storageClassName' | tee /dev/stderr) - [ "${actual}" = "foo" ] + yq '.spec.template.spec.affinity | .podAntiAffinity? != null' | tee /dev/stderr) + [ "${actual}" = "true" ] } - diff --git a/values.yaml b/values.yaml index f18f4d164006..29cb44fe8fe5 100644 --- a/values.yaml +++ b/values.yaml @@ -48,9 +48,10 @@ server: connect: true # Resource requests, limits, etc. for the server cluster placement. This - # should map directly to the value of the resources field for a PodSpec. - # By default no direct resource request is made. - resources: {} + # should map directly to the value of the resources field for a PodSpec, + # formatted as a multi-line string. By default no direct resource request + # is made. + resources: null # updatePartition is used to control a careful rolling update of Consul # servers. This should be done particularly when changing the version @@ -105,9 +106,10 @@ client: grpc: false # Resource requests, limits, etc. for the client cluster placement. This - # should map directly to the value of the resources field for a PodSpec. - # By default no direct resource request is made. - resources: {} + # should map directly to the value of the resources field for a PodSpec, + # formatted as a multi-line string. By default no direct resource request + # is made. + resources: null # extraConfig is a raw string of extra configuration to set with the # server. This should be JSON.