{"record":{"id":"084bfcdc9184e9b6","repo":"GoogleContainerTools/skaffold","slug":"getting-group-version-resource-from-obj-w","errorCode":null,"errorMessage":"getting group version resource from obj: %w","messagePattern":"getting group version resource from obj: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/deploy/label/labels.go","lineNumber":103,"sourceCode":"}\n\nfunc updateRuntimeObject(ctx context.Context, client dynamic.Interface, disco discovery.DiscoveryInterface, labels map[string]string, res deploy.Artifact, kubeContext string) error {\n\toriginalJSON, _ := json.Marshal(res.Obj)\n\tmodifiedObj := res.Obj.DeepCopyObject()\n\taccessor, err := meta.Accessor(modifiedObj)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"getting metadata accessor: %w\", err)\n\t}\n\tname := accessor.GetName()\n\n\taddLabels(labels, accessor)\n\n\tmodifiedJSON, _ := json.Marshal(modifiedObj)\n\tp, _ := patch.CreateTwoWayMergePatch(originalJSON, modifiedJSON, modifiedObj)\n\n\tnamespaced, gvr, err := util.GroupVersionResource(disco, modifiedObj.GetObjectKind().GroupVersionKind())\n\tif err != nil {\n\t\treturn fmt.Errorf(\"getting group version resource from obj: %w\", err)\n\t}\n\n\tif namespaced {\n\t\tvar namespace string\n\t\tif accessor.GetNamespace() != \"\" {\n\t\t\tnamespace = accessor.GetNamespace()\n\t\t} else {\n\t\t\tnamespace = res.Namespace\n\t\t}\n\n\t\tns, err := resolveNamespace(namespace, kubeContext)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"resolving namespace: %w\", err)\n\t\t}\n\n\t\tlog.Entry(ctx).Debug(\"Patching\", name, \"in namespace\", ns)\n\t\tif _, err := client.Resource(gvr).Namespace(ns).Patch(ctx, name, types.StrategicMergePatchType, p, metav1.PatchOptions{}); err != nil {\n\t\t\treturn fmt.Errorf(\"patching resource %s/%q: %w\", ns, name, err)","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/deploy/label/labels.go#L85-L121","documentation":"updateRuntimeObject resolves the GroupVersionResource from the object's GroupVersionKind using the discovery API (util.GroupVersionResource performs a RESTMapping lookup). This error means discovery could not map the GVK to a resource — the API server does not serve that kind, or discovery itself failed.","triggerScenarios":"Patching an object whose GVK is not registered on the target cluster (missing CRD); the discovery client cannot reach the API server; an unsupported/typo'd apiVersion in the manifest.","commonSituations":"Deploying CRs before their CRDs are installed; wrong apiVersion string after a Kubernetes API migration (e.g. extensions/v1beta1 to apps/v1); cluster unreachable so discovery returns no resources.","solutions":["Install the CRD for the custom kind before deploying: `kubectl apply -f crd.yaml`","Fix the apiVersion/kind in the manifest to match a resource served by the cluster (`kubectl api-resources | grep <kind>`)","Verify cluster connectivity with `kubectl version` — discovery requires a reachable API server","Run `kubectl explain <resource>` to confirm the correct group/version"],"exampleFix":"// before\napiVersion: extensions/v1beta1\nkind: Deployment\n// after\napiVersion: apps/v1\nkind: Deployment","handlingStrategy":"validation","validationCode":"// verify the GVK is served before deploying\nres, err := disco.ServerResourcesForGroupVersion(gvk.GroupVersion().String())\nif err != nil || !containsKind(res.APIResources, gvk.Kind) {\n    return fmt.Errorf(\"kind %s not served in %s — install CRDs first\", gvk.Kind, gvk.GroupVersion())\n}","typeGuard":null,"tryCatchPattern":"_, gvr, err := util.GroupVersionResource(disco, gvk)\nif err != nil {\n    return fmt.Errorf(\"no RESTMapping for %s — is its CRD installed? %w\", gvk, err)\n}","preventionTips":["Apply CRDs before custom resources (skaffold does this, but check ordering with external tools)","Run kubectl api-resources to confirm served kinds","Migrate manifests off removed apiVersions (extensions/v1beta1 etc.)","Check connectivity — discovery needs a live API server"],"tags":["kubernetes","discovery","restmapping","crd"],"backgroundTag":"no-matches-for-kind","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}