From 70d6d01ce34776683bfc2904948ab9d67fce27a1 Mon Sep 17 00:00:00 2001 From: Terry Tao Date: Sat, 10 Aug 2024 20:30:46 +0800 Subject: [PATCH] fix(16424): K8sUtils#jobExists may cause huge memory usage (#16432) --- .../plugin/task/api/utils/K8sUtils.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/K8sUtils.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/K8sUtils.java index ca8347b19b..a96f3ebb01 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/K8sUtils.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/K8sUtils.java @@ -22,12 +22,10 @@ import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.LOG_LINE import org.apache.dolphinscheduler.plugin.task.api.TaskException; import java.util.List; -import java.util.Optional; import lombok.extern.slf4j.Slf4j; import io.fabric8.kubernetes.api.model.Pod; import io.fabric8.kubernetes.api.model.batch.v1.Job; -import io.fabric8.kubernetes.api.model.batch.v1.JobList; import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClientBuilder; @@ -65,14 +63,9 @@ public class K8sUtils { } public Boolean jobExist(String jobName, String namespace) { - Optional result; try { - JobList jobList = client.batch().jobs().inNamespace(namespace).list(); - List jobs = jobList.getItems(); - result = jobs.stream() - .filter(job -> job.getMetadata().getName().equals(jobName)) - .findFirst(); - return result.isPresent(); + Job job = client.batch().v1().jobs().inNamespace(namespace).withName(jobName).get(); + return job != null; } catch (Exception e) { throw new TaskException("fail to check job: ", e); }