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

kubernetes-sigs / kubebuilder / 21644195158

03 Feb 2026 07:17PM UTC coverage: 66.682% (-7.2%) from 73.852%
21644195158

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.

7069 of 10601 relevant lines covered (66.68%)

37.83 hits per line

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

17.33
/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 from PROJECT by encoding empty struct
110
        // Empty struct will be omitted from YAML during marshaling
NEW
111
        key := plugin.GetPluginKeyForConfig(p.config.GetPluginChain(), Plugin{})
×
NEW
112
        if err := p.config.EncodePluginConfig(key, struct{}{}); err != nil {
×
NEW
113
                canonicalKey := plugin.KeyFor(Plugin{})
×
NEW
114
                if key != canonicalKey {
×
NEW
115
                        if err2 := p.config.EncodePluginConfig(canonicalKey, struct{}{}); err2 != nil {
×
NEW
116
                                log.Warn("Failed to remove plugin config", "error", err2)
×
NEW
117
                        }
×
NEW
118
                } else {
×
NEW
119
                        log.Warn("Failed to remove plugin config", "error", err)
×
NEW
120
                }
×
121
        }
122

NEW
123
        return nil
×
124
}
125

126
func (p *editSubcommand) PostScaffold() error {
×
127
        // Inform users about GitHub Models if they didn't enable it
×
128
        if !p.useGHModels {
×
129
                log.Info("Consider enabling GitHub Models to get an AI summary to help with the update")
×
130
                log.Info("Use the --use-gh-models flag if your project/organization has permission to use GitHub Models")
×
131
        }
×
132
        return nil
×
133
}
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