Skip to content

Commit

Permalink
enhancement(helm): Add support for defining topology spread constrain…
Browse files Browse the repository at this point in the history
…ts (#1821)

* Add topologySpreadConstraints to the helm chart

Signed-off-by: Piotr Solarczyk <psolarcz@cisco.com>

* Use a template function

Signed-off-by: Charith Ellawala <charith@cerbos.dev>

---------

Signed-off-by: Piotr Solarczyk <psolarcz@cisco.com>
Signed-off-by: Charith Ellawala <charith@cerbos.dev>
Co-authored-by: Piotr Solarczyk <psolarcz@cisco.com>
  • Loading branch information
charithe and psolarcz committed Oct 5, 2023
1 parent 85e4eac commit 56f7683
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
20 changes: 20 additions & 0 deletions deploy/charts/cerbos/templates/_helpers.tpl
Expand Up @@ -167,3 +167,23 @@ The image reference to use in pods
{{- end -}}
"
{{- end }}

{{/*
Topology spread constraints with label selector injected
*/}}
{{- define "cerbos.topologySpreadConstraints" -}}
{{- if .Values.topologySpreadConstraints }}
{{- $defaultLabels := (fromYaml (include "cerbos.selectorLabels" $)) }}
{{- $defaultLabelSelector := (dict "labelSelector" (dict "matchLabels" $defaultLabels)) }}
{{- $constraints := list }}
{{- range $c := .Values.topologySpreadConstraints }}
{{- if (hasKey $c "labelSelector") }}
{{- $constraints = (append $constraints $c) }}
{{- else }}
{{- $constraints = (append $constraints (mergeOverwrite $c $defaultLabelSelector)) }}
{{- end }}
{{- end }}
topologySpreadConstraints:
{{ toYaml $constraints | indent 2 }}
{{- end }}
{{- end }}
1 change: 1 addition & 0 deletions deploy/charts/cerbos/templates/deployment.yaml
Expand Up @@ -132,3 +132,4 @@ spec:
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- include "cerbos.topologySpreadConstraints" . | nindent 6}}
6 changes: 6 additions & 0 deletions deploy/charts/cerbos/values.yaml
Expand Up @@ -79,6 +79,12 @@ tolerations: []
# Pod affinity rules.
affinity: {}

# Topology Spread Constraints rules.
topologySpreadConstraints: []
# - topologyKey: topology.kubernetes.io/zone
# maxSkew: 1
# whenUnsatisfiable: ScheduleAnyway

# Volumes to add to the pod.
volumes: []

Expand Down

0 comments on commit 56f7683

Please sign in to comment.