Browse Source

fix(16424): K8sUtils#jobExists may cause huge memory usage (#16432)

dev
Terry Tao 4 months ago committed by GitHub
parent
commit
70d6d01ce3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 11
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/K8sUtils.java

11
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 org.apache.dolphinscheduler.plugin.task.api.TaskException;
import java.util.List; import java.util.List;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import io.fabric8.kubernetes.api.model.Pod; import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.batch.v1.Job; 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.Config;
import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder; import io.fabric8.kubernetes.client.KubernetesClientBuilder;
@ -65,14 +63,9 @@ public class K8sUtils {
} }
public Boolean jobExist(String jobName, String namespace) { public Boolean jobExist(String jobName, String namespace) {
Optional<Job> result;
try { try {
JobList jobList = client.batch().jobs().inNamespace(namespace).list(); Job job = client.batch().v1().jobs().inNamespace(namespace).withName(jobName).get();
List<Job> jobs = jobList.getItems(); return job != null;
result = jobs.stream()
.filter(job -> job.getMetadata().getName().equals(jobName))
.findFirst();
return result.isPresent();
} catch (Exception e) { } catch (Exception e) {
throw new TaskException("fail to check job: ", e); throw new TaskException("fail to check job: ", e);
} }

Loading…
Cancel
Save