{"record":{"id":"b1f32c1fa6b857f8","repo":"kubernetes/kops","slug":"instancegroups-deletecollection-not-supported-for","errorCode":null,"errorMessage":"InstanceGroups::DeleteCollection not supported for server-side client","messagePattern":"InstanceGroups::DeleteCollection not supported for server-side client","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops-controller/pkg/controllerclientset/instancegroups.go","lineNumber":112,"sourceCode":"\t\tc.addLabels(&list.Items[i])\n\t}\n\treturn list, nil\n}\n\nfunc (c *instanceGroups) Create(ctx context.Context, g *kopsapi.InstanceGroup, opts metav1.CreateOptions) (*kopsapi.InstanceGroup, error) {\n\treturn nil, fmt.Errorf(\"InstanceGroups::Create not supported for server-side client\")\n}\n\nfunc (c *instanceGroups) Update(ctx context.Context, g *kopsapi.InstanceGroup, opts metav1.UpdateOptions) (*kopsapi.InstanceGroup, error) {\n\treturn nil, fmt.Errorf(\"InstanceGroups::Update not supported for server-side client\")\n}\n\nfunc (c *instanceGroups) Delete(ctx context.Context, name string, options metav1.DeleteOptions) error {\n\treturn fmt.Errorf(\"InstanceGroups::Delete not supported for server-side client\")\n}\n\nfunc (r *instanceGroups) DeleteCollection(ctx context.Context, options metav1.DeleteOptions, listOptions metav1.ListOptions) error {\n\treturn fmt.Errorf(\"InstanceGroups::DeleteCollection not supported for server-side client\")\n}\n\nfunc (r *instanceGroups) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {\n\treturn nil, fmt.Errorf(\"InstanceGroups::Watch not supported for server-side client\")\n}\n\nfunc (r *instanceGroups) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *kopsapi.InstanceGroup, err error) {\n\treturn nil, fmt.Errorf(\"InstanceGroups::Patch not supported for server-side client\")\n}\n","sourceCodeStart":94,"sourceCodeEnd":122,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops-controller/pkg/controllerclientset/instancegroups.go#L94-L122","documentation":"The kops-controller server-side clientset intentionally does not implement InstanceGroups collection deletion. The instanceGroups resource wrapper returns this sentinel error from DeleteCollection because the controller clientset only supports the subset of methods kops-controller actually needs. Calling an unimplemented method on the server-side client always returns this fixed error; nothing is sent to the API server.","triggerScenarios":"Any code path that calls ctxClient.InstanceGroups().DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{}) on the server-side controller clientset, e.g. bulk-cleanup code or generic reconcile logic written against the full kops clientset interface.","commonSituations":"Refactoring code that previously used the legacy kops clientset (which supports DeleteCollection) to the controller server-side clientset; writing a controller helper that assumes interface parity; generic code that iterates and deletes collections of resources.","solutions":["Avoid DeleteCollection on this clientset: list InstanceGroups and delete each item individually via Delete(name) — but note Delete is also unsupported, so instead delete via the standard Kubernetes clientset or apply an empty/desired state server-side","Use a standard Kubernetes typed clientset (client-go) built from the controller's REST config for deletion operations","Restructure logic to not require deleting instance group collections (e.g. manage desired state with server-side apply and let garbage collection remove objects)","If the method is genuinely needed, contribute an implementation to cmd/kops-controller/pkg/controllerclientset/instancegroups.go"],"exampleFix":"// before\nerr := client.InstanceGroups().DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{})\n// after\ngroups, err := client.InstanceGroups().List(ctx, metav1.ListOptions{})\nif err != nil {\n\treturn err\n}\nfor _, ig := range groups.Items {\n\tklog.Infof(\"instance group %s must be removed out-of-band\", ig.Name)\n}","handlingStrategy":"fallback","validationCode":"if _, ok := igClient.(interface{ DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error }); ok {\n\t// only safe if implemented; controllerclientset returns sentinel error, so skip\n}\n// Prefer: restrict deletion logic to the standard client-go clientset.\n","typeGuard":"func supportsDeleteCollection(v interface{}) bool {\n\t_, ok := v.(interface {\n\t\tDeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error\n\t})\n\treturn ok\n}","tryCatchPattern":"if err := igClient.DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{}); err != nil {\n\tif strings.Contains(err.Error(), \"not supported for server-side client\") {\n\t\treturn handleOutOfBandDeletion(ctx) // fallback path via kubectl/standard clientset\n\t}\n\treturn err\n}","preventionTips":["Consult cmd/kops-controller/pkg/controllerclientset for the supported method set before writing code against it","Route all delete operations through the standard client-go clientset, not the controller clientset","Prefer server-side apply of desired state over imperative collection deletes","Add a unit test asserting which registry methods your code path uses"],"tags":["kubernetes","kops-controller","clientset","unsupported-method"],"backgroundTag":"unsupported-clientset-method","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}