From 69c7c7bb06c7ec50700e20ef9720ed4a32a6464c Mon Sep 17 00:00:00 2001 From: Pascal Sthamer Date: Wed, 3 Dec 2025 11:58:46 +0100 Subject: [PATCH] fix label matching for worker and apps Signed-off-by: Pascal Sthamer --- .../backend/backend-network-policy.yaml | 4 ++-- .../orborus/orborus-network-policy.yaml | 2 +- .../templates/shuffle-app/_helpers.tpl | 23 ++++++++++++++++--- .../shuffle-app-network-policy.yaml | 6 ++--- .../templates/shuffle-app/shuffle-apps.yaml | 1 - .../templates/shuffle-worker/_helpers.tpl | 21 ++++++++++++++--- .../shuffle-worker-network-policy.yaml | 7 +++--- .../shuffle-worker/shuffle-worker-svc.yaml | 3 ++- 8 files changed, 49 insertions(+), 18 deletions(-) diff --git a/functions/kubernetes/charts/shuffle/templates/backend/backend-network-policy.yaml b/functions/kubernetes/charts/shuffle/templates/backend/backend-network-policy.yaml index 516c9f33..48010706 100644 --- a/functions/kubernetes/charts/shuffle/templates/backend/backend-network-policy.yaml +++ b/functions/kubernetes/charts/shuffle/templates/backend/backend-network-policy.yaml @@ -51,14 +51,14 @@ spec: matchLabels: kubernetes.io/metadata.name: {{ .Release.Namespace }} podSelector: - matchLabels: {{ include "shuffle.workerInstance.matchLabels" . | nindent 14 }} + matchLabels: {{ include "shuffle.worker.matchLabels" . | nindent 14 }} # Allow traffic from apps - namespaceSelector: matchLabels: kubernetes.io/metadata.name: {{ .Release.Namespace }} podSelector: - matchLabels: {{ include "shuffle.appInstance.matchLabels" . | nindent 14 }} + matchLabels: {{ include "shuffle.app.matchLabels" . | nindent 14 }} {{- end }} {{- if .Values.backend.networkPolicy.extraIngress }} {{- include "common.tplvalues.render" ( dict "value" .Values.backend.networkPolicy.extraIngress "context" $ ) | nindent 4 }} diff --git a/functions/kubernetes/charts/shuffle/templates/orborus/orborus-network-policy.yaml b/functions/kubernetes/charts/shuffle/templates/orborus/orborus-network-policy.yaml index 68ea9aa5..f55bf957 100644 --- a/functions/kubernetes/charts/shuffle/templates/orborus/orborus-network-policy.yaml +++ b/functions/kubernetes/charts/shuffle/templates/orborus/orborus-network-policy.yaml @@ -48,7 +48,7 @@ spec: matchLabels: kubernetes.io/metadata.name: {{ .Release.Namespace }} podSelector: - matchLabels: {{ include "shuffle.workerInstance.matchLabels" . | nindent 14 }} + matchLabels: {{ include "shuffle.worker.matchLabels" . | nindent 14 }} {{- if .Values.orborus.networkPolicy.extraEgress }} {{- include "common.tplvalues.render" ( dict "value" .Values.orborus.networkPolicy.extraEgress "context" $ ) | nindent 4 }} {{- end }} diff --git a/functions/kubernetes/charts/shuffle/templates/shuffle-app/_helpers.tpl b/functions/kubernetes/charts/shuffle/templates/shuffle-app/_helpers.tpl index 027a49a0..f47f073e 100644 --- a/functions/kubernetes/charts/shuffle/templates/shuffle-app/_helpers.tpl +++ b/functions/kubernetes/charts/shuffle/templates/shuffle-app/_helpers.tpl @@ -87,7 +87,7 @@ app.kubernetes.io/managed-by: {{ .context.Release.Service }} app.kubernetes.io/part-of: shuffle app.shuffler.io/name: {{ include "shuffle.appInstance.name" .app }} app.shuffler.io/version: {{ .app.version | quote }} -{{- if .customValues }} +{{- if .customLabels }} {{- range $key, $value := .customLabels }} {{ $key }}: {{ $value }} {{- end }} @@ -95,12 +95,29 @@ app.shuffler.io/version: {{ .app.version | quote }} {{- end -}} {{/* -Return the match labels for apps. -These must match the labels of helm-deployed apps (shuffle.appInstance.labels), +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 +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 -}} {{/* diff --git a/functions/kubernetes/charts/shuffle/templates/shuffle-app/shuffle-app-network-policy.yaml b/functions/kubernetes/charts/shuffle/templates/shuffle-app/shuffle-app-network-policy.yaml index 73c0572e..a8493002 100644 --- a/functions/kubernetes/charts/shuffle/templates/shuffle-app/shuffle-app-network-policy.yaml +++ b/functions/kubernetes/charts/shuffle/templates/shuffle-app/shuffle-app-network-policy.yaml @@ -11,7 +11,7 @@ metadata: spec: {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.app.podLabels .Values.commonLabels ) "context" . ) }} podSelector: - matchLabels: {{- include "shuffle.appInstance.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 6 }} + matchLabels: {{- include "shuffle.app.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 6 }} policyTypes: - Ingress - Egress @@ -48,7 +48,7 @@ spec: matchLabels: kubernetes.io/metadata.name: {{ .Release.Namespace }} podSelector: - matchLabels: {{ include "shuffle.workerInstance.matchLabels" . | nindent 14 }} + matchLabels: {{ include "shuffle.worker.matchLabels" . | nindent 14 }} {{- if .Values.app.networkPolicy.extraEgress }} {{- include "common.tplvalues.render" ( dict "value" .Values.app.networkPolicy.extraEgress "context" $ ) | nindent 4 }} {{- end }} @@ -64,7 +64,7 @@ spec: matchLabels: kubernetes.io/metadata.name: {{ .Release.Namespace }} podSelector: - matchLabels: {{ include "shuffle.workerInstance.matchLabels" . | nindent 14 }} + matchLabels: {{ include "shuffle.worker.matchLabels" . | nindent 14 }} {{- end }} {{- if .Values.app.networkPolicy.extraIngress }} {{- include "common.tplvalues.render" ( dict "value" .Values.app.networkPolicy.extraIngress "context" $ ) | nindent 4 }} 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 d1af8c02..112c6241 100644 --- a/functions/kubernetes/charts/shuffle/templates/shuffle-app/shuffle-apps.yaml +++ b/functions/kubernetes/charts/shuffle/templates/shuffle-app/shuffle-apps.yaml @@ -214,7 +214,6 @@ spec: {{- if or $appValues.pdb.maxUnavailable ( not $appValues.pdb.minAvailable ) }} maxUnavailable: {{ $appValues.pdb.maxUnavailable | default 1 }} {{- end }} - {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list $appValues.podLabels $.Values.commonLabels ) "context" $ ) }} selector: matchLabels: {{- include "shuffle.appInstance.matchLabels" ( dict "app" $app "customLabels" $podLabels "context" $ ) | nindent 6 }} {{- end }} diff --git a/functions/kubernetes/charts/shuffle/templates/shuffle-worker/_helpers.tpl b/functions/kubernetes/charts/shuffle/templates/shuffle-worker/_helpers.tpl index d9e16fea..b9f223fd 100644 --- a/functions/kubernetes/charts/shuffle/templates/shuffle-worker/_helpers.tpl +++ b/functions/kubernetes/charts/shuffle/templates/shuffle-worker/_helpers.tpl @@ -76,7 +76,7 @@ app.kubernetes.io/part-of: shuffle {{- with .context.Chart.AppVersion }} app.kubernetes.io/version: {{ . | replace "+" "_" | quote }} {{- end -}} -{{- if .customValues }} +{{- if .customLabels }} {{- range $key, $value := .customLabels }} {{ $key }}: {{ $value }} {{- end }} @@ -84,12 +84,27 @@ app.kubernetes.io/version: {{ . | replace "+" "_" | quote }} {{- end -}} {{/* -Return the match labels for workers. -These must match the labels of helm-deployed workers (shuffle.workerInstance.labels), +Return the labels to match ALL workers. +These match the labels of helm-deployed workers (shuffle.workerInstance.labels), as well as orborus-deployed workers (deployk8sworker). */}} +{{- define "shuffle.worker.matchLabels" -}} +app.kubernetes.io/name: shuffle-worker +{{- end -}} + +{{/* +Return the labels to match a helm-deployed worker. +Usage: +{{ include "shuffle.workerInstance.matchLabels" (dict "customLabels" .Values.commonLabels "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 }} {{- end -}} {{/* diff --git a/functions/kubernetes/charts/shuffle/templates/shuffle-worker/shuffle-worker-network-policy.yaml b/functions/kubernetes/charts/shuffle/templates/shuffle-worker/shuffle-worker-network-policy.yaml index 259300e1..514f3815 100644 --- a/functions/kubernetes/charts/shuffle/templates/shuffle-worker/shuffle-worker-network-policy.yaml +++ b/functions/kubernetes/charts/shuffle/templates/shuffle-worker/shuffle-worker-network-policy.yaml @@ -9,9 +9,8 @@ metadata: annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }} {{- end }} spec: - {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.worker.podLabels .Values.commonLabels ) "context" . ) }} podSelector: - matchLabels: {{- include "shuffle.workerInstance.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 6 }} + matchLabels: {{- include "shuffle.worker.matchLabels" . | nindent 6 }} policyTypes: - Ingress - Egress @@ -35,7 +34,7 @@ spec: matchLabels: kubernetes.io/metadata.name: {{ .Release.Namespace }} podSelector: - matchLabels: {{ include "shuffle.appInstance.matchLabels" . | nindent 14 }} + matchLabels: {{- include "shuffle.app.matchLabels" . | nindent 14 }} {{- if .Values.worker.networkPolicy.extraEgress }} {{- include "common.tplvalues.render" ( dict "value" .Values.worker.networkPolicy.extraEgress "context" $ ) | nindent 4 }} {{- end }} @@ -57,7 +56,7 @@ spec: matchLabels: kubernetes.io/metadata.name: {{ .Release.Namespace }} podSelector: - matchLabels: {{ include "shuffle.appInstance.matchLabels" . | nindent 14 }} + matchLabels: {{- include "shuffle.app.matchLabels" . | nindent 14 }} {{- end }} {{- if .Values.worker.networkPolicy.extraIngress }} {{- include "common.tplvalues.render" ( dict "value" .Values.worker.networkPolicy.extraIngress "context" $ ) | nindent 4 }} diff --git a/functions/kubernetes/charts/shuffle/templates/shuffle-worker/shuffle-worker-svc.yaml b/functions/kubernetes/charts/shuffle/templates/shuffle-worker/shuffle-worker-svc.yaml index 79f5be00..b9f355a5 100644 --- a/functions/kubernetes/charts/shuffle/templates/shuffle-worker/shuffle-worker-svc.yaml +++ b/functions/kubernetes/charts/shuffle/templates/shuffle-worker/shuffle-worker-svc.yaml @@ -17,5 +17,6 @@ spec: targetPort: 33333 protocol: TCP appProtocol: http - selector: {{- include "shuffle.workerInstance.matchLabels" $ | nindent 4 }} + {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.worker.podLabels .Values.commonLabels ) "context" . ) }} + selector: {{- include "shuffle.workerInstance.matchLabels" (dict "customLabels" $podLabels "context" .) | nindent 4 }} {{- end }} \ No newline at end of file