{"record":{"id":"26b71adc571f79a8","repo":"argoproj/argo-workflows","slug":"unable-to-convert-object-s-to-configmap-when-sync","errorCode":null,"errorMessage":"unable to convert object %s to configmap when syncing ConfigMaps","messagePattern":"unable to convert object (.+?) to configmap when syncing ConfigMaps","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"workflow/common/configmap.go","lineNumber":24,"sourceCode":"\tapiv1 \"k8s.io/api/core/v1\"\n\n\t\"github.com/argoproj/argo-workflows/v4/errors\"\n)\n\ntype ConfigMapStore interface {\n\tGetByKey(key string) (any, bool, error)\n}\n\n// GetConfigMapValue retrieves a configmap value\nfunc GetConfigMapValue(configMapStore ConfigMapStore, namespace, name, key string) (string, error) {\n\tobj, exists, err := configMapStore.GetByKey(namespace + \"/\" + name)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tif exists {\n\t\tcm, ok := obj.(*apiv1.ConfigMap)\n\t\tif !ok {\n\t\t\treturn \"\", fmt.Errorf(\"unable to convert object %s to configmap when syncing ConfigMaps\", name)\n\t\t}\n\t\tif cmType := cm.Labels[LabelKeyConfigMapType]; cmType != LabelValueTypeConfigMapParameter {\n\t\t\treturn \"\", fmt.Errorf(\n\t\t\t\t\"ConfigMap '%s' needs to have the label %s: %s to load parameters\",\n\t\t\t\tname, LabelKeyConfigMapType, LabelValueTypeConfigMapParameter)\n\t\t}\n\t\tcmValue, ok := cm.Data[key]\n\t\tif !ok {\n\t\t\treturn \"\", errors.Errorf(errors.CodeNotFound, \"ConfigMap '%s' does not have the key '%s'\", name, key)\n\t\t}\n\t\treturn cmValue, nil\n\t}\n\treturn \"\", errors.Errorf(errors.CodeNotFound, \"ConfigMap '%s' does not exist. Please make sure it has the label %s: %s to be detectable by the controller\",\n\t\tname, LabelKeyConfigMapType, LabelValueTypeConfigMapParameter)\n}\n","sourceCodeStart":6,"sourceCodeEnd":40,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/workflow/common/configmap.go#L6-L40","documentation":"GetConfigMapValue fetches a ConfigMap via the Kubernetes API and asserts the returned object is actually a *apiv1.ConfigMap. Since the List/Get was filtered by name this should always be a ConfigMap; failure indicates a client/typing mismatch (e.g. wrong scheme, mocked client, or object of another kind with the same name).","triggerScenarios":"The k8s object returned by the client for the given name/namespace fails the *apiv1.ConfigMap type assertion — typically when using an offline/mocked client or a client configured against a nonstandard scheme.","commonSituations":"Unit tests injecting foreign objects into a fake clientset; CRD or other object shadowing the ConfigMap name; client-go scheme not registering corev1 properly in custom transports.","solutions":["Verify the object with that name in that namespace is truly a ConfigMap (kubectl get cm &lt;name&gt; -n &lt;ns&gt;)","If in tests, ensure the fake client only returns *apiv1.ConfigMap objects for GetConfigMapValue paths","Recreate the object with 'kubectl create configmap' if it is some other kind","Check client construction (scheme/RESTMapper) if using a custom or offline apiclient"],"exampleFix":"// before (test)\nfakeClient.PrependReactor(\"get\", \"configmaps\", func(...) { return &appsv1.Deployment{}, nil })\n// after\nfakeClient.PrependReactor(\"get\", \"configmaps\", func(...) { return &corev1.ConfigMap{ObjectMeta: ...}, nil })","handlingStrategy":"type-guard","validationCode":"obj, err := client.CoreV1().ConfigMaps(ns).Get(ctx, name, metav1.GetOptions{})\n// typed Get already guarantees *apiv1.ConfigMap; avoid untyped dynamic client here","typeGuard":"func asConfigMap(obj runtime.Object) (*corev1.ConfigMap, bool) {\n  cm, ok := obj.(*corev1.ConfigMap)\n  return cm, ok\n}","tryCatchPattern":"cm, err := GetConfigMapValue(...)\nif err != nil && strings.Contains(err.Error(), \"unable to convert object\") {\n  log.Printf(\"object %s is not a ConfigMap; check kind and client scheme\", name)\n}","preventionTips":["Use the typed CoreV1 client for ConfigMap lookups instead of untyped interfaces","Ensure fake clients in tests return the correct kind","Verify object kind with kubectl get -o jsonpath='{.kind}' before programmatic use"],"tags":["kubernetes","configmap","type-assertion","parameters"],"backgroundTag":"configmap-type-mismatch","analyzedSha":"35bff19146f5a6ada77468c431f2624bd577e373","analyzedAt":"2026-09-03T19:34:35.908Z","contentChangedAt":"2026-09-03T19:34:35.908Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}