From 6657003d6574f298863f8ac7561f8d1a73e29197 Mon Sep 17 00:00:00 2001
From: allegroai <>
Date: Thu, 29 Feb 2024 13:49:30 +0200
Subject: [PATCH] Fix using controller-uid will not always return required pods

---
 clearml_agent/glue/k8s.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clearml_agent/glue/k8s.py b/clearml_agent/glue/k8s.py
index 21d3232..e6fddd5 100644
--- a/clearml_agent/glue/k8s.py
+++ b/clearml_agent/glue/k8s.py
@@ -372,8 +372,9 @@ class K8sIntegration(Worker):
             self.log.warning('Failed parsing kubectl output:\n{}\nEx: {}'.format(output, ex))
 
     def get_pods_for_jobs(self, job_condition: str = None, pod_filters: List[str] = None, debug_msg: str = None):
+        # Use metadata.uid so job related pods can be found filterin g following list with this param
         controller_uids = self.get_jobs_info(
-            "spec.selector.matchLabels.controller-uid", condition=job_condition, debug_msg=debug_msg
+            "metadata.uid", condition=job_condition, debug_msg=debug_msg
         )
         if not controller_uids:
             # No pods were found for these jobs