From 7545c37ddf300ea6062d64cb74546d864afb8aec Mon Sep 17 00:00:00 2001 From: ThibaultFy Date: Mon, 24 Jun 2024 14:43:32 +0200 Subject: [PATCH] chore: toYaml Signed-off-by: ThibaultFy --- backend/substrapp/compute_tasks/compute_pod.py | 8 ++++---- .../templates/statefulset-worker.yaml | 6 +++--- charts/substra-backend/values.yaml | 17 +++++++++-------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/backend/substrapp/compute_tasks/compute_pod.py b/backend/substrapp/compute_tasks/compute_pod.py index 1deb1b367..63d65444f 100644 --- a/backend/substrapp/compute_tasks/compute_pod.py +++ b/backend/substrapp/compute_tasks/compute_pod.py @@ -1,4 +1,4 @@ -import json +import yaml import os import kubernetes @@ -129,9 +129,9 @@ def create_pod( image_pull_secrets = None spec = kubernetes.client.V1PodSpec( restart_policy="Never", - affinity=json.loads(os.getenv("COMPUTE_POD_AFFINITY")), - node_selector=json.loads(os.getenv("COMPUTE_POD_NODE_SELECTOR")), - tolerations=json.loads(os.getenv("COMPUTE_POD_TOLERATIONS")), + affinity=yaml.safe_load(os.getenv("COMPUTE_POD_AFFINITY")), + node_selector=yaml.safe_load(os.getenv("COMPUTE_POD_NODE_SELECTOR")), + tolerations=yaml.safe_load(os.getenv("COMPUTE_POD_TOLERATIONS")), containers=[container_compute], volumes=volumes + gpu_volume, security_context=get_pod_security_context(), diff --git a/charts/substra-backend/templates/statefulset-worker.yaml b/charts/substra-backend/templates/statefulset-worker.yaml index 161f2d356..2e18b8992 100644 --- a/charts/substra-backend/templates/statefulset-worker.yaml +++ b/charts/substra-backend/templates/statefulset-worker.yaml @@ -131,11 +131,11 @@ spec: fieldRef: fieldPath: metadata.name - name: COMPUTE_POD_AFFINITY - value: {{ .Values.worker.computePod.affinity | quote }} # TODO see if it works to inject POD_NAME venv in string + value: {{ toYaml .Values.worker.computePod.affinity | quote }} # TODO see if it works to inject POD_NAME venv in string - name: COMPUTE_POD_NODE_SELECTOR - value: {{ .Values.worker.computePod.nodeSelector | quote }} + value: {{ toYaml .Values.worker.computePod.nodeSelector | quote }} - name: COMPUTE_POD_TOLERATIONS - value: {{ .Values.worker.computePod.tolerations | quote }} + value: {{ toYaml .Values.worker.computePod.tolerations | quote }} - name: COMPUTE_POD_RESOURCES value: {{ toYaml .Values.worker.computePod.resources | quote }} - name: COMPUTE_POD_MAX_STARTUP_WAIT_SECONDS diff --git a/charts/substra-backend/values.yaml b/charts/substra-backend/values.yaml index e4a361380..0477b7304 100644 --- a/charts/substra-backend/values.yaml +++ b/charts/substra-backend/values.yaml @@ -373,18 +373,19 @@ worker: ## @param worker.computePod.tolerations Toleration labels for pod assignment ## tolerations: [] - ## @param worker.computePod.affinity Worker compute pod container affinity + ## @param worker.computePod.affinity Worker compute pod container affinity. Pass as a string in order to catch the generated pod name on the statefuset environment variable PODNAME. ## + ## '{"podAffinity": {"requiredDuringSchedulingIgnoredDuringExecution": {"topologyKey":"kubernetes.io/hostname", "labelSelector": {"matchExpressions":{"key":"statefulset.kubernetes.io/pod-name", "operator":"In","values":"$POD_NAME"}}}}}' affinity: podAffinity: requiredDuringSchedulingIgnoredDuringExecution: - - labelSelector: - matchExpressions: - - key: statefulset.kubernetes.io/pod-name - operator: In - values: - - $(POD_NAME) - topologyKey: kubernetes.io/hostname" + - labelSelector: + matchExpressions: + - key: statefulset.kubernetes.io/pod-name + operator: In + values: + - POD_NAME + topologyKey: kubernetes.io/hostname events: ## @param worker.events.enabled Enable event service ##