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

kubernetes-sigs / kubebuilder / 20694092930

04 Jan 2026 02:06PM UTC coverage: 67.164% (-4.2%) from 71.354%
20694092930

Pull #5352

github

camilamacedo86
Add delete api and delete webhook commands

Add delete functionality to remove APIs and webhooks from projects.
Users can now clean up scaffolded resources with proper validation.
Pull Request #5352: WIP ✨ Add delete api and delete webhook commands

341 of 1049 new or added lines in 18 files covered. (32.51%)

1 existing line in 1 file now uncovered.

6521 of 9709 relevant lines covered (67.16%)

27.1 hits per line

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

18.84
/pkg/plugins/optional/autoupdate/v1alpha/edit.go
1
/*
2
Copyright 2025 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 v1alpha
18

19
import (
20
        "fmt"
21
        log "log/slog"
22
        "path/filepath"
23

24
        "github.com/spf13/afero"
25
        "github.com/spf13/pflag"
26

27
        "sigs.k8s.io/kubebuilder/v4/pkg/config"
28
        "sigs.k8s.io/kubebuilder/v4/pkg/machinery"
29
        "sigs.k8s.io/kubebuilder/v4/pkg/plugin"
30
        "sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/autoupdate/v1alpha/scaffolds"
31
)
32

33
var _ plugin.EditSubcommand = &editSubcommand{}
34

35
type editSubcommand struct {
36
        config      config.Config
37
        useGHModels bool
38
        delete      bool
39
}
40

41
func (p *editSubcommand) UpdateMetadata(cliMeta plugin.CLIMetadata, subcmdMeta *plugin.SubcommandMetadata) {
×
42
        subcmdMeta.Description = metaDataDescription
×
43

×
44
        subcmdMeta.Examples = fmt.Sprintf(`  # Edit a common project with this plugin
×
45
  %[1]s edit --plugins=%[2]s
×
46

×
47
  # Edit a common project with GitHub Models enabled (requires repo permissions)
×
48
  %[1]s edit --plugins=%[2]s --use-gh-models
×
49
`, cliMeta.CommandName, plugin.KeyFor(Plugin{}))
×
50
}
×
51

52
func (p *editSubcommand) BindFlags(fs *pflag.FlagSet) {
×
53
        fs.BoolVar(&p.useGHModels, "use-gh-models", false,
×
54
                "enable GitHub Models AI summary in the scaffolded workflow (requires GitHub Models permissions)")
×
NEW
55
        fs.BoolVar(&p.delete, "delete", false, "delete auto-update workflow from the project")
×
UNCOV
56
}
×
57

58
func (p *editSubcommand) InjectConfig(c config.Config) error {
2✔
59
        p.config = c
2✔
60
        return nil
2✔
61
}
2✔
62

63
func (p *editSubcommand) PreScaffold(machinery.Filesystem) error {
2✔
64
        if len(p.config.GetCliVersion()) == 0 {
3✔
65
                return fmt.Errorf(
1✔
66
                        "you must manually upgrade your project to a version that records the CLI version in PROJECT (`cliVersion`) " +
1✔
67
                                "to allow the `alpha update` command to work properly before using this plugin.\n" +
1✔
68
                                "More info: https://book.kubebuilder.io/migrations",
1✔
69
                )
1✔
70
        }
1✔
71
        return nil
1✔
72
}
73

74
func (p *editSubcommand) Scaffold(fs machinery.Filesystem) error {
×
NEW
75
        if p.delete {
×
NEW
76
                return p.deleteAutoUpdateWorkflow(fs)
×
NEW
77
        }
×
78

79
        if err := insertPluginMetaToConfig(p.config, PluginConfig{UseGHModels: p.useGHModels}); err != nil {
×
80
                return fmt.Errorf("error inserting project plugin meta to configuration: %w", err)
×
81
        }
×
82

83
        scaffolder := scaffolds.NewInitScaffolder(p.useGHModels)
×
84
        scaffolder.InjectFS(fs)
×
85
        if err := scaffolder.Scaffold(); err != nil {
×
86
                return fmt.Errorf("error scaffolding edit subcommand: %w", err)
×
87
        }
×
88

89
        return nil
×
90
}
91

NEW
92
func (p *editSubcommand) deleteAutoUpdateWorkflow(fs machinery.Filesystem) error {
×
NEW
93
        log.Info("Deleting auto-update workflow...")
×
NEW
94

×
NEW
95
        workflowFile := filepath.Join(".github", "workflows", "auto_update.yml")
×
NEW
96

×
NEW
97
        if exists, _ := afero.Exists(fs.FS, workflowFile); exists {
×
NEW
98
                if err := fs.FS.Remove(workflowFile); err != nil {
×
NEW
99
                        log.Warn("Failed to delete workflow file", "file", workflowFile, "error", err)
×
NEW
100
                } else {
×
NEW
101
                        log.Info("Deleted workflow file", "file", workflowFile)
×
NEW
102
                        fmt.Println("\nDeleted auto-update workflow")
×
NEW
103
                }
×
NEW
104
        } else {
×
NEW
105
                log.Warn("Workflow file not found", "file", workflowFile)
×
NEW
106
                fmt.Println("\nWorkflow file not found (may have been already deleted)")
×
NEW
107
        }
×
108

109
        // Remove plugin config
NEW
110
        key := plugin.GetPluginKeyForConfig(p.config.GetPluginChain(), Plugin{})
×
NEW
111
        if err := p.config.EncodePluginConfig(key, PluginConfig{}); err != nil {
×
NEW
112
                log.Warn("Failed to remove plugin config", "error", err)
×
NEW
113
        }
×
114

NEW
115
        return nil
×
116
}
117

118
func (p *editSubcommand) PostScaffold() error {
×
119
        // Inform users about GitHub Models if they didn't enable it
×
120
        if !p.useGHModels {
×
121
                log.Info("Consider enabling GitHub Models to get an AI summary to help with the update")
×
122
                log.Info("Use the --use-gh-models flag if your project/organization has permission to use GitHub Models")
×
123
        }
×
124
        return nil
×
125
}
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