{"record":{"id":"ed40e9a9da8d5ed3","repo":"apache/dolphinscheduler","slug":"execute-k8s-task-error","errorCode":null,"errorMessage":"Execute k8s task error","messagePattern":"Execute k8s task error","errorType":"exception","errorClass":"TaskException","httpStatus":null,"severity":"critical","filePath":"dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/k8s/AbstractK8sTask.java","lineNumber":60,"sourceCode":"     */\n    protected AbstractK8sTask(TaskExecutionContext taskRequest) {\n        super(taskRequest);\n        this.abstractK8sTaskExecutor = new K8sTaskExecutor(taskRequest);\n    }\n\n    // todo split handle to submit and track\n    @Override\n    public void handle(TaskCallBack taskCallBack) throws TaskException {\n        try {\n            TaskResponse response = abstractK8sTaskExecutor.run(buildCommand());\n            setExitStatusCode(response.getExitStatusCode());\n            setAppIds(response.getAppIds());\n            dealOutParam(abstractK8sTaskExecutor.getTaskOutputParams());\n            taskRequest.setVarPool(getParameters().getVarPool());\n        } catch (Exception e) {\n            log.error(\"k8s task submit failed with error\");\n            exitStatusCode = -1;\n            throw new TaskException(\"Execute k8s task error\", e);\n        }\n    }\n\n    // todo\n    @Override\n    public void submitApplication() throws TaskException {\n\n    }\n\n    // todo\n    @Override\n    public void trackApplicationStatus() throws TaskException {\n\n    }\n\n    /**\n     * cancel application\n     *","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/k8s/AbstractK8sTask.java#L42-L78","documentation":"AbstractK8sTask.handle() wraps any exception raised while submitting or tracking a Kubernetes task (submitApplication/run/waitTimeout/cancel or output-param processing) into a TaskException(\"Execute k8s task error\", e), after setting exitStatusCode = -1 so the task instance is marked failed. The message is generic; the root cause is in the wrapped cause.","triggerScenarios":"Any exception in the submit flow: K8sTaskExecutor.run() failing (YAML parse error, job submission failure, timeout from waitTimeout), getTaskOutputParams() failing, or dealOutParam/setVarPool throwing.","commonSituations":"Unreachable or misconfigured Kubernetes cluster (bad kubeconfig/context); invalid command/args YAML in task params; job image missing or pull errors; task timeout exceeded; RBAC denying job creation in the namespace.","solutions":["Inspect the caused-by chain in the logs (k8s task submit failed with error) to find the root exception.","Verify cluster connectivity and credentials (kubeconfig, API server reachable from the worker).","Validate the task's commands/args YAML and container image settings in the task definition.","Check task timeout configuration and increase it if waitTimeout caused the failure.","Fix the underlying cause, then rerun the task; exitStatusCode -1 marks the instance failed and it can be re-run."],"exampleFix":"// before (opaque)\nthrow new TaskException(\"Execute k8s task error\", e);\n// after (actionable)\nlog.error(\"k8s task submit failed\", e);\nthrow new TaskException(\"Execute k8s task error: \" + e.getMessage(), e);","handlingStrategy":"try-catch","validationCode":"if (StringUtils.isBlank(k8sTaskParams.getCommand()) || clusterUnreachable()) {\n    throw new TaskException(\"Pre-flight check failed before k8s submit\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    taskExecutionContext = abstractK8sTaskExecutor.run(parameter);\n} catch (TaskException e) {\n    log.error(\"K8s task failed: {}\", e.getCause() != null ? e.getCause().getMessage() : e.getMessage(), e);\n    exitStatusCode = -1;\n    throw e;\n}","preventionTips":["Always inspect getCause() — the top-level message is generic.","Pre-validate the cluster connection and task YAML before submit.","Set realistic task timeouts and monitor pod events for Pending/CrashLoopBackOff.","Grant the worker's service account the RBAC roles needed to create jobs."],"tags":["kubernetes","task-execution","wrapper-exception"],"backgroundTag":"k8s-job-submission-failed","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}