Skip to content

🛠️ add ignore flags for selective scaffolding in edit command #4889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion pkg/plugins/optional/helm/v1alpha/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ var _ plugin.EditSubcommand = &editSubcommand{}
type editSubcommand struct {
config config.Config
force bool

IgnorePrometheus bool
IgnoreNetworkPolicy bool
IgnoreCertManager bool
IgnoreWebhook bool
}

//nolint:lll
Expand Down Expand Up @@ -66,6 +71,11 @@ manifests in the chart align with the latest changes.

func (p *editSubcommand) BindFlags(fs *pflag.FlagSet) {
fs.BoolVar(&p.force, "force", false, "if true, regenerates all the files")

fs.BoolVar(&p.IgnorePrometheus, "ignore-prometheus", false, "ignore scaffolding of prometheus monitor")
fs.BoolVar(&p.IgnoreNetworkPolicy, "ignore-networkPolicy", false, "ignore scaffolding of network policy")
fs.BoolVar(&p.IgnoreCertManager, "ignore-certmanager", false, "ignore scaffolding of cert-manager manifests")
fs.BoolVar(&p.IgnoreWebhook, "ignore-webhook", false, "ignore scaffolding of webhooks")
}

func (p *editSubcommand) InjectConfig(c config.Config) error {
Expand All @@ -74,7 +84,14 @@ func (p *editSubcommand) InjectConfig(c config.Config) error {
}

func (p *editSubcommand) Scaffold(fs machinery.Filesystem) error {
scaffolder := scaffolds.NewInitHelmScaffolder(p.config, p.force)
ignoreFlags := map[string]bool{
"ignore-prometheus": p.IgnorePrometheus,
"ignore-networkPolicy": p.IgnoreNetworkPolicy,
"ignore-certmanager": p.IgnoreCertManager,
"ignore-webhook": p.IgnoreWebhook,
}
scaffolder := scaffolds.NewInitHelmScaffolder(p.config, p.force, ignoreFlags)

scaffolder.InjectFS(fs)
err := scaffolder.Scaffold()
if err != nil {
Expand Down
9 changes: 8 additions & 1 deletion pkg/plugins/optional/helm/v1alpha/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ func (p *initSubcommand) InjectConfig(c config.Config) error {
}

func (p *initSubcommand) Scaffold(fs machinery.Filesystem) error {
scaffolder := scaffolds.NewInitHelmScaffolder(p.config, false)
ignoreFlags := map[string]bool{
"ignore-prometheus": false,
"ignore-networkPolicy": false,
"ignore-certmanager": false,
"ignore-webhook": false,
}
Copy link
Member

@camilamacedo86 camilamacedo86 Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make this work, we’d need to ensure that we have none conditions using them in the scaffold as well.
For example, see the values.ymal and the other helm templates, we have conditions that check if has webhooks and etc.. handling those isn’t as straightforward as it seems.

I know we opened an issue about this in the past, but I’m not sure how feasible or maintainable it is long-term. We’d also need a way to validate and guarantee support across all options.

If we go ahead with this, we should: ( we cannot add the options without ensure that all works and is done as expected in each case )

  • Cover all relevant scaffold points
  • Add CI tests to validate configs for each scenario
  • Mock Helm charts and install them during e2e to catch issues early

We could follow the same pattern used in our e2e tests: create mocks per case, deploy them, and verify outcomes. See e2e/go/v4 and related GitHub Actions as reference.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the clarification!
Yes, currently the flags only prevent the files from being regenerated, but the corresponding checks in values.yaml and templates still need to be handled.
I’ll start working on adding the necessary conditions for those.
If you have any suggestions or references for adding those conditions or e2e tests, it would really help me a lot!


scaffolder := scaffolds.NewInitHelmScaffolder(p.config, false, ignoreFlags)
scaffolder.InjectFS(fs)
err := scaffolder.Scaffold()
if err != nil {
Expand Down
43 changes: 33 additions & 10 deletions pkg/plugins/optional/helm/v1alpha/scaffolds/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,22 @@ type initScaffolder struct {
fs machinery.Filesystem

force bool

IgnorePrometheus bool
IgnoreCertManager bool
IgnoreWebhook bool
IgnoreNetworkPolicy bool
}

// NewInitHelmScaffolder returns a new Scaffolder for HelmPlugin
func NewInitHelmScaffolder(cfg config.Config, force bool) plugins.Scaffolder {
func NewInitHelmScaffolder(cfg config.Config, force bool, ignoreFlags map[string]bool) plugins.Scaffolder {
return &initScaffolder{
config: cfg,
force: force,
config: cfg,
force: force,
IgnorePrometheus: ignoreFlags["ignore-prometheus"],
IgnoreCertManager: ignoreFlags["ignore-certmanager"],
IgnoreWebhook: ignoreFlags["ignore-webhook"],
IgnoreNetworkPolicy: ignoreFlags["ignore-networkPolicy"],
}
}

Expand Down Expand Up @@ -92,17 +101,31 @@ func (s *initScaffolder) Scaffold() error {
},
&templates.HelmIgnore{},
&charttemplates.HelmHelpers{},
&manager.Deployment{
}

if !s.IgnoreWebhook {
buildScaffold = append(buildScaffold, &manager.Deployment{
Force: s.force,
DeployImages: len(imagesEnvVars) > 0,
HasWebhooks: hasWebhooks,
},
&templatescertmanager.Certificate{HasWebhooks: hasWebhooks},
&templatesmetrics.Service{},
&prometheus.Monitor{},
})
}

if !s.IgnoreCertManager {
buildScaffold = append(buildScaffold, &templatescertmanager.Certificate{
HasWebhooks: hasWebhooks,
})
}

if !s.IgnoreNetworkPolicy {
buildScaffold = append(buildScaffold, &templatesmetrics.Service{})
}

if !s.IgnorePrometheus {
buildScaffold = append(buildScaffold, &prometheus.Monitor{})
}

if len(mutatingWebhooks) > 0 || len(validatingWebhooks) > 0 {
if !s.IgnoreWebhook && len(mutatingWebhooks) > 0 || len(validatingWebhooks) > 0 {
buildScaffold = append(buildScaffold,
&templateswebhooks.Template{
MutatingWebhooks: mutatingWebhooks,
Expand All @@ -111,7 +134,7 @@ func (s *initScaffolder) Scaffold() error {
)
}

if hasWebhooks {
if !s.IgnoreWebhook && hasWebhooks {
buildScaffold = append(buildScaffold,
&templateswebhooks.Service{},
)
Expand Down