{"record":{"id":"c7f53ae5cb4cbb7d","repo":"zhisheng17/flink-learning","slug":"configmap-configmapname-does-not-exists-it-may","errorCode":null,"errorMessage":"ConfigMap {configMapName} does not exists. It may be deleted externally.","messagePattern":"ConfigMap (.+?) does not exists\\. It may be deleted externally\\.","errorType":"exception","errorClass":"KubernetesException","httpStatus":null,"severity":"error","filePath":"flink-learning-k8s/flink-k8s/src/main/java/org/apache/flink/kubernetes/highavailability/KubernetesStateHandleStore.java","lineNumber":243,"sourceCode":"\t *\n\t * @throws IOException if the method failed to deserialize the stored state handle\n\t * @throws NotExistException when the name does not exist\n\t * @throws Exception if get state handle from ConfigMap failed\n\t */\n\t@Override\n\tpublic RetrievableStateHandle<T> getAndLock(String key) throws Exception {\n\t\tcheckNotNull(key, \"Key in ConfigMap.\");\n\n\t\tfinal Optional<KubernetesConfigMap> optional = kubeClient.getConfigMap(configMapName);\n\t\tif (optional.isPresent()) {\n\t\t\tfinal KubernetesConfigMap configMap = optional.get();\n\t\t\tif (configMap.getData().containsKey(key)) {\n\t\t\t\treturn deserializeObject(configMap.getData().get(key));\n\t\t\t} else {\n\t\t\t\tthrow getKeyNotExistException(key);\n\t\t\t}\n\t\t} else {\n\t\t\tthrow getConfigMapNotExistException();\n\t\t}\n\t}\n\n\t/**\n\t * Gets all available state handles from Kubernetes.\n\t *\n\t * @return All state handles from ConfigMap.\n\t */\n\t@Override\n\tpublic List<Tuple2<RetrievableStateHandle<T>, String>> getAllAndLock() {\n\n\t\treturn kubeClient.getConfigMap(configMapName)\n\t\t\t.map(\n\t\t\t\tconfigMap -> {\n\t\t\t\t\tfinal List<Tuple2<RetrievableStateHandle<T>, String>> stateHandles = new ArrayList<>();\n\t\t\t\t\tconfigMap.getData().entrySet().stream()\n\t\t\t\t\t\t.filter(entry -> configMapKeyFilter.test(entry.getKey()))\n\t\t\t\t\t\t.forEach(entry -> {","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/zhisheng17/flink-learning/blob/d731cee7618021be56d132cc925102ffff8d75e6/flink-learning-k8s/flink-k8s/src/main/java/org/apache/flink/kubernetes/highavailability/KubernetesStateHandleStore.java#L225-L261","documentation":"KubernetesStateHandleStore.getAndLock throws getConfigMapNotExistException when kubeClient.getConfigMap(configMapName) returns empty, meaning the entire HA ConfigMap is gone — the message warns it may have been deleted externally. Flink's HA relies on this ConfigMap persisting job state handles; its absence breaks leader election/recovery assumptions. Callers get a distinct error from key-missing so they can react to total storage loss.","triggerScenarios":"Calling getAndLock(configMapName, key) where the Kubernetes API returns no ConfigMap for configMapName — it was never created, deleted manually/by a GC controller, or the client is pointed at the wrong namespace.","commonSituations":"Someone ran kubectl delete on HA ConfigMaps, a namespace-scoped cleanup job (or TTL controller) removed them, or the Flink configuration's namespace/cluster-id changed so the store looks in the wrong place.","solutions":["Confirm the ConfigMap exists in the expected namespace: kubectl -n <ns> get configmap <configMapName>","Check high-availability configuration (namespace, cluster-id) hasn't changed between savepoint and recovery","Recreate the ConfigMap from backup or restore HA metadata from an alternative storage backend","Investigate external deletion (TTL controllers, cleanup scripts, RBAC-restricted operators) and disable or reconfigure it"],"exampleFix":"// before\nkubectl delete configmap flink-cluster-ha --namespace flink\n// after\nkubectl -n flink get configmap flink-cluster-ha  # verify before any cleanup; exclude *-ha configmaps from TTL/cleanup policies","handlingStrategy":"try-catch","validationCode":"if (!kubeClient.getConfigMap(configMapName).isPresent()) {\n    LOG.error(\"HA ConfigMap {} missing — state handles unavailable\", configMapName);\n    return Optional.empty();\n}","typeGuard":null,"tryCatchPattern":"try {\n    return stateHandleStore.getAndLock(configMapName, key);\n} catch (Exception e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"does not exists\")) {\n        LOG.error(\"HA ConfigMap {} was deleted externally; manual restore required\", configMapName);\n    }\n    throw e;\n}","preventionTips":["Exclude Flink HA ConfigMaps from TTL controllers and cleanup scripts","Pin high-availability.namespace/cluster-id config so lookups never drift","Alert on ConfigMap deletion events in the Flink namespace"],"tags":["kubernetes","flink","high-availability","configmap"],"backgroundTag":"resource-not-found","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"}