Skip to content
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.

Add topologySpreadConstraints support for server pods #863

Merged
merged 4 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions templates/server-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ spec:
{{- if .Values.server.tolerations }}
tolerations:
{{ tpl .Values.server.tolerations . | nindent 8 | trim }}
{{- end }}
{{- if .Values.server.topologySpreadConstraints }}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a check here similar to:
{{- if or ( gt .Capabilities.KubeVersion.Major "1" ) ( ge .Capabilities.KubeVersion.Minor "18" ) }} ?

There is a warning in the values file, but this might be helpful in ensuring it doesn't accidentally get templated when say re-using a values file. We have tests that do something similar in ui-ingress.bats for reference!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added the checks.

A side note: do you think it's better to just have this fail instead of being silently ignored when a user tries to use this on a cluster < 1.18 though?

Copy link

@thisisnotashwin thisisnotashwin Mar 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YES! I like this idea a lot. Would you mind updating the PR to fail if the user attempts to set this value on a cluster < 1.18?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added that in.

topologySpreadConstraints:
{{ tpl .Values.server.topologySpreadConstraints . | nindent 8 | trim }}
{{- end }}
terminationGracePeriodSeconds: 30
serviceAccountName: {{ template "consul.fullname" . }}-server
Expand Down
22 changes: 22 additions & 0 deletions test/unit/server-statefulset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,28 @@ load _helpers
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# tolerations

@test "server/StatefulSet: topologySpreadConstraints not set by default" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-statefulset.yaml \
. | tee /dev/stderr |
yq '.spec.template.spec | .topologySpreadConstraints? == null' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "server/StatefulSet: topologySpreadConstraints can be set" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-statefulset.yaml \
--set 'server.topologySpreadConstraints=foobar' \
. | tee /dev/stderr |
yq '.spec.template.spec.topologySpreadConstraints == "foobar"' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# global.openshift.enabled & server.securityContext

Expand Down
21 changes: 21 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,27 @@ server:
# (https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/) array in a Pod spec.
tolerations: ""

# Pod topology spread constraints for server pods.
# This should be a multi-line YAML string matching the `topologySpreadConstraints` array
# (https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/) in a Pod Spec.
#
# This requires K8S >= 1.18 (beta) or 1.19 (stable).
#
# Example:
#
# ```yaml
# topologySpreadConstraints: |
# - maxSkew: 1
# topologyKey: topology.kubernetes.io/zone
# whenUnsatisfiable: DoNotSchedule
# labelSelector:
# matchLabels:
# app: {{ template "consul.name" . }}
# release: "{{ .Release.Name }}"
# component: server
# ```
topologySpreadConstraints: ""

# This value defines `nodeSelector` (https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector)
# labels for server pod assignment, formatted as a multi-line string.
#
Expand Down