{"record":{"id":"2f41af37c364fb51","repo":"zhisheng17/flink-learning","slug":"failed-to-create-configmap","errorCode":null,"errorMessage":"Failed to create ConfigMap {}","messagePattern":"Failed to create ConfigMap (.+?)","errorType":"exception","errorClass":"KubernetesException","httpStatus":null,"severity":"error","filePath":"flink-learning-k8s/flink-k8s/src/main/java/org/apache/flink/kubernetes/kubeclient/Fabric8FlinkKubeClient.java","lineNumber":263,"sourceCode":"\tpublic KubernetesLeaderElector createLeaderElector(\n\t\t\tKubernetesLeaderElectionConfiguration leaderElectionConfiguration,\n\t\t\tKubernetesLeaderElector.LeaderCallbackHandler leaderCallbackHandler) {\n\t\treturn new KubernetesLeaderElector(\n\t\t\t(NamespacedKubernetesClient) this.internalClient,\n\t\t\tnamespace,\n\t\t\tleaderElectionConfiguration,\n\t\t\tleaderCallbackHandler);\n\t}\n\n\t@Override\n\tpublic CompletableFuture<Void> createConfigMap(KubernetesConfigMap configMap) {\n\t\tfinal String configMapName = configMap.getName();\n\t\treturn CompletableFuture.runAsync(\n\t\t\t() -> this.internalClient.configMaps().inNamespace(namespace).create(configMap.getInternalResource()),\n\t\t\tkubeClientExecutorService)\n\t\t\t.exceptionally(\n\t\t\t\tthrowable -> {\n\t\t\t\t\tthrow new CompletionException(\n\t\t\t\t\t\tnew KubernetesException(\"Failed to create ConfigMap \" + configMapName, throwable));\n\t\t\t\t});\n\t}\n\n\t@Override\n\tpublic Optional<KubernetesConfigMap> getConfigMap(String name) {\n\t\tfinal ConfigMap configMap = this.internalClient.configMaps().inNamespace(namespace).withName(name).get();\n\t\treturn configMap == null ? Optional.empty() : Optional.of(new KubernetesConfigMap(configMap));\n\t}\n\n\t@Override\n\tpublic CompletableFuture<Boolean> checkAndUpdateConfigMap(\n\t\t\tString configMapName,\n\t\t\tFunction<KubernetesConfigMap, Optional<KubernetesConfigMap>> function) {\n\t\treturn FutureUtils.retry(\n\t\t\t() -> CompletableFuture.supplyAsync(\n\t\t\t\t() -> getConfigMap(configMapName)\n\t\t\t\t\t.map(","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/zhisheng17/flink-learning/blob/d731cee7618021be56d132cc925102ffff8d75e6/flink-learning-k8s/flink-k8s/src/main/java/org/apache/flink/kubernetes/kubeclient/Fabric8FlinkKubeClient.java#L245-L281","documentation":"createConfigMap() runs the fabric8 ConfigMap create asynchronously and maps any throwable into this CompletionException(KubernetesException) with the ConfigMap name. The Kubernetes API rejected or failed the create call.","triggerScenarios":"createConfigMap called with a ConfigMap that already exists in the namespace (409 AlreadyExists), or the API server is unreachable, times out, or RBAC denies create on configmaps.","commonSituations":"Re-submitting a job/application after a previous run left the HA ConfigMap behind; limited service-account RBAC in restricted namespaces; API server outages or etcd quota exceeded ('resourceQuota exceeded' errors).","solutions":["Check if the ConfigMap already exists (getConfigMap(name)) and reuse/delete it before creating.","Check RBAC: the Flink service account needs create on configmaps in the namespace.","Inspect the wrapped cause for 403/409/timeout and address accordingly.","If etcd/quota limits hit, free resources or raise namespace quotas."],"exampleFix":"// before: fails on re-submission with leftover configmap\nclient.createConfigMap(configMap).get();\n// after: delete stale configmap first\nclient.getConfigMap(configMap.getName())\n    .ifPresent(cm -> client.deleteConfigMap(configMap.getName()).join());\nclient.createConfigMap(configMap).get();","handlingStrategy":"try-catch","validationCode":"// create only if absent\nif (kubeClient.getConfigMap(name).isPresent()) {\n    return; // or delete first, then create\n}","typeGuard":null,"tryCatchPattern":"try {\n    client.createConfigMap(cm).get();\n} catch (CompletionException e) {\n    Throwable c = e.getCause();\n    if (c instanceof KubernetesException && c.getMessage().contains(\"AlreadyExists\")) {\n        // idempotent: configmap already provisioned\n    } else {\n        throw e;\n    }\n}","preventionTips":["Make ConfigMap creation idempotent (get-or-create).","Grant create permission on configmaps to the Flink SA.","Clean stale HA ConfigMaps between job submissions.","Watch namespace resource quotas and etcd limits."],"tags":["kubernetes","configmap","kubeclient","async"],"backgroundTag":"api-request-failed","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"}