{"record":{"id":"301502151903ce92","repo":"apache/dolphinscheduler","slug":"fail-to-delete-job","errorCode":null,"errorMessage":"fail to delete job","messagePattern":"fail to delete job","errorType":"exception","errorClass":"TaskException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/K8sUtils.java","lineNumber":61,"sourceCode":"                    .v1()\n                    .jobs()\n                    .inNamespace(namespace)\n                    .create(job);\n        } catch (Exception e) {\n            throw new TaskException(\"fail to create job\", e);\n        }\n    }\n\n    public void deleteJob(String jobName, String namespace) {\n        try {\n            client.batch()\n                    .v1()\n                    .jobs()\n                    .inNamespace(namespace)\n                    .withName(jobName)\n                    .delete();\n        } catch (Exception e) {\n            throw new TaskException(\"fail to delete job\", e);\n        }\n    }\n\n    public Boolean jobExist(String jobName, String namespace) {\n        try {\n            Job job = client.batch().v1().jobs().inNamespace(namespace).withName(jobName).get();\n            return job != null;\n        } catch (Exception e) {\n            throw new TaskException(\"fail to check job: \", e);\n        }\n    }\n\n    public Watch createBatchJobWatcher(String jobName, Watcher<Job> watcher) {\n        try {\n            return client.batch()\n                    .v1()\n                    .jobs()\n                    .withName(jobName)","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/K8sUtils.java#L43-L79","documentation":"K8sUtils.deleteJob() deletes a Batch/V1 Job by name in a namespace and wraps any client exception in a TaskException 'fail to delete job'. Any failure in the delete call — connectivity, RBAC, or API server errors — surfaces under this generic message.","triggerScenarios":"Calling deleteJob(jobName, namespace) when the API server rejects or cannot process the DELETE: unreachable cluster, no 'jobs delete' RBAC permission, invalid kubeconfig, or a finalizer conflict preventing deletion.","commonSituations":"Cleanup of a completed/failed K8s task job when the cluster was replaced or kubeconfig rotated; service account permissions narrowed; job stuck with finalizers; namespace already being terminated.","solutions":["Read the chained cause in worker logs for the actual Fabric8 KubernetesClientException.","Confirm cluster reachability and a valid kubeconfig on the worker node.","Check RBAC allows 'delete' on batch/jobs in the target namespace.","If the job is stuck, delete with propagation or clear finalizers via kubectl, then retry.","Verify the namespace is active (not Terminating) before deleting jobs."],"exampleFix":"// before\nk8sUtils.deleteJob(jobName, namespace); // throws on stuck job\n// after\ntry {\n    k8sUtils.deleteJob(jobName, namespace);\n} catch (TaskException e) {\n    log.warn(\"job cleanup failed, checking existence\", e);\n    if (Boolean.TRUE.equals(k8sUtils.jobExist(jobName, namespace))) {\n        throw e;\n    }\n}","handlingStrategy":"try-catch","validationCode":"if (!Boolean.TRUE.equals(k8sUtils.jobExist(jobName, namespace))) {\n    return; // nothing to delete\n}","typeGuard":"boolean canDeleteJobs(KubernetesClient client, String ns) {\n    return client != null && client.namespaces().withName(ns).get() != null;\n}","tryCatchPattern":"try {\n    k8sUtils.deleteJob(jobName, namespace);\n} catch (TaskException e) {\n    if (Boolean.TRUE.equals(k8sUtils.jobExist(jobName, namespace))) {\n        throw e; // still there, real failure\n    }\n    log.warn(\"delete errored but job is gone; treating as success\");\n}","preventionTips":["Make cleanup idempotent: treat 'job already gone' as success.","Check for finalizers on stuck jobs before retrying deletes.","Ensure the service account has the delete verb on batch/jobs."],"tags":["kubernetes","job-deletion","task-exception"],"backgroundTag":"http-error-response","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}