{"record":{"id":"213249d4beea3efc","repo":"kubernetes/kops","slug":"unable-to-find-resource-for-s-w","errorCode":null,"errorMessage":"unable to find resource for %s: %w","messagePattern":"unable to find resource for (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"channels/pkg/channels/prune.go","lineNumber":83,"sourceCode":"\t}\n\n\tfor i := range spec.Kinds {\n\t\tpruneKind := &spec.Kinds[i]\n\t\tgk := schema.GroupKind{Group: pruneKind.Group, Kind: pruneKind.Kind}\n\t\tif err := p.pruneObjectsOfKind(ctx, gk, pruneKind, objectsByKind[gk]); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to prune objects of kind %s: %w\", gk, err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (p *Pruner) pruneObjectsOfKind(ctx context.Context, gk schema.GroupKind, spec *api.PruneKindSpec, keepObjects []*kubemanifest.Object) error {\n\tklog.Infof(\"pruning objects of kind: %v\", gk)\n\n\trestMapping, err := p.RESTMapper.RESTMapping(gk)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to find resource for %s: %w\", gk, err)\n\t}\n\n\tgvr := restMapping.Resource\n\n\tvar listOptions v1.ListOptions\n\tlistOptions.LabelSelector = spec.LabelSelector\n\tlistOptions.FieldSelector = spec.FieldSelector\n\n\tbaseResource := p.Client.Resource(gvr)\n\tif len(spec.Namespaces) == 0 {\n\t\tobjects, err := baseResource.List(ctx, listOptions)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error listing objects: %w\", err)\n\t\t}\n\t\tif err := p.pruneObjects(ctx, gvr, objects, keepObjects); err != nil {\n\t\t\treturn err\n\t\t}\n\t} else {","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/channels/pkg/channels/prune.go#L65-L101","documentation":"pruneObjectsOfKind asks the DeferredDiscoveryRESTMapper to map a GroupKind to a REST resource. If the discovery mapper has no mapping (kind unknown to the cluster), the error is wrapped as `unable to find resource for <gk>` and pruning of that kind aborts.","triggerScenarios":"The PruneSpec lists a kind whose resource does not exist on the API server: wrong group/kind, CRD not installed, API removed in the cluster's Kubernetes version, or discovery cache is stale.","commonSituations":"Typo'd kind in prune spec; pruning a custom resource before its CRD is applied; cluster upgraded to a version that removed an API (e.g. policy/v1beta1 kinds); discovery cache stale after CRD install.","solutions":["Check the kind exists: `kubectl api-resources | grep <kind>` and align the PruneSpec with actual group/kind","Install the CRD before running the channel update/prune","Reset the discovery cache (restart the controller/kops process) if a CRD was just installed","Remove obsolete kinds from the PruneSpec for clusters where the API no longer exists"],"exampleFix":"// before\nkinds:\n- group: monitoring.coreos.com\n  kind: ServiceMonitor  # CRD not installed yet\n// after\n// apply the CRD first, or:\nkinds:\n- group: apps\n  kind: Deployment","handlingStrategy":"validation","validationCode":"gk := schema.GroupKind{Group: \"monitoring.coreos.com\", Kind: \"ServiceMonitor\"}\nif _, err := restMapper.RESTMapping(gk); err != nil {\n    return fmt.Errorf(\"skip prune, kind %v unavailable in cluster\", gk)\n}","typeGuard":null,"tryCatchPattern":"if err := pruner.Prune(ctx, manifest, spec); err != nil {\n    if strings.Contains(err.Error(), \"unable to find resource for\") {\n        klog.Warningf(\"prune kind unknown to cluster, skipping: %v\", err)\n        return nil // or install the CRD and retry\n    }\n    return err\n}","preventionTips":["Cross-check prune spec kinds against `kubectl api-resources` for every supported cluster version","Apply CRDs before addon manifests and pruning","Bump/remove prune entries when a Kubernetes upgrade removes an API","Restart processes after CRD installation if using a cached discovery mapper"],"tags":["restmapper","discovery","crd","kubernetes"],"backgroundTag":"no-resource-mapping-found","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"}