|
| 1 | +/* |
| 2 | +Copyright 2026 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package cli |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + |
| 22 | + "github.com/spf13/cobra" |
| 23 | + |
| 24 | + "sigs.k8s.io/kubebuilder/v4/pkg/plugin" |
| 25 | +) |
| 26 | + |
| 27 | +func (c CLI) newDeleteCmd() *cobra.Command { |
| 28 | + cmd := &cobra.Command{ |
| 29 | + Use: "delete", |
| 30 | + Short: "Delete a Kubernetes API, webhook, or plugin features", |
| 31 | + Long: `Delete a Kubernetes API, webhook, or plugin features. |
| 32 | +
|
| 33 | +For resource-specific deletion: |
| 34 | + kubebuilder delete api --group <group> --version <version> --kind <kind> |
| 35 | + kubebuilder delete webhook --group <group> --version <version> --kind <kind> |
| 36 | +
|
| 37 | +For project-level plugin deletion: |
| 38 | + kubebuilder delete --plugins=helm/v2-alpha |
| 39 | + kubebuilder delete --plugins=grafana/v1-alpha,autoupdate/v1-alpha |
| 40 | +`, |
| 41 | + RunE: errCmdFunc( |
| 42 | + fmt.Errorf("delete requires a subcommand (api, webhook) or --plugins flag"), |
| 43 | + ), |
| 44 | + } |
| 45 | + |
| 46 | + // If plugins are specified, route to Edit subcommand with delete context |
| 47 | + if len(c.resolvedPlugins) > 0 { |
| 48 | + subcommands := c.filterSubcommands( |
| 49 | + func(p plugin.Plugin) bool { |
| 50 | + _, isValid := p.(plugin.Edit) |
| 51 | + return isValid |
| 52 | + }, |
| 53 | + func(p plugin.Plugin) plugin.Subcommand { |
| 54 | + return p.(plugin.Edit).GetEditSubcommand() |
| 55 | + }, |
| 56 | + ) |
| 57 | + |
| 58 | + if len(subcommands) > 0 { |
| 59 | + c.applySubcommandHooks(cmd, subcommands, "failed to delete plugin features", false) |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + return cmd |
| 64 | +} |
0 commit comments