Skip to content

Commit

Permalink
Switch resource definitions to multi-line strings
Browse files Browse the repository at this point in the history
These values now default to null and are optional in the template files.
Adds tests for the new values.

Also changes the file extension on several of the test files from .yaml
to .bats.
  • Loading branch information
adilyse committed Nov 20, 2018
1 parent ad36ca0 commit 2bfcb1c
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 27 deletions.
4 changes: 3 additions & 1 deletion templates/client-daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
4 changes: 3 additions & 1 deletion templates/server-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
File renamed without changes.
61 changes: 42 additions & 19 deletions test/unit/server-statefulset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ load _helpers
[ "${actual}" = "false" ]
}

#--------------------------------------------------------------------
# image

@test "server/StatefulSet: image defaults to global.image" {
cd `chart_dir`
local actual=$(helm template \
Expand All @@ -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`
Expand Down Expand Up @@ -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" ]
}

#--------------------------------------------------------------------
Expand Down Expand Up @@ -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" ]
}

14 changes: 8 additions & 6 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 2bfcb1c

Please sign in to comment.