diff --git a/charts/library/common-test/Chart.yaml b/charts/library/common-test/Chart.yaml index a5e228cc56a64..195b2cc4970d5 100644 --- a/charts/library/common-test/Chart.yaml +++ b/charts/library/common-test/Chart.yaml @@ -7,7 +7,7 @@ apiVersion: v2 appVersion: unknown dependencies: - name: common - version: ~26.0.0 + version: ~26.1.0 repository: file://../common/ condition: "" alias: "" diff --git a/charts/library/common/Chart.yaml b/charts/library/common/Chart.yaml index 01ff0df1ac486..42fe1986c256c 100644 --- a/charts/library/common/Chart.yaml +++ b/charts/library/common/Chart.yaml @@ -48,4 +48,4 @@ sources: - https://hub.docker.com/_/ - https://hub.docker.com/r/mikefarah/yq type: library -version: 26.0.1 +version: 26.1.0 diff --git a/charts/library/common/templates/class/_cronjob.tpl b/charts/library/common/templates/class/_cronjob.tpl index 0eeea41cad7b3..b7b92af00c838 100644 --- a/charts/library/common/templates/class/_cronjob.tpl +++ b/charts/library/common/templates/class/_cronjob.tpl @@ -34,6 +34,7 @@ spec: {{- $labels := (mustMerge ($objectData.podSpec.labels | default dict) (include "tc.v1.common.lib.metadata.allLabels" $rootCtx | fromYaml) (include "tc.v1.common.lib.metadata.podLabels" (dict "rootCtx" $rootCtx "objectData" $objectData) | fromYaml) + (include "tc.v1.common.lib.metadata.volumeLabels" (dict "rootCtx" $rootCtx "objectData" $objectData) | fromYaml) (include "tc.v1.common.lib.metadata.selectorLabels" (dict "rootCtx" $rootCtx "objectType" "pod" "objectName" $objectData.shortName) | fromYaml)) -}} {{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $labels) | trim) }} labels: diff --git a/charts/library/common/templates/class/_deployment.tpl b/charts/library/common/templates/class/_deployment.tpl index d4219186d05eb..2e6540936c06f 100644 --- a/charts/library/common/templates/class/_deployment.tpl +++ b/charts/library/common/templates/class/_deployment.tpl @@ -37,6 +37,7 @@ spec: {{- $labels := (mustMerge ($objectData.podSpec.labels | default dict) (include "tc.v1.common.lib.metadata.allLabels" $rootCtx | fromYaml) (include "tc.v1.common.lib.metadata.podLabels" (dict "rootCtx" $rootCtx "objectData" $objectData) | fromYaml) + (include "tc.v1.common.lib.metadata.volumeLabels" (dict "rootCtx" $rootCtx "objectData" $objectData) | fromYaml) (include "tc.v1.common.lib.metadata.selectorLabels" (dict "rootCtx" $rootCtx "objectType" "pod" "objectName" $objectData.shortName) | fromYaml)) -}} {{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $labels) | trim) }} labels: diff --git a/charts/library/common/templates/class/_job.tpl b/charts/library/common/templates/class/_job.tpl index 6813bdbfbd8f6..a3e4e9aa3da00 100644 --- a/charts/library/common/templates/class/_job.tpl +++ b/charts/library/common/templates/class/_job.tpl @@ -34,6 +34,7 @@ spec: {{- $labels := (mustMerge ($objectData.podSpec.labels | default dict) (include "tc.v1.common.lib.metadata.allLabels" $rootCtx | fromYaml) (include "tc.v1.common.lib.metadata.podLabels" (dict "rootCtx" $rootCtx "objectData" $objectData) | fromYaml) + (include "tc.v1.common.lib.metadata.volumeLabels" (dict "rootCtx" $rootCtx "objectData" $objectData) | fromYaml) (include "tc.v1.common.lib.metadata.selectorLabels" (dict "rootCtx" $rootCtx "objectType" "pod" "objectName" $objectData.shortName) | fromYaml)) -}} {{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $labels) | trim) }} labels: diff --git a/charts/library/common/templates/class/_statefulset.tpl b/charts/library/common/templates/class/_statefulset.tpl index 157bc84868c88..8de6c390bbcfc 100644 --- a/charts/library/common/templates/class/_statefulset.tpl +++ b/charts/library/common/templates/class/_statefulset.tpl @@ -37,6 +37,7 @@ spec: {{- $labels := (mustMerge ($objectData.podSpec.labels | default dict) (include "tc.v1.common.lib.metadata.allLabels" $rootCtx | fromYaml) (include "tc.v1.common.lib.metadata.podLabels" (dict "rootCtx" $rootCtx "objectData" $objectData) | fromYaml) + (include "tc.v1.common.lib.metadata.volumeLabels" (dict "rootCtx" $rootCtx "objectData" $objectData) | fromYaml) (include "tc.v1.common.lib.metadata.selectorLabels" (dict "rootCtx" $rootCtx "objectType" "pod" "objectName" $objectData.shortName) | fromYaml)) -}} {{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $labels) | trim) }} labels: diff --git a/charts/library/common/templates/lib/metadata/_podLabels.tpl b/charts/library/common/templates/lib/metadata/_podLabels.tpl index 0f6b5370f7f6d..f513d2b9aa9cd 100644 --- a/charts/library/common/templates/lib/metadata/_podLabels.tpl +++ b/charts/library/common/templates/lib/metadata/_podLabels.tpl @@ -23,4 +23,5 @@ {{- fail "PodLabels - Template used in a place that is not designed to be used" -}} {{- end }} pod.lifecycle: {{ $label }} + {{- end -}} diff --git a/charts/library/common/templates/lib/metadata/_volumeLabels.tpl b/charts/library/common/templates/lib/metadata/_volumeLabels.tpl new file mode 100644 index 0000000000000..7eff61f4e79ce --- /dev/null +++ b/charts/library/common/templates/lib/metadata/_volumeLabels.tpl @@ -0,0 +1,66 @@ +{{/* Labels that are added to podSpec */}} +{{/* Call this template: +{{ include "tc.v1.common.lib.metadata.volumeLabels" $ }} +*/}} +{{- define "tc.v1.common.lib.metadata.volumeLabels" -}} + + {{- $rootCtx := .rootCtx -}} + {{- $objectData := .objectData -}} + {{- $pvcNames := "" -}} + + {{- range $name, $persistenceValues := $rootCtx.Values.persistence -}} + {{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict + "rootCtx" $rootCtx "objectData" $persistenceValues + "name" $name "caller" "Volumes" + "key" "persistence")) -}} + {{- if (eq $enabled "true") -}} + {{- $persistence := (mustDeepCopy $persistenceValues) -}} + {{- $_ := set $persistence "shortName" $name -}} + + {{- $selected := false -}} + + {{/* If set to true, define volume */}} + {{- if $persistence.targetSelectAll -}} + {{- $selected = true -}} + + {{/* If the pod is the autopermission */}} + {{- else if eq $objectData.shortName "autopermissions" -}} + {{- if $persistence.autoPermissions -}} + {{- if $persistence.autoPermissions.enabled -}} + {{- $selected = true -}} + {{- end -}} + {{- end -}} + + {{/* If targetSelector is set, check if pod is selected */}} + {{- else if $persistence.targetSelector -}} + {{- if not (kindIs "map" $persistence.targetSelector) -}} + {{- fail (printf "Persistence - Expected [targetSelector] to be [dict], but got [%s]" (kindOf $persistence.targetSelector)) -}} + {{- end -}} + + {{- if (mustHas $objectData.shortName (keys $persistence.targetSelector)) -}} + {{- $selected = true -}} + {{- end -}} + + {{/* If no targetSelector is set or targetSelectAll, check if pod is primary */}} + {{- else if $objectData.primary -}} + {{- $selected = true -}} + {{- end -}} + + {{/* If pod selected */}} + {{- if $selected -}} + {{/* Define the volume based on type */}} + {{- $type := ($persistence.type | default $rootCtx.Values.global.fallbackDefaults.persistenceType) -}} + + {{- if eq "pvc" $type }} + {{- if $pvcNames -}} + {{ $pvcNames = ( printf "%s+%s" $pvcNames $name ) }} + {{- else -}} + {{ $pvcNames = $name }} + {{- end -}} + {{ end -}} + {{- end -}} + + {{- end -}} + {{- end -}} +"truecharts.org/pvc": {{ $pvcNames }} +{{- end -}} diff --git a/charts/library/common/templates/lib/pod/_affinity.tpl b/charts/library/common/templates/lib/pod/_affinity.tpl new file mode 100644 index 0000000000000..4da6e27cd06f8 --- /dev/null +++ b/charts/library/common/templates/lib/pod/_affinity.tpl @@ -0,0 +1,42 @@ +{{/* Returns pod affinity */}} +{{/* Call this template: +{{ include "tc.v1.common.lib.pod.affinity" (dict "rootCtx" $ "objectData" $objectData) }} +rootCtx: The root context of the chart. +objectData: The object data to be used to render the Pod. +*/}} +{{- define "tc.v1.common.lib.pod.affinity" -}} + {{- $rootCtx := .rootCtx -}} + {{- $objectData := .objectData -}} + + {{- $affinity := list -}} + + {{/* Initialize from the "global" option */}} + {{- with $rootCtx.Values.podOptions.affinity -}} + {{- $affinity = . -}} + {{- end -}} + + {{/* Override with pods option */}} + {{- with $objectData.podSpec.affinity -}} + {{- $affinity = . -}} + {{- end -}} + + {{- $validTypes := (list "Deployment" "StatefulSet") -}} + {{/* TODO: We need to merge default with user input */}} + {{- $pvcLabels := (include "tc.v1.common.lib.metadata.volumeLabels" (dict "rootCtx" $rootCtx "objectData" $objectData) | fromYaml ) -}} + {{- if and (mustHas $objectData.type $validTypes) $pvcLabels $rootCtx.Values.podOptions.defaultAffinity }} + podAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: + matchExpressions: + - key: app + operator: In + values: + - {{ $pvcLabels | toYaml }} + topologyKey: "kubernetes.io/hostname" + {{- 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 -}} diff --git a/charts/library/common/templates/lib/workload/_pod.tpl b/charts/library/common/templates/lib/workload/_pod.tpl index 31e414cf77a3d..cb4b5219814e4 100644 --- a/charts/library/common/templates/lib/workload/_pod.tpl +++ b/charts/library/common/templates/lib/workload/_pod.tpl @@ -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 }} diff --git a/charts/library/common/values.yaml b/charts/library/common/values.yaml index e5c5e49a31d5e..1b61459fc92dd 100644 --- a/charts/library/common/values.yaml +++ b/charts/library/common/values.yaml @@ -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: ""