From d63db15c42167484a0e852f8e199f5e8a25343a1 Mon Sep 17 00:00:00 2001 From: Pascal Sthamer Date: Wed, 3 Dec 2025 12:43:29 +0100 Subject: [PATCH] fix affinity rules for worker and apps Signed-off-by: Pascal Sthamer --- .../templates/shuffle-app/_helpers.tpl | 52 +++++++++---------- .../templates/shuffle-app/shuffle-apps.yaml | 4 +- .../templates/shuffle-worker/_helpers.tpl | 52 ++++++++----------- .../shuffle-worker/shuffle-worker-dpl.yaml | 6 +-- 4 files changed, 53 insertions(+), 61 deletions(-) diff --git a/functions/kubernetes/charts/shuffle/templates/shuffle-app/_helpers.tpl b/functions/kubernetes/charts/shuffle/templates/shuffle-app/_helpers.tpl index f47f073e..d8718f3e 100644 --- a/functions/kubernetes/charts/shuffle/templates/shuffle-app/_helpers.tpl +++ b/functions/kubernetes/charts/shuffle/templates/shuffle-app/_helpers.tpl @@ -55,6 +55,16 @@ imagePullSecrets: {{- end }} {{- end -}} +{{/* +Return the match labels for ALL apps. +These match the labels of helm-deployed apps (shuffle.appInstance.labels), +as well as worker-deployed apps (deployK8sApp). +*/}} +{{- define "shuffle.app.matchLabels" -}} +app.kubernetes.io/name: shuffle-app +{{- end -}} + + {{/* Return the sanitized name of a shuffle app. Usage: @@ -79,45 +89,33 @@ Usage: {{ include "shuffle.appInstance.labels" (dict "app" $app "customLabels" .Values.commonLabels "context" $) }} */}} {{- define "shuffle.appInstance.labels" -}} -app.kubernetes.io/name: shuffle-app -app.kubernetes.io/instance: {{ include "shuffle.appInstance.fullname" .app }} -helm.sh/chart: {{ include "common.names.chart" .context }} -app.kubernetes.io/instance: {{ .context.Release.Name }} -app.kubernetes.io/managed-by: {{ .context.Release.Service }} -app.kubernetes.io/part-of: shuffle +{{- $customLabels := mustMerge (dict "app.kubernetes.io/name" "shuffle-app" "app.kubernetes.io/part-of" "shuffle") $customLabels -}} +{{ include "common.labels.standard" (dict "customLabels" $customLabels "context" $) }} app.shuffler.io/name: {{ include "shuffle.appInstance.name" .app }} app.shuffler.io/version: {{ .app.version | quote }} -{{- if .customLabels }} -{{- range $key, $value := .customLabels }} -{{ $key }}: {{ $value }} -{{- end }} -{{- end }} {{- end -}} -{{/* -Return the match labels for ALL apps. -These match the labels of helm-deployed apps (shuffle.appInstance.labels), -as well as worker-deployed apps (deployK8sApp). -*/}} -{{- define "shuffle.app.matchLabels" -}} -app.kubernetes.io/name: shuffle-app -{{- end -}} - - {{/* Return the match labels of a single app, deployed via helm. Usage: {{ include "shuffle.appInstance.matchLabels" (dict "app" $app "customLabels" .Values.commonLabels "context" $) }} */}} {{- define "shuffle.appInstance.matchLabels" -}} -app.kubernetes.io/name: shuffle-app +{{- $customLabels := mustMerge (dict "app.kubernetes.io/name" "shuffle-app" "app.kubernetes.io/part-of" "shuffle") $customLabels -}} +{{ include "common.labels.matchLabels" (dict "customLabels" $customLabels "context" $) }} app.shuffler.io/name: {{ include "shuffle.appInstance.name" .app }} app.shuffler.io/version: {{ .app.version | quote }} -{{- if .customLabels }} -{{- range $key, $value := .customLabels }} -{{ $key }}: {{ $value }} -{{- end }} -{{- end }} +{{- end -}} + +{{/* +Return a podAffinity/podAntiAffinity definition. +Usage: +{{ include "shuffle.appInstance.affinities.pods" (dict "type" "soft" "app" $app "customLabels" $podLabels "context" $) -}} +*/}} +{{- define "shuffle.appInstance.affinities.pods" -}} +{{- $customLabels := mustMerge (dict "app.kubernetes.io/name" "shuffle-app" "app.kubernetes.io/part-of" "shuffle") .customLabels -}} +{{- $extraMatchLabels := dict "app.shuffler.io/name" (include "shuffle.appInstance.name" .app) "app.shuffler.io/version" (.app.version | quote) }} +{{ include "common.affinities.pods" (dict "type" .type "customLabels" $customLabels "context" .context "extraMatchLabels" $extraMatchLabels )}} {{- end -}} {{/* diff --git a/functions/kubernetes/charts/shuffle/templates/shuffle-app/shuffle-apps.yaml b/functions/kubernetes/charts/shuffle/templates/shuffle-app/shuffle-apps.yaml index 112c6241..df16f4c7 100644 --- a/functions/kubernetes/charts/shuffle/templates/shuffle-app/shuffle-apps.yaml +++ b/functions/kubernetes/charts/shuffle/templates/shuffle-app/shuffle-apps.yaml @@ -73,8 +73,8 @@ spec: affinity: {{- include "common.tplvalues.render" ( dict "value" $appValues.affinity "context" $) | nindent 8 }} {{- else }} affinity: - podAffinity: {{- include "common.affinities.pods" (dict "type" $appValues.podAffinityPreset "customLabels" $podLabels "context" $) | nindent 10 }} - podAntiAffinity: {{- include "common.affinities.pods" (dict "type" $appValues.podAntiAffinityPreset "customLabels" $podLabels "context" $) | nindent 10 }} + podAffinity: {{- include "shuffle.appInstance.affinities.pods" (dict "app" $app "type" $appValues.podAffinityPreset "customLabels" $podLabels "context" $) | nindent 10 }} + podAntiAffinity: {{- include "shuffle.appInstance.affinities.pods" (dict "app" $app "type" $appValues.podAntiAffinityPreset "customLabels" $podLabels "context" $) | nindent 10 }} nodeAffinity: {{- include "common.affinities.nodes" (dict "type" $appValues.nodeAffinityPreset.type "key" $appValues.nodeAffinityPreset.key "values" $appValues.nodeAffinityPreset.values) | nindent 10 }} {{- end }} {{- if $appValues.nodeSelector }} diff --git a/functions/kubernetes/charts/shuffle/templates/shuffle-worker/_helpers.tpl b/functions/kubernetes/charts/shuffle/templates/shuffle-worker/_helpers.tpl index b9f223fd..d58b3912 100644 --- a/functions/kubernetes/charts/shuffle/templates/shuffle-worker/_helpers.tpl +++ b/functions/kubernetes/charts/shuffle/templates/shuffle-worker/_helpers.tpl @@ -62,27 +62,6 @@ imagePullSecrets: {{- end }} {{- end -}} -{{/* -Return the labels for a specific worker instance deployed via helm. -Usage: -{{ include "shuffle.workerInstance.labels" (dict "customLabels" .Values.commonLabels "context" $) -}} -*/}} -{{- define "shuffle.workerInstance.labels" -}} -app.kubernetes.io/name: shuffle-worker -helm.sh/chart: {{ include "common.names.chart" .context }} -app.kubernetes.io/instance: {{ .context.Release.Name }} -app.kubernetes.io/managed-by: {{ .context.Release.Service }} -app.kubernetes.io/part-of: shuffle -{{- with .context.Chart.AppVersion }} -app.kubernetes.io/version: {{ . | replace "+" "_" | quote }} -{{- end -}} -{{- if .customLabels }} -{{- range $key, $value := .customLabels }} -{{ $key }}: {{ $value }} -{{- end }} -{{- end }} -{{- end -}} - {{/* Return the labels to match ALL workers. These match the labels of helm-deployed workers (shuffle.workerInstance.labels), @@ -92,19 +71,34 @@ as well as orborus-deployed workers (deployk8sworker). app.kubernetes.io/name: shuffle-worker {{- end -}} +{{/* +Return the labels for a specific worker instance deployed via helm. +Usage: +{{ include "shuffle.workerInstance.labels" (dict "customLabels" $podLabels "context" $) -}} +*/}} +{{- define "shuffle.workerInstance.labels" -}} +{{- $customLabels := mustMerge (dict "app.kubernetes.io/name" "shuffle-worker" "app.kubernetes.io/part-of" "shuffle") $customLabels -}} +{{ include "common.labels.standard" (dict "customLabels" $customLabels "context" $) }} +{{- end -}} + {{/* Return the labels to match a helm-deployed worker. Usage: -{{ include "shuffle.workerInstance.matchLabels" (dict "customLabels" .Values.commonLabels "context" $) -}} +{{ include "shuffle.workerInstance.matchLabels" (dict "customLabels" $podLabels "context" $) -}} */}} {{- define "shuffle.workerInstance.matchLabels" -}} -app.kubernetes.io/name: shuffle-worker -app.kubernetes.io/instance: {{ .context.Release.Name }} -{{- if .customLabels }} -{{- range $key, $value := .customLabels }} -{{ $key }}: {{ $value }} -{{- end }} -{{- end }} +{{- $customLabels := mustMerge (dict "app.kubernetes.io/name" "shuffle-worker" "app.kubernetes.io/part-of" "shuffle") $customLabels -}} +{{ include "common.labels.matchLabels" (dict "customLabels" $customLabels "context" $) }} +{{- end -}} + +{{/* +Return a podAffinity/podAntiAffinity definition. +Usage: +{{ include "shuffle.workerInstance.affinities.pods" (dict "type" "soft" "customLabels" $podLabels "context" $) -}} +*/}} +{{- define "shuffle.workerInstance.affinities.pods" -}} +{{- $customLabels := mustMerge (dict "app.kubernetes.io/name" "shuffle-worker" "app.kubernetes.io/part-of" "shuffle") .customLabels -}} +{{ include "common.affinities.pods" (dict "type" .type "customLabels" $customLabels "context" .context )}} {{- end -}} {{/* diff --git a/functions/kubernetes/charts/shuffle/templates/shuffle-worker/shuffle-worker-dpl.yaml b/functions/kubernetes/charts/shuffle/templates/shuffle-worker/shuffle-worker-dpl.yaml index 09d00269..748fe232 100644 --- a/functions/kubernetes/charts/shuffle/templates/shuffle-worker/shuffle-worker-dpl.yaml +++ b/functions/kubernetes/charts/shuffle/templates/shuffle-worker/shuffle-worker-dpl.yaml @@ -36,8 +36,8 @@ spec: affinity: {{- include "common.tplvalues.render" ( dict "value" .Values.worker.affinity "context" $) | nindent 8 }} {{- else }} affinity: - podAffinity: {{- include "common.affinities.pods" (dict "type" .Values.worker.podAffinityPreset "component" "orborus" "customLabels" $podLabels "context" $) | nindent 10 }} - podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.worker.podAntiAffinityPreset "component" "orborus" "customLabels" $podLabels "context" $) | nindent 10 }} + podAffinity: {{- include "shuffle.workerInstance.affinities.pods" (dict "type" .Values.worker.podAffinityPreset "customLabels" $podLabels "context" $) | nindent 10 }} + podAntiAffinity: {{- include "shuffle.workerInstance.affinities.pods" (dict "type" .Values.worker.podAntiAffinityPreset "customLabels" $podLabels "context" $) | nindent 10 }} nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.worker.nodeAffinityPreset.type "key" .Values.worker.nodeAffinityPreset.key "values" .Values.worker.nodeAffinityPreset.values) | nindent 10 }} {{- end }} {{- if .Values.worker.nodeSelector }} @@ -66,7 +66,7 @@ spec: {{- include "common.tplvalues.render" (dict "value" .Values.worker.initContainers "context" $) | nindent 8 }} {{- end }} containers: - - name: orborus + - name: worker image: {{ template "shuffle.worker.image" . }} imagePullPolicy: {{ .Values.worker.image.pullPolicy }} {{- if .Values.worker.containerSecurityContext.enabled }}