Skip to content

Commit 6ba543b

Browse files
authored
⚠ (helm/v1-alpha): remove init command from Helm plugin as it's only meaningful with edit (#4903)
feat(helm): remove helm from init command Signed-off-by: Mario Constanti <mario.constanti@mercedes-benz.com>
1 parent 2dc5419 commit 6ba543b

File tree

5 files changed

+16
-83
lines changed

5 files changed

+16
-83
lines changed

docs/book/src/plugins/available/helm-v1-alpha.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ under the [testdata][testdata] directory on the root directory of the Kubebuilde
4141

4242
### Basic Usage
4343

44-
The Helm plugin is attached to the `init` subcommand and the `edit` subcommand:
44+
The Helm plugin is attached to the `edit` subcommand as the `helm/v1-alpha` plugin
45+
relies on the Go project being scaffolded first.
4546

4647
```sh
4748

48-
# Initialize a new project with helm chart
49-
kubebuilder init --plugins=helm/v1-alpha
49+
# Initialize a new project
50+
kubebuilder init
5051

5152
# Enable or Update the helm chart via the helm plugin to an existing project
5253
# Before run the edit command, run `make manifests` to generate the manifest under `config/`
@@ -80,8 +81,6 @@ The Helm plugin implements the following subcommands:
8081

8182
- edit (`$ kubebuilder edit [OPTIONS]`)
8283

83-
- init (`$ kubebuilder init [OPTIONS]`)
84-
8584
## Affected files
8685

8786
The following scaffolds will be created or updated by this plugin:

pkg/plugins/optional/helm/v1alpha/edit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (p *editSubcommand) InjectConfig(c config.Config) error {
7474
}
7575

7676
func (p *editSubcommand) Scaffold(fs machinery.Filesystem) error {
77-
scaffolder := scaffolds.NewInitHelmScaffolder(p.config, p.force)
77+
scaffolder := scaffolds.NewHelmScaffolder(p.config, p.force)
7878
scaffolder.InjectFS(fs)
7979
err := scaffolder.Scaffold()
8080
if err != nil {

pkg/plugins/optional/helm/v1alpha/init.go

Lines changed: 0 additions & 59 deletions
This file was deleted.

pkg/plugins/optional/helm/v1alpha/plugin.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,10 @@ var (
3434

3535
// Plugin implements the plugin.Full interface
3636
type Plugin struct {
37-
initSubcommand
3837
editSubcommand
3938
}
4039

41-
var (
42-
_ plugin.Init = Plugin{}
43-
_ plugin.Edit = Plugin{}
44-
)
40+
var _ plugin.Edit = Plugin{}
4541

4642
type pluginConfig struct{}
4743

@@ -54,9 +50,6 @@ func (Plugin) Version() plugin.Version { return pluginVersion }
5450
// SupportedProjectVersions returns an array with all project versions supported by the plugin
5551
func (Plugin) SupportedProjectVersions() []config.Version { return supportedProjectVersions }
5652

57-
// GetInitSubcommand will return the subcommand which is responsible for initializing and scaffolding helm manifests
58-
func (p Plugin) GetInitSubcommand() plugin.InitSubcommand { return &p.initSubcommand }
59-
6053
// GetEditSubcommand will return the subcommand which is responsible for adding and/or edit a helm chart
6154
func (p Plugin) GetEditSubcommand() plugin.EditSubcommand { return &p.editSubcommand }
6255

pkg/plugins/optional/helm/v1alpha/scaffolds/init.go renamed to pkg/plugins/optional/helm/v1alpha/scaffolds/edit.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,31 @@ import (
4242
"sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/github"
4343
)
4444

45-
var _ plugins.Scaffolder = &initScaffolder{}
45+
var _ plugins.Scaffolder = &editScaffolder{}
4646

47-
type initScaffolder struct {
47+
type editScaffolder struct {
4848
config config.Config
4949

5050
fs machinery.Filesystem
5151

5252
force bool
5353
}
5454

55-
// NewInitHelmScaffolder returns a new Scaffolder for HelmPlugin
56-
func NewInitHelmScaffolder(cfg config.Config, force bool) plugins.Scaffolder {
57-
return &initScaffolder{
55+
// NewHelmScaffolder returns a new Scaffolder for HelmPlugin
56+
func NewHelmScaffolder(cfg config.Config, force bool) plugins.Scaffolder {
57+
return &editScaffolder{
5858
config: cfg,
5959
force: force,
6060
}
6161
}
6262

6363
// InjectFS implements cmdutil.Scaffolder
64-
func (s *initScaffolder) InjectFS(fs machinery.Filesystem) {
64+
func (s *editScaffolder) InjectFS(fs machinery.Filesystem) {
6565
s.fs = fs
6666
}
6767

6868
// Scaffold scaffolds the Helm chart with the necessary files.
69-
func (s *initScaffolder) Scaffold() error {
69+
func (s *editScaffolder) Scaffold() error {
7070
log.Println("Generating Helm Chart to distribute project")
7171

7272
imagesEnvVars := s.getDeployImagesEnvVars()
@@ -132,7 +132,7 @@ func (s *initScaffolder) Scaffold() error {
132132

133133
// getDeployImagesEnvVars will return the values to append the envvars for projects
134134
// which has the APIs scaffolded with DeployImage plugin
135-
func (s *initScaffolder) getDeployImagesEnvVars() map[string]string {
135+
func (s *editScaffolder) getDeployImagesEnvVars() map[string]string {
136136
deployImages := make(map[string]string)
137137

138138
pluginConfig := struct {
@@ -157,7 +157,7 @@ func (s *initScaffolder) getDeployImagesEnvVars() map[string]string {
157157
// extractWebhooksFromGeneratedFiles parses the files generated by controller-gen under
158158
// config/webhooks and created Mutating and Validating helper structures to
159159
// generate the webhook manifest for the helm-chart
160-
func (s *initScaffolder) extractWebhooksFromGeneratedFiles() (mutatingWebhooks []templateswebhooks.DataWebhook,
160+
func (s *editScaffolder) extractWebhooksFromGeneratedFiles() (mutatingWebhooks []templateswebhooks.DataWebhook,
161161
validatingWebhooks []templateswebhooks.DataWebhook, err error,
162162
) {
163163
manifestFile := "config/webhook/manifests.yaml"
@@ -227,7 +227,7 @@ func (s *initScaffolder) extractWebhooksFromGeneratedFiles() (mutatingWebhooks [
227227
}
228228

229229
// Helper function to copy files from config/ to dist/chart/templates/
230-
func (s *initScaffolder) copyConfigFiles() error {
230+
func (s *editScaffolder) copyConfigFiles() error {
231231
configDirs := []struct {
232232
SrcDir string
233233
DestDir string

0 commit comments

Comments
 (0)