{"record":{"id":"ffb2449036be6511","repo":"kubernetes/kops","slug":"unknown-scope-for-gvk-s-q","errorCode":null,"errorMessage":"unknown scope for gvk %s: %q","messagePattern":"unknown scope for gvk (.+?): %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/applylib/applyset/unstructuredclient.go","lineNumber":75,"sourceCode":"\n\tswitch restMapping.Scope.Name() {\n\tcase meta.RESTScopeNameNamespace:\n\t\tif ns == \"\" {\n\t\t\t// TODO: Differentiate between server-fixable vs client-fixable errors?\n\t\t\treturn nil, fmt.Errorf(\"namespace was not provided for namespace-scoped object %v\", gvk)\n\t\t}\n\t\treturn c.client.Resource(gvr).Namespace(ns), nil\n\n\tcase meta.RESTScopeNameRoot:\n\t\tif ns != \"\" {\n\t\t\t// TODO: Differentiate between server-fixable vs client-fixable errors?\n\t\t\treturn nil, fmt.Errorf(\"namespace %q was provided for cluster-scoped object %v\", ns, gvk)\n\t\t}\n\t\treturn c.client.Resource(gvr), nil\n\n\tdefault:\n\t\t// Internal error ... this is panic-level\n\t\treturn nil, fmt.Errorf(\"unknown scope for gvk %s: %q\", gvk, restMapping.Scope.Name())\n\t}\n}\n\n// Patch performs a Patch operation, used for server-side apply and client-side patch.\nfunc (c *UnstructuredClient) Patch(ctx context.Context, gvk schema.GroupVersionKind, nn types.NamespacedName, patchType types.PatchType, data []byte, opt metav1.PatchOptions) (*unstructured.Unstructured, error) {\n\tdynamicResource, err := c.dynamicResource(ctx, gvk, nn.Namespace)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tname := nn.Name\n\tpatched, err := dynamicResource.Patch(ctx, name, patchType, data, opt)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error patching object: %w\", err)\n\t}\n\treturn patched, nil\n}\n","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/applylib/applyset/unstructuredclient.go#L57-L93","documentation":"A fallback branch in dynamicResource: after namespace-scoped and root-scoped cases, any unrecognized RESTScopeName indicates the RESTMapper returned data the client does not understand. The code itself calls this panic-level, i.e. it should be unreachable with a correct discovery client and k8s.io/client-go version.","triggerScenarios":"Only reachable if restMapping.Scope.Name() returns a value other than \"namespace\" or \"\" (root), which implies a corrupted/mis-built RESTMapping or an unexpected client-go version change.","commonSituations":"Practically never hit in production; may appear when vendoring mismatched versions of k8s.io/client-go / discovery, or with custom/simulated RESTMappers in tests returning fake scopes.","solutions":["Check go.mod for mismatched k8s.io/client-go and apimachinery versions and run make gomod to realign vendoring","Re-run discovery / rebuild the RESTMapper cache and retry","If using a custom RESTMapper (e.g. in tests), ensure its mappings return meta.RESTScopeNamespace or meta.RESTScopeRoot","Report upstream with the gvk and scope string if it reproduces with stock client-go"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"mapping, err := mapper.RESTMapping(gvk.GroupKind(), gvk.Version)\nif err == nil {\n\tscope := mapping.Scope.Name()\n\tif scope != meta.RESTScopeNameNamespace && scope != meta.RESTScopeNameRoot {\n\t\treturn fmt.Errorf(\"unexpected REST scope %q for %s; check client-go versions\", scope, gvk)\n\t}\n}","typeGuard":"func knownScope(mapping *meta.RESTMapping) bool {\n\tname := mapping.Scope.Name()\n\treturn name == meta.RESTScopeNameNamespace || name == meta.RESTScopeNameRoot\n}","tryCatchPattern":"res, err := client.Get(ctx, gvk, nn)\nif err != nil {\n\tif strings.HasPrefix(err.Error(), \"unknown scope for gvk\") {\n\t\t// dependency/invariant bug: rebuild discovery cache, realign client-go\n\t\treturn fmt.Errorf(\"internal: bad REST mapping for %s: %w\", gvk, err)\n\t}\n\treturn err\n}","preventionTips":["Keep k8s.io/client-go and apimachinery versions aligned in go.mod (make gomod)","Rebuild the RESTMapper after discovery errors instead of reusing stale mappings","Avoid custom RESTMappers in production paths","Treat this error as a bug report trigger, not a user-facing condition"],"tags":["kubernetes","discovery","internal-invariant"],"backgroundTag":"unknown-rest-scope","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}