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

kubernetes-sigs / kubebuilder / 25163963190

30 Apr 2026 11:46AM UTC coverage: 82.042% (-0.3%) from 82.313%
25163963190

Pull #5584

github

camilamacedo86
fix(alpha generate): license boilerplate
Pull Request #5584: WIP: chore(alpha update/AutoUpdate): Changes to ensure better usage and allow granular workflow and permissions

1 of 39 new or added lines in 2 files covered. (2.56%)

1 existing line in 1 file now uncovered.

7707 of 9394 relevant lines covered (82.04%)

73.43 hits per line

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

14.29
/pkg/plugins/optional/autoupdate/v1alpha/plugin.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
        "errors"
21
        "fmt"
22

23
        "sigs.k8s.io/kubebuilder/v4/pkg/config"
24
        cfgv3 "sigs.k8s.io/kubebuilder/v4/pkg/config/v3"
25
        "sigs.k8s.io/kubebuilder/v4/pkg/model/stage"
26
        "sigs.k8s.io/kubebuilder/v4/pkg/plugin"
27
        "sigs.k8s.io/kubebuilder/v4/pkg/plugins"
28
)
29

30
//nolint:lll
31
const metaDataDescription = `This plugin scaffolds a GitHub Action that helps you keep your project aligned with the latest Kubebuilder improvements. With a tiny amount of setup, you'll receive **automatic notifications** whenever a new Kubebuilder release is available, with both a GitHub Issue and Pull Request created by default.
32

33
Under the hood, the workflow runs 'kubebuilder alpha update' using a **3-way merge strategy** to refresh your scaffold while preserving your code. It creates and pushes an update branch, then opens both a GitHub **Issue** (for notification) and a **Pull Request** (for review and merge).
34

35
### How to set it up
36

37
1) **Add the plugin**: Use the Kubebuilder CLI to scaffold the automation into your repo.
38
2) **Review the workflow**: The file '.github/workflows/auto_update.yml' runs on a schedule to check for updates.
39
3) **Permissions required** (via the built-in 'GITHUB_TOKEN'):
40
   - **contents: write** — needed to create and push the update branch.
41
   - **issues: write** — needed to create the notification Issue (can be disabled with --open-gh-issue=false).
42
   - **pull-requests: write** — needed to create the Pull Request (can be disabled with --open-gh-pr=false).
43
   - **models: read** (optional) — only required if using --use-gh-models flag for AI-generated summaries.
44
4) **Protect your branches**: Enable **branch protection rules** so automated changes **cannot** be pushed directly. All updates must go through a Pull Request for review.
45

46
### Optional: GitHub Models AI Summary
47

48
By default, the workflow does NOT use GitHub Models. To enable AI-generated summaries in Pull Requests:
49
  - Ensure your repository/organization has permissions to use GitHub Models.
50
  - Re-run: kubebuilder edit --plugins="autoupdate/v1-alpha" --use-gh-models
51

52
Without this flag, the workflow will still work but won't include AI summaries (avoiding 403 Forbidden errors).`
53

54
const pluginName = "autoupdate." + plugins.DefaultNameQualifier
55

56
var (
57
        pluginVersion            = plugin.Version{Number: 1, Stage: stage.Alpha}
58
        supportedProjectVersions = []config.Version{cfgv3.Version}
59
)
60

61
// Plugin implements the plugin.Full interface
62
type Plugin struct {
63
        editSubcommand
64
}
65

66
var _ plugin.Edit = Plugin{}
67

68
// PluginConfig defines the structure that will be used to track the data
69
type PluginConfig struct {
70
        UseGHModels bool `json:"useGHModels,omitempty"`
71
        OpenGHIssue bool `json:"openGHIssue,omitempty"`
72
        OpenGHPR    bool `json:"openGHPR,omitempty"`
73
}
74

75
// Name returns the name of the plugin
76
func (Plugin) Name() string { return pluginName }
×
77

78
// Version returns the version of the Helm plugin
79
func (Plugin) Version() plugin.Version { return pluginVersion }
1✔
80

81
// SupportedProjectVersions returns an array with all project versions supported by the plugin
82
func (Plugin) SupportedProjectVersions() []config.Version { return supportedProjectVersions }
1✔
83

84
// GetEditSubcommand will return the subcommand which is responsible for adding and/or edit a autoupdate
85
func (p Plugin) GetEditSubcommand() plugin.EditSubcommand { return &p.editSubcommand }
×
86

87
// Description returns a short description of the plugin
88
func (Plugin) Description() string {
×
89
        return "Proposes Kubebuilder scaffold updates via GitHub Actions"
×
90
}
×
91

92
// DeprecationWarning define the deprecation message or return empty when plugin is not deprecated
93
func (p Plugin) DeprecationWarning() string {
1✔
94
        return ""
1✔
95
}
1✔
96

97
// insertPluginMetaToConfig will insert the metadata to the plugin configuration
98
func insertPluginMetaToConfig(target config.Config, cfg PluginConfig) error {
×
99
        key := plugin.GetPluginKeyForConfig(target.GetPluginChain(), Plugin{})
×
100
        canonicalKey := plugin.KeyFor(Plugin{})
×
101

×
NEW
102
        // Decode existing config for validation, but don't overwrite flag values
×
NEW
103
        var existing PluginConfig
×
NEW
104
        if err := target.DecodePluginConfig(key, &existing); err != nil {
×
105
                switch {
×
106
                case errors.As(err, &config.UnsupportedFieldError{}):
×
107
                        return nil
×
108
                case errors.As(err, &config.PluginKeyNotFoundError{}):
×
109
                        if key != canonicalKey {
×
NEW
110
                                if err2 := target.DecodePluginConfig(canonicalKey, &existing); err2 != nil {
×
111
                                        if errors.As(err2, &config.UnsupportedFieldError{}) {
×
112
                                                return nil
×
113
                                        }
×
114
                                        if !errors.As(err2, &config.PluginKeyNotFoundError{}) {
×
115
                                                return fmt.Errorf("error decoding plugin configuration: %w", err2)
×
116
                                        }
×
117
                                }
118
                        }
119
                default:
×
120
                        return fmt.Errorf("error decoding plugin configuration: %w", err)
×
121
                }
122
        }
123

124
        // Always encode the new config from flags (cfg parameter), not the existing one
125
        if err := target.EncodePluginConfig(key, cfg); err != nil {
×
126
                return fmt.Errorf("error encoding plugin configuration: %w", err)
×
127
        }
×
128

129
        return nil
×
130
}
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