|
@@ -5,6 +5,7 @@ import io.kubernetes.client.openapi.ApiClient;
|
|
import io.kubernetes.client.openapi.ApiException;
|
|
import io.kubernetes.client.openapi.ApiException;
|
|
import io.kubernetes.client.openapi.apis.BatchV1Api;
|
|
import io.kubernetes.client.openapi.apis.BatchV1Api;
|
|
import io.kubernetes.client.openapi.apis.CoreV1Api;
|
|
import io.kubernetes.client.openapi.apis.CoreV1Api;
|
|
|
|
+import io.kubernetes.client.openapi.models.V1JobList;
|
|
import io.kubernetes.client.openapi.models.V1Namespace;
|
|
import io.kubernetes.client.openapi.models.V1Namespace;
|
|
import io.kubernetes.client.openapi.models.V1ObjectMeta;
|
|
import io.kubernetes.client.openapi.models.V1ObjectMeta;
|
|
import io.kubernetes.client.openapi.models.V1PodList;
|
|
import io.kubernetes.client.openapi.models.V1PodList;
|
|
@@ -100,8 +101,59 @@ public class KubernetesUtil {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- public static void deleteJob(ApiClient apiClient, String namespaceName, String jobName) throws ApiException {
|
|
|
|
|
|
+ public static List<String> getJob(ApiClient apiClient, String namespaceName) throws ApiException {
|
|
BatchV1Api batchV1Api = new BatchV1Api(apiClient);
|
|
BatchV1Api batchV1Api = new BatchV1Api(apiClient);
|
|
- batchV1Api.deleteNamespacedJob(jobName, namespaceName, null, null, null, null, null, null);
|
|
|
|
|
|
+ V1JobList v1JobList;
|
|
|
|
+ if (namespaceName == null || "".equals(namespaceName) || "default".equals(namespaceName)) {
|
|
|
|
+ v1JobList = batchV1Api.listNamespacedJob(
|
|
|
|
+ "default",
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ null);
|
|
|
|
+ } else if ("all".equals(namespaceName)) {
|
|
|
|
+ v1JobList = batchV1Api.listJobForAllNamespaces(
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ null);
|
|
|
|
+ } else {
|
|
|
|
+ v1JobList = batchV1Api.listNamespacedJob(
|
|
|
|
+ namespaceName,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ null,
|
|
|
|
+ null);
|
|
|
|
+ }
|
|
|
|
+ return v1JobList.getItems().stream().map(pod -> Objects.requireNonNull(pod.getMetadata()).getName()).collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void deleteJob(ApiClient apiClient, String namespaceName, String jobNameToDelete) throws ApiException {
|
|
|
|
+ List<String> runningJobNameList = getJob(apiClient, namespaceName);
|
|
|
|
+ for (String runningJobName : runningJobNameList) {
|
|
|
|
+ if (jobNameToDelete.equals(runningJobName)) {
|
|
|
|
+ BatchV1Api batchV1Api = new BatchV1Api(apiClient);
|
|
|
|
+ batchV1Api.deleteNamespacedJob(jobNameToDelete, namespaceName, null, null, null, null, null, null);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|