46
46
from kubernetes import config as k8s_config
47
47
48
48
from zenml .config .base_settings import BaseSettings
49
+ from zenml .constants import (
50
+ METADATA_ORCHESTRATOR_RUN_ID ,
51
+ )
49
52
from zenml .enums import StackComponentType
50
53
from zenml .integrations .kubernetes .flavors .kubernetes_orchestrator_flavor import (
51
54
KubernetesOrchestratorConfig ,
61
64
)
62
65
from zenml .integrations .kubernetes .pod_settings import KubernetesPodSettings
63
66
from zenml .logger import get_logger
67
+ from zenml .metadata .metadata_types import MetadataType
64
68
from zenml .orchestrators import ContainerizedOrchestrator , SubmissionResult
65
69
from zenml .orchestrators .utils import get_orchestrator_run_name
66
70
from zenml .stack import StackValidator
@@ -467,9 +471,7 @@ def submit_pipeline(
467
471
# This will internally also build the command/args for all step pods.
468
472
command = KubernetesOrchestratorEntrypointConfiguration .get_entrypoint_command ()
469
473
args = KubernetesOrchestratorEntrypointConfiguration .get_entrypoint_arguments (
470
- run_name = orchestrator_run_name ,
471
474
deployment_id = deployment .id ,
472
- kubernetes_namespace = self .config .kubernetes_namespace ,
473
475
run_id = placeholder_run .id if placeholder_run else None ,
474
476
)
475
477
@@ -508,6 +510,18 @@ def submit_pipeline(
508
510
}
509
511
)
510
512
513
+ orchestrator_pod_labels = {
514
+ "pipeline" : kube_utils .sanitize_label (pipeline_name ),
515
+ }
516
+
517
+ if placeholder_run :
518
+ orchestrator_pod_labels ["run_id" ] = kube_utils .sanitize_label (
519
+ str (placeholder_run .id )
520
+ )
521
+ orchestrator_pod_labels ["run_name" ] = kube_utils .sanitize_label (
522
+ str (placeholder_run .name )
523
+ )
524
+
511
525
# Schedule as CRON job if CRON schedule is given.
512
526
if deployment .schedule :
513
527
if not deployment .schedule .cron_expression :
@@ -519,9 +533,7 @@ def submit_pipeline(
519
533
cron_expression = deployment .schedule .cron_expression
520
534
cron_job_manifest = build_cron_job_manifest (
521
535
cron_expression = cron_expression ,
522
- run_name = orchestrator_run_name ,
523
536
pod_name = pod_name ,
524
- pipeline_name = pipeline_name ,
525
537
image_name = image ,
526
538
command = command ,
527
539
args = args ,
@@ -533,6 +545,7 @@ def submit_pipeline(
533
545
successful_jobs_history_limit = settings .successful_jobs_history_limit ,
534
546
failed_jobs_history_limit = settings .failed_jobs_history_limit ,
535
547
ttl_seconds_after_finished = settings .ttl_seconds_after_finished ,
548
+ labels = orchestrator_pod_labels ,
536
549
)
537
550
538
551
self ._k8s_batch_api .create_namespaced_cron_job (
@@ -547,16 +560,15 @@ def submit_pipeline(
547
560
else :
548
561
# Create and run the orchestrator pod.
549
562
pod_manifest = build_pod_manifest (
550
- run_name = orchestrator_run_name ,
551
563
pod_name = pod_name ,
552
- pipeline_name = pipeline_name ,
553
564
image_name = image ,
554
565
command = command ,
555
566
args = args ,
556
567
privileged = False ,
557
568
pod_settings = orchestrator_pod_settings ,
558
569
service_account_name = service_account_name ,
559
570
env = environment ,
571
+ labels = orchestrator_pod_labels ,
560
572
mount_local_stores = self .config .is_local ,
561
573
)
562
574
@@ -572,6 +584,11 @@ def submit_pipeline(
572
584
startup_timeout = settings .pod_startup_timeout ,
573
585
)
574
586
587
+ metadata : Dict [str , MetadataType ] = {
588
+ METADATA_ORCHESTRATOR_RUN_ID : pod_name ,
589
+ }
590
+
591
+ # Wait for the orchestrator pod to finish and stream logs.
575
592
if settings .synchronous :
576
593
577
594
def _wait_for_run_to_finish () -> None :
@@ -588,7 +605,8 @@ def _wait_for_run_to_finish() -> None:
588
605
)
589
606
590
607
return SubmissionResult (
591
- wait_for_completion = _wait_for_run_to_finish
608
+ metadata = metadata ,
609
+ wait_for_completion = _wait_for_run_to_finish ,
592
610
)
593
611
else :
594
612
logger .info (
@@ -597,7 +615,9 @@ def _wait_for_run_to_finish() -> None:
597
615
f"Run the following command to inspect the logs: "
598
616
f"`kubectl logs { pod_name } -n { self .config .kubernetes_namespace } `."
599
617
)
600
- return None
618
+ return SubmissionResult (
619
+ metadata = metadata ,
620
+ )
601
621
602
622
def _get_service_account_name (
603
623
self , settings : KubernetesOrchestratorSettings
@@ -642,3 +662,18 @@ def get_orchestrator_run_id(self) -> str:
642
662
"Unable to read run id from environment variable "
643
663
f"{ ENV_ZENML_KUBERNETES_RUN_ID } ."
644
664
)
665
+
666
+ def get_pipeline_run_metadata (
667
+ self , run_id : UUID
668
+ ) -> Dict [str , "MetadataType" ]:
669
+ """Get general component-specific metadata for a pipeline run.
670
+
671
+ Args:
672
+ run_id: The ID of the pipeline run.
673
+
674
+ Returns:
675
+ A dictionary of metadata.
676
+ """
677
+ return {
678
+ METADATA_ORCHESTRATOR_RUN_ID : self .get_orchestrator_run_id (),
679
+ }
0 commit comments