go-kratos/kratos · error

kubernetes Object not ConfigMap

Error message

kubernetes Object not ConfigMap

What it means

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.

Source

Thrown at contrib/config/kubernetes/watcher.go:50

func (w *watcher) Next() ([]*config.KeyValue, error) {
ResultChan:
	ch := <-w.watcher.ResultChan()
	if ch.Object == nil {
		// recreate the watcher
		k8sWatcher, err := w.k.client.CoreV1().ConfigMaps(w.k.opts.Namespace).Watch(context.Background(), metav1.ListOptions{
			LabelSelector: w.k.opts.LabelSelector,
			FieldSelector: w.k.opts.FieldSelector,
		})
		if err != nil {
			return nil, err
		}
		w.watcher = k8sWatcher
		goto ResultChan
	}
	cm, ok := ch.Object.(*v1.ConfigMap)
	if !ok {
		return nil, fmt.Errorf("kubernetes Object not ConfigMap")
	}
	if ch.Type == "DELETED" {
		return nil, fmt.Errorf("kubernetes configmap delete %s", cm.Name)
	}
	return w.k.configMap(*cm), nil
}

func (w *watcher) Stop() error {
	w.watcher.Stop()
	return nil
}

View on GitHub (pinned to 668db92c2c)

Solutions

  1. Verify the watcher is created via CoreV1().ConfigMaps(...).Watch and RBAC grants exactly that
  2. Align client-go/kubernetes versions with your API server
  3. Treat malformed events as skippable: log and continue instead of aborting the config watch loop
Defensive patterns

Strategy: try-catch

Type guard

func isConfigMap(obj runtime.Object) bool {
    _, ok := obj.(*v1.ConfigMap)
    return ok
}

Try / catch

if err != nil {
    if strings.Contains(err.Error(), "not ConfigMap") {
        // malformed watch payload: skip and keep watching
        log.Warn("skipped malformed kubernetes watch event")
        continue
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: client-go version skew with the API server; RBAC returning degraded objects; custom setups reusing or wrapping the source's watcher.

Related errors


AI-assisted analysis of go-kratos/kratos@668db92c2c (2026-08-16). Data as JSON: /api/errors/c5f01ca440d3bea7. Report an issue: GitHub.