{"record":{"id":"c9084c95f825ad7e","repo":"apache/dolphinscheduler","slug":"fail-to-check-job","errorCode":null,"errorMessage":"fail to check job: ","messagePattern":"fail to check 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":70,"sourceCode":"    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)\n                    .watch(watcher);\n        } catch (Exception e) {\n            throw new TaskException(\"fail to register batch job watcher\", e);\n        }\n    }\n\n    public String getPodLog(String jobName, String namespace) {\n        try {\n            List<Pod> podList = client.pods().inNamespace(namespace).list().getItems();","sourceCodeStart":52,"sourceCodeEnd":88,"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#L52-L88","documentation":"K8sUtils.jobExist() performs a GET on a Batch/V1 Job and wraps any client exception in a TaskException 'fail to check job: ' (note the message has a trailing space and does not append the job name). It signals the existence-check itself failed — not that the job is missing (a missing job returns false).","triggerScenarios":"Calling jobExist(jobName, namespace) when the GET request errors: API server unreachable, invalid kubeconfig/client not built, or RBAC denies 'get' on batch/jobs.","commonSituations":"Worker's K8s client never initialized via buildClient() (null/blank config); network outage to API server; service account without read access to jobs; checking a job in a namespace the account cannot see.","solutions":["Inspect the wrapped cause in logs to distinguish connectivity vs RBAC errors.","Ensure buildClient(configYaml) succeeded before calling jobExist.","Test access with kubectl auth can-i get jobs -n <namespace> using the same credentials.","Confirm the namespace name is correct and active."],"exampleFix":"// before\nBoolean exists = k8sUtils.jobExist(jobName, namespace); // may throw\n// after\nk8sUtils.buildClient(kubeconfigYaml); // build/validate client first\nBoolean exists = k8sUtils.jobExist(jobName, namespace);","handlingStrategy":"try-catch","validationCode":"Objects.requireNonNull(jobName, \"jobName required\");\nObjects.requireNonNull(namespace, \"namespace required\");\nk8sUtils.buildClient(configYaml); // ensure client is initialized","typeGuard":"boolean clientReady(K8sUtils k) {\n    return k != null; // plus internal client != null per buildClient success\n}","tryCatchPattern":"try {\n    exists = k8sUtils.jobExist(jobName, namespace);\n} catch (TaskException e) {\n    log.error(\"existence check failed for job {} in ns {}\", jobName, namespace, e);\n    throw e;\n}","preventionTips":["Always call buildClient() successfully before any K8sUtils query.","Verify read permissions (get on batch/jobs) for the worker's service account.","Distinguish 'not found' (returns false) from 'check failed' (throws) in your logic."],"tags":["kubernetes","job-existence","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"}