{"record":{"id":"d655eae0ac00db9a","repo":"zhisheng17/flink-learning","slug":"error-to-parse-kubernetesworkernode-from-resourc","errorCode":null,"errorMessage":"Error to parse KubernetesWorkerNode from ${resourceID}.","messagePattern":"Error to parse KubernetesWorkerNode from (.+?)\\.","errorType":"exception","errorClass":"ResourceManagerException","httpStatus":null,"severity":"error","filePath":"flink-learning-k8s/flink-k8s/src/main/java/org/apache/flink/kubernetes/KubernetesWorkerNode.java","lineNumber":55,"sourceCode":"\t * This pattern should be updated when {@link KubernetesResourceManagerDriver#TASK_MANAGER_POD_FORMAT} changed.\n\t */\n\tprivate static final Pattern TASK_MANAGER_POD_PATTERN = Pattern.compile(\"\\\\S+-taskmanager-([\\\\d]+)-([\\\\d]+)\");\n\n\tKubernetesWorkerNode(ResourceID resourceID) {\n\t\tthis.resourceID = checkNotNull(resourceID);\n\t}\n\n\t@Override\n\tpublic ResourceID getResourceID() {\n\t\treturn resourceID;\n\t}\n\n\tpublic long getAttempt() throws ResourceManagerException {\n\t\tMatcher matcher = TASK_MANAGER_POD_PATTERN.matcher(resourceID.toString());\n\t\tif (matcher.find()) {\n\t\t\treturn Long.parseLong(matcher.group(1));\n\t\t} else {\n\t\t\tthrow new ResourceManagerException(\"Error to parse KubernetesWorkerNode from \" + resourceID + \".\");\n\t\t}\n\t}\n}\n","sourceCodeStart":37,"sourceCodeEnd":59,"githubUrl":"https://github.com/zhisheng17/flink-learning/blob/d731cee7618021be56d132cc925102ffff8d75e6/flink-learning-k8s/flink-k8s/src/main/java/org/apache/flink/kubernetes/KubernetesWorkerNode.java#L37-L59","documentation":"KubernetesWorkerNode.getAttempt parses the attempt number from a TaskManager pod name matching the pattern \\S+-taskmanager-([\\d]+)-([\\d]+). If the ResourceID does not match the expected TaskManager pod naming scheme, a ResourceManagerException is thrown.","triggerScenarios":"Calling getAttempt (used by attempt()) with a ResourceID whose string does not end with '<something>-taskmanager-<num>-<num>' — e.g. a manually built ResourceID, a renamed pod, or an ID produced by a different TASK_MANAGER_POD_FORMAT.","commonSituations":"Custom pod name templates configured via KubernetesResourceManagerDriver pod format changed without updating the parser; pods created outside the driver (hand-spun TaskManagers); mixing worker IDs from another resource manager (YARN) into Kubernetes code; attempting-based recovery enabled with mismatched naming.","solutions":["Ensure TaskManager pods are created by the KubernetesResourceManagerDriver so names follow the taskmanager-<attempt>-<index> format.","If you changed kubernetes.taskmanager.pod naming/prefix, revert it or update TASK_MANAGER_POD_PATTERN to match (the code comments require keeping them in sync).","Log/inspect resourceID.toString() to see the offending value and compare it against the expected pattern.","Do not pass hand-crafted ResourceIDs to KubernetesWorkerNode; construct via KubernetesResourceManagerDriver's worker creation path."],"exampleFix":"// before: arbitrary resource id\nnew KubernetesWorkerNode(ResourceID.generate()).getAttempt(); // throws\n// after: id derived from an actual TM pod name\nString podName = \"flink-cluster-taskmanager-3-1\";\nnew KubernetesWorkerNode(new ResourceID(podName)).getAttempt(); // 3","handlingStrategy":"validation","validationCode":"private static final Pattern TM = Pattern.compile(\"\\\\S+-taskmanager-([\\\\d]+)-([\\\\d]+)\");\nboolean isParseableKubernetesWorker(ResourceID id) { return TM.matcher(id.toString()).find(); }","typeGuard":"boolean isTaskManagerPodName(ResourceID id) {\n    return id != null && Pattern.compile(\"\\\\S+-taskmanager-([\\\\d]+)-([\\\\d]+)\").matcher(id.toString()).find();\n}","tryCatchPattern":"try {\n    long attempt = workerNode.getAttempt();\n} catch (ResourceManagerException e) {\n    LOG.warn(\"Non-standard worker id: {}\", e.getMessage());\n}","preventionTips":["Only construct KubernetesWorkerNode from driver-created pod names","Keep TASK_MANAGER_POD_PATTERN in sync with any pod-name-format change","Log resourceID before parsing for diagnostics","Don't mix worker IDs from other resource managers"],"tags":["kubernetes","flink","resourcemanager","pod-name-parsing"],"backgroundTag":"invalid-identifier-format","analyzedSha":"d731cee7618021be56d132cc925102ffff8d75e6","analyzedAt":"2026-09-06T05:35:08.496Z","contentChangedAt":"2026-09-06T05:35:08.496Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}