This is an automated email from the ASF dual-hosted git repository.
zihaoxiang pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new 70d6d01ce3 fix(16424): K8sUtils#jobExists may cause huge memory usage
(#16432)
70d6d01ce3 is described below
commit 70d6d01ce34776683bfc2904948ab9d67fce27a1
Author: Terry Tao <[email protected]>
AuthorDate: Sat Aug 10 20:30:46 2024 +0800
fix(16424): K8sUtils#jobExists may cause huge memory usage (#16432)
---
.../dolphinscheduler/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<Job> result;
try {
- JobList jobList =
client.batch().jobs().inNamespace(namespace).list();
- List<Job> 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);
}