Skip to content

Commit 4b8af7e

Browse files
committed
feat: Launchers - Kubernetes - Support a temporary way to implicitly pass multi-node information to the component code
When multi-node is activated, the component code will have access to the following environment variables: * `_TANGLE_MULTI_NODE_NUMBER_OF_NODES` * `_TANGLE_MULTI_NODE_NODE_INDEX` After testing, this implementation will be replaced by more explicit way to consume multi-node information (dynamicData arguments passed to component inputs).
1 parent b042255 commit 4b8af7e

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

cloud_pipelines_backend/launchers/kubernetes_launchers.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,12 +919,43 @@ def launch_container_task(
919919
num_nodes_annotation_str = (annotations or {}).get(
920920
MULTI_NODE_NUMBER_OF_NODES_ANNOTATION_KEY, 1
921921
)
922+
enable_multi_node = num_nodes_annotation_str is not None
922923
num_nodes = int(num_nodes_annotation_str) if num_nodes_annotation_str else 1
923924
if not (0 < num_nodes <= 16):
924925
raise interfaces.LauncherError(
925926
f"Invalid number of nodes for multi-node execution. Number of nodes must be between 1 and 16, but got {num_nodes}."
926927
)
927928

929+
if enable_multi_node:
930+
# Temporary implementation of implicitly passing multi-node information to the component code.
931+
# After testing, this implementation will be replaced by more explicit way to consume multi-node information (dynamicData arguments passed to component inputs).
932+
MULTI_NODE_NUMBER_OF_NODES_ENV_VAR_NAME = (
933+
"_TANGLE_MULTI_NODE_NUMBER_OF_NODES"
934+
)
935+
MULTI_NODE_NODE_INDEX_ENV_VAR_NAME = "_TANGLE_MULTI_NODE_NODE_INDEX"
936+
937+
main_container_spec = pod.spec.containers[0]
938+
main_container_spec.env = main_container_spec.env or []
939+
main_container_spec.env.append(
940+
k8s_client_lib.V1EnvVar(
941+
name=MULTI_NODE_NUMBER_OF_NODES_ENV_VAR_NAME,
942+
value=str(num_nodes),
943+
)
944+
)
945+
main_container_spec.env.append(
946+
k8s_client_lib.V1EnvVar(
947+
name=MULTI_NODE_NODE_INDEX_ENV_VAR_NAME,
948+
# We cannot use "$(JOB_COMPLETION_INDEX)" in env variables since it's added after all other env variables.
949+
# value="$(JOB_COMPLETION_INDEX)",
950+
# So we just recreate it by reading the pod annotation/label that Kubernetes sets on pods of indexed jobs.
951+
value_from=k8s_client_lib.V1EnvVarSource(
952+
field_ref=k8s_client_lib.V1ObjectFieldSelector(
953+
field_path="metadata.annotations['batch.kubernetes.io/job-completion-index']"
954+
)
955+
),
956+
)
957+
)
958+
928959
job_name_prefix = "job-" + pod.metadata.generate_name
929960

930961
job = k8s_client_lib.V1Job(

0 commit comments

Comments
 (0)