Skip to content

Commit

Permalink
Create default affinity rule, to keep pods with same PVCs on same nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
PrivatePuffin committed Feb 7, 2025
1 parent e9633e4 commit 6c33096
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
11 changes: 5 additions & 6 deletions charts/library/common/templates/lib/pod/_affinity.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,21 @@ objectData: The object data to be used to render the Pod.
{{- end -}}

{{- $validTypes := (list "Deployment" "StatefulSet") -}}
{{/* TODO: We need to merge default with user input */}}
{{- if and (mustHas $objectData.type $validTypes) $rootCtx.Values.podOptions.defaultAffinity }}
{{/*
TODO: We need to label pods with the PVCs that are attached, then use those labels here
EXAMPLE FORMAT:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- PERSITENCE NAME LABEL
- {{include "tc.v1.common.lib.metadata.volumeLabels" (dict "rootCtx" $rootCtx "objectData" $objectData)}}
topologyKey: "kubernetes.io/hostname"
*/}}
{{- end -}}
{{- else -}}
{{- with $affinity -}} {{/* TODO: Template this, so we can add some validation around easy to make mistakes. Low Prio */}}
{{- . | toYaml | nindent 0 }}
{{- end -}}
{{- end -}}

{{- end -}}
4 changes: 4 additions & 0 deletions charts/library/common/templates/lib/workload/_pod.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ priorityClassName: {{ . }}
nodeSelector:
{{- . | nindent 2 }}
{{- end -}}
{{- with (include "tc.v1.common.lib.pod.affinity" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }}
affinity:
{{- . | nindent 2 }}
{{- end -}}
{{- with (include "tc.v1.common.lib.pod.topologySpreadConstraints" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }}
topologySpreadConstraints:
{{- . | nindent 2 }}
Expand Down
1 change: 1 addition & 0 deletions charts/library/common/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ podOptions:
kubernetes.io/arch: "amd64"
# -- Used to enforce a good spread for Deployments and StatefulSets by default
defaultSpread: true
defaultAffinity: true
topologySpreadConstraints: []
tolerations: []
schedulerName: ""
Expand Down

0 comments on commit 6c33096

Please sign in to comment.