• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kubernetes-sigs / kubebuilder / 21705957068

05 Feb 2026 09:24AM UTC coverage: 66.755% (-7.2%) from 73.919%
21705957068

Pull #5352

github

camilamacedo86
(chore) Add delete interface and implementation for all options

Add delete functionality to remove APIs and webhooks from projects.
Users can now clean up scaffolded resources.
Pull Request #5352: ✨ Added Delete API and implemented a unified interface across all commands and plugin options

394 of 1568 new or added lines in 21 files covered. (25.13%)

1 existing line in 1 file now uncovered.

7092 of 10624 relevant lines covered (66.75%)

37.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

59.62
/pkg/cli/delete.go
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 {
10✔
28
        cmd := &cobra.Command{
10✔
29
                Use:   "delete",
10✔
30
                Short: "Delete a Kubernetes API, webhook, or plugin features",
10✔
31
                Long: `Delete scaffolded code and manifests for APIs, webhooks, or plugin features.
10✔
32

10✔
33
Deletes generated files and updates PROJECT configuration automatically.
10✔
34
Code inserted at markers in cmd/main.go is automatically removed when possible.
10✔
35

10✔
36
Examples:
10✔
37
  # Delete an API (webhooks must be deleted first)
10✔
38
  kubebuilder delete api --group crew --version v1 --kind Captain
10✔
39

10✔
40
  # Delete specific webhook type
10✔
41
  kubebuilder delete webhook --group crew --version v1 --kind Captain --defaulting
10✔
42

10✔
43
  # Delete all webhook types for a resource
10✔
44
  kubebuilder delete webhook --group crew --version v1 --kind Captain
10✔
45

10✔
46
  # Delete API created with additional plugins
10✔
47
  kubebuilder delete api --group crew --version v1 --kind Captain --plugins=deploy-image/v1-alpha
10✔
48

10✔
49
  # Delete optional plugin features
10✔
50
  kubebuilder delete --plugins=grafana/v1-alpha
10✔
51
  kubebuilder delete --plugins=helm/v2-alpha
10✔
52
`,
10✔
53
                RunE: c.deleteWithPlugins,
10✔
54
        }
10✔
55

10✔
56
        return cmd
10✔
57
}
10✔
58

59
// deleteWithPlugins handles delete command when --plugins flag is used for optional plugins
NEW
60
func (c CLI) deleteWithPlugins(_ *cobra.Command, args []string) error {
×
NEW
61
        if len(args) > 0 {
×
NEW
62
                return fmt.Errorf("delete requires a subcommand: api or webhook")
×
NEW
63
        }
×
64

65
        // Check if we have optional plugins that implement deletion through Edit interface
66
        // (optional plugins like helm, grafana, autoupdate use Edit with --delete flag internally)
NEW
67
        hasOptionalPlugin := false
×
NEW
68
        for _, p := range c.resolvedPlugins {
×
NEW
69
                if _, hasEdit := p.(plugin.Edit); hasEdit {
×
NEW
70
                        if _, hasDeleteAPI := p.(plugin.DeleteAPI); !hasDeleteAPI {
×
NEW
71
                                if _, hasDeleteWebhook := p.(plugin.DeleteWebhook); !hasDeleteWebhook {
×
NEW
72
                                        hasOptionalPlugin = true
×
NEW
73
                                        break
×
74
                                }
75
                        }
76
                }
77
        }
78

NEW
79
        if hasOptionalPlugin {
×
NEW
80
                // Forward to edit command with --delete flag for optional plugin cleanup
×
NEW
81
                editCmd := c.newEditCmd()
×
NEW
82
                editCmd.SetArgs(append(args, "--delete"))
×
NEW
83
                if err := editCmd.Execute(); err != nil {
×
NEW
84
                        return fmt.Errorf("failed to delete optional plugin features: %w", err)
×
NEW
85
                }
×
NEW
86
                return nil
×
87
        }
88

NEW
89
        return fmt.Errorf("delete requires a subcommand (api, webhook) or " +
×
NEW
90
                "use with optional plugins (helm, grafana, autoupdate)")
×
91
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc