{"record":{"id":"03a83516a32aab69","repo":"go-kratos/kratos","slug":"kubernetes-configmap-delete-s","errorCode":null,"errorMessage":"kubernetes configmap delete %s","messagePattern":"kubernetes configmap delete (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"contrib/config/kubernetes/watcher.go","lineNumber":53,"sourceCode":"\tch := <-w.watcher.ResultChan()\n\tif ch.Object == nil {\n\t\t// recreate the watcher\n\t\tk8sWatcher, err := w.k.client.CoreV1().ConfigMaps(w.k.opts.Namespace).Watch(context.Background(), metav1.ListOptions{\n\t\t\tLabelSelector: w.k.opts.LabelSelector,\n\t\t\tFieldSelector: w.k.opts.FieldSelector,\n\t\t})\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tw.watcher = k8sWatcher\n\t\tgoto ResultChan\n\t}\n\tcm, ok := ch.Object.(*v1.ConfigMap)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"kubernetes Object not ConfigMap\")\n\t}\n\tif ch.Type == \"DELETED\" {\n\t\treturn nil, fmt.Errorf(\"kubernetes configmap delete %s\", cm.Name)\n\t}\n\treturn w.k.configMap(*cm), nil\n}\n\nfunc (w *watcher) Stop() error {\n\tw.watcher.Stop()\n\treturn nil\n}\n","sourceCodeStart":35,"sourceCodeEnd":62,"githubUrl":"https://github.com/go-kratos/kratos/blob/668db92c2c001e9552594ba5a8aede8456af6d7e/contrib/config/kubernetes/watcher.go#L35-L62","documentation":"Reported when the watched ConfigMap receives a DELETED event: the watcher turns the deletion into an error ('kubernetes configmap delete <name>') to signal that the config source vanished. Deletion usually comes from kubectl, Helm pruning, or garbage collection while the app runs.","triggerScenarios":"The ConfigMap being watched is deleted (kubectl delete, helm upgrade pruning, namespace teardown, GC) so the watch loop receives an event with Type == DELETED.","commonSituations":"Ops cleanup during debugging; helm upgrade removing unannotated maps; CI scripts deleting and recreating maps with a gap; namespace teardown while apps still run.","solutions":["Recreate the ConfigMap with the same name (kubectl apply) — events resume once it exists again","Use a create-before-delete or apply-over strategy to avoid a no-config window","Treat the error as a signal: keep last-known config values, alert, and wait for re-creation instead of crashing"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-check the ConfigMap exists before starting the app\n_, err := k8scli.CoreV1().ConfigMaps(ns).Get(ctx, name, metav1.GetOptions{})\nif err != nil {\n    return fmt.Errorf(\"configmap %s missing: %w\", name, err)\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n    if strings.HasPrefix(err.Error(), \"kubernetes configmap delete\") {\n        // config removed: keep last-known values, alert, wait for re-create\n        alertConfigDeleted()\n        return nil\n    }\n    return err\n}","preventionTips":["Recreate ConfigMaps with kubectl apply, never delete-then-new with a gap","Use labels plus ownerReferences so Helm/GC does not prune config","Alert on deletion events instead of crashing"],"tags":["kubernetes","config","watch","lifecycle","deletion"],"backgroundTag":null,"analyzedSha":"668db92c2c001e9552594ba5a8aede8456af6d7e","analyzedAt":"2026-08-16T02:07:20.704Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}