{"record":{"id":"c5f01ca440d3bea7","repo":"go-kratos/kratos","slug":"kubernetes-object-not-configmap","errorCode":null,"errorMessage":"kubernetes Object not ConfigMap","messagePattern":"kubernetes Object not ConfigMap","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"contrib/config/kubernetes/watcher.go","lineNumber":50,"sourceCode":"\nfunc (w *watcher) Next() ([]*config.KeyValue, error) {\nResultChan:\n\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":32,"sourceCodeEnd":62,"githubUrl":"https://github.com/go-kratos/kratos/blob/668db92c2c001e9552594ba5a8aede8456af6d7e/contrib/config/kubernetes/watcher.go#L32-L62","documentation":"The contrib/config Kubernetes watcher consumes watch events and asserts each event object is *v1.ConfigMap; an event carrying any other runtime.Object (nil object on an error event, or an object of another kind) fails the assertion. It indicates unexpected watch payloads rather than a configuration mistake.","triggerScenarios":"The k8s watch delivers an event whose ch.Object is not *v1.ConfigMap — typically a nil object or a different kind — failing the type assertion in the watcher's polling loop.","commonSituations":"client-go version skew with the API server; RBAC returning degraded objects; custom setups reusing or wrapping the source's watcher.","solutions":["Verify the watcher is created via CoreV1().ConfigMaps(...).Watch and RBAC grants exactly that","Align client-go/kubernetes versions with your API server","Treat malformed events as skippable: log and continue instead of aborting the config watch loop"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func isConfigMap(obj runtime.Object) bool {\n    _, ok := obj.(*v1.ConfigMap)\n    return ok\n}","tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"not ConfigMap\") {\n        // malformed watch payload: skip and keep watching\n        log.Warn(\"skipped malformed kubernetes watch event\")\n        continue\n    }\n    return err\n}","preventionTips":["Pin client-go/kubernetes versions to your API server","Scope RBAC to configmaps get/list/watch only","Do not reuse or wrap watchers across sources"],"tags":["kubernetes","config","watch","type-assertion","go"],"backgroundTag":null,"analyzedSha":"668db92c2c001e9552594ba5a8aede8456af6d7e","analyzedAt":"2026-08-16T02:07:20.704Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}