Skip to content

馃悰 (helm/v2-alpha): Support webhook opt-out via env overrides - #5995

Open
aiqubits wants to merge 2 commits into
kubernetes-sigs:masterfrom
aiqubits:fix/helm-webhook-env-overrides-5987
Open

aiqubits wants to merge 2 commits into
kubernetes-sigs:masterfrom
aiqubits:fix/helm-webhook-env-overrides-5987

Conversation

@aiqubits

@aiqubits aiqubits commented Aug 27, 2026

Copy link
Copy Markdown

Description

webhook.enabled=false skips the webhook resources rendered by the chart, but it does not stop the scaffolded manager from registering webhooks or starting its webhook server.

This change:

  • allows explicit manager environment overrides when the source Deployment has no env field, without exposing envOverrides in the default values or changing the default rendered manifest
  • adds conditional environment variable templating to manager containers without existing environment variables
  • allows users to stop scaffolded webhooks with manager.envOverrides.ENABLE_WEBHOOKS=false
  • documents the actual webhook.enabled behavior, the default 9443 listener, and conversion webhook limitations
  • regenerates the affected Helm chart samples

The chart does not automatically set ENABLE_WEBHOOKS=false, so existing runtime behavior remains unchanged unless the user explicitly configures the override.

Fixes #5987

Testing

  • make test-unit
  • go test -race -tags=integration -timeout 10m ./pkg/plugins/optional/helm/v2alpha/...
  • make generate-charts
  • make helm-lint
  • make kube-linter
  • make fix-docs
  • bin/golangci-lint fmt --diff
  • rendered charts with manager.envOverrides.ENABLE_WEBHOOKS=false and verified that Helm emits value: "false"

@kubernetes-prow

Copy link
Copy Markdown
Contributor

Welcome @aiqubits!

It looks like this is your first PR to kubernetes-sigs/kubebuilder 馃帀. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/kubebuilder has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 馃槂

@kubernetes-prow kubernetes-prow Bot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 27, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Hi @aiqubits. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@kubernetes-prow kubernetes-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 27, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: aiqubits
Once this PR has been reviewed and has the lgtm label, please assign camilamacedo86 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

childIndent + `{{- end }}`,
childIndent + `{{- else }}`,
childIndent + "[]",
childIndent + `{{- end }}`,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would be possible to use buf.WriteString ??
Or constants as we do on other places to faciliate the maintainability?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated. The shared Helm condition is now a named constant, and the block is generated with strings.Builder. The existing-env and optional-env paths share the same builder while preserving their different default rendering behavior.

## Environment variable overrides (--set manager.envOverrides.VAR=value)
## These values take precedence over entries with the same name in manager.env.
##
envOverrides: {}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why that was added ??
Would with this propose we start to add it indeed when has no ENV VARs?
What would be the use cases?
Pros and cons? Maybe that is the right approach just trying to think on that to ensure that we are going in the right direction.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I added this because the workaround in #5987 currently does not work for the common case where the source Deployment has no env field: both the generated env template and envOverrides are omitted.
However, you are right that always exposing envOverrides broadens the chart API beyond what this fix needs. Helm can create a missing nested value through --set, so I can narrow the change: keep envOverrides in values.yaml only when source env entries exist, while generating a fully conditional env block for deployments without env. The default manifest then remains unchanged, but the explicit --set manager.envOverrides.ENABLE_WEBHOOKS=false workaround still works.

@kubernetes-prow kubernetes-prow Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 2, 2026
@aiqubits aiqubits changed the title fix(helm/v2-alpha): support webhook opt-out via env overrides 馃悰 (helm/v2-alpha): Support webhook opt-out via env overrides Sep 2, 2026
Always expose manager.envOverrides and template the manager env field even when the source Deployment has no environment variables. Document the limits of webhook.enabled and the conversion webhook caveat.
@aiqubits
aiqubits force-pushed the fix/helm-webhook-env-overrides-5987 branch from 3d058bd to e3e2825 Compare September 2, 2026 10:27
@kubernetes-prow kubernetes-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 2, 2026
@hexbinoct

Copy link
Copy Markdown
Contributor

One wording point on the new aside, since it is going into the book as a permanent warning.

No webhook.port value disables the server.

That holds today for two independent reasons: the chart does not pass --webhook-port at all when webhook.enabled=false, and controller-runtime v0.24.1 defaults any port <= 0 back to 9443 in Options.setDefaults.

The second reason is already gone upstream. controller-runtime#3481 (merged 2026-07-27, unreleased, newest tag is v0.24.1 from 2026-05-12) narrowed that to if o.Port == 0 and made a negative port disable the server. So after the scaffold's next controller-runtime bump, --set webhook.enabled=true --set webhook.port=-1 will pass --webhook-port=-1 and the server will not listen, which makes that sentence false.

Scoping it to what we pin would keep it accurate, something like: "with the controller-runtime version the scaffold currently pins, no webhook.port value disables the server." Everything else in the aside reads correctly to me.

@aiqubits

aiqubits commented Sep 4, 2026

Copy link
Copy Markdown
Author

@hexbinoct I scoped the statement to the controller-runtime version currently pinned by the scaffold, as suggested. Thanks for catching that.

@camilamacedo86

Copy link
Copy Markdown
Member

Hi @aiqubits

See the comment: #5987 (comment)

We will need to bump controller-runtime latest and then address this one

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

馃煝 Approval recommended

The implementation preserves default rendering while providing tested, documented opt-out behavior.

Pull request overview

Adds explicit Helm environment overrides so users can disable scaffolded webhook registration without changing default chart output.

Changes:

  • Conditionally renders manager environment overrides when no source env field exists.
  • Adds unit and integration coverage for default and override rendering.
  • Documents webhook opt-out behavior and regenerates tutorial charts.
File summaries
File Description
pkg/plugins/optional/helm/v2alpha/scaffolds/test/chart_generation_integration_test.go Tests rendered override behavior.
pkg/plugins/optional/helm/v2alpha/scaffolds/internal/templates/values_test.go Tests environment values generation.
pkg/plugins/optional/helm/v2alpha/scaffolds/internal/kustomize/templater/appliers/manager.go Adds conditional manager environment templating.
pkg/plugins/optional/helm/v2alpha/scaffolds/internal/kustomize/templater/appliers/helpers_test.go Covers env-less and inline-env deployments.
docs/book/src/plugins/available/helm-v2-alpha.md Documents webhook behavior and opt-out usage.
docs/book/src/multiversion-tutorial/testdata/project/dist/chart/templates/manager/manager.yaml Regenerates the multiversion chart.
docs/book/src/getting-started/testdata/project/dist/chart/templates/manager/manager.yaml Regenerates the getting-started chart.
docs/book/src/cronjob-tutorial/testdata/project/dist/chart/templates/manager/manager.yaml Regenerates the CronJob chart.
Review details
  • Files reviewed: 5/8 changed files
  • Comments generated: 0
  • Review effort level: Balanced

馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.


Setting `webhook.enabled=false` prevents the chart from rendering the webhook `Service`, admission webhook configurations, and `NetworkPolicy`. It does not prevent the scaffolded manager from registering its webhooks or starting its webhook server.

When `webhook.enabled=false`, the chart does not pass `--webhook-port` to the manager. The scaffolded manager therefore listens on its compiled default port, `9443`, regardless of `webhook.port`. The `Deployment` still declares `webhook.port` as the `webhook-server` container port, but this declaration does not configure the listener. With the controller-runtime version the scaffold currently pins, no `webhook.port` value disables the server.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@aiqubits could you please check in the latets CR release if we cannot set 0 as it is done for metrics?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@camilamacedo86 I checked controller-runtime v0.25.0. Port 0 still defaults to 9443, while Port -1 disables the webhook server: https://github.com/kubernetes-sigs/controller-runtime/blob/v0.25.0/pkg/webhook/server.go#L76-L80 and https://github.com/kubernetes-sigs/controller-runtime/blob/v0.25.0/pkg/webhook/server.go#L203-L206.

Kubebuilder still pins v0.24.1, so after the controller-runtime bump lands I will revise this PR to use --webhook-port=-1 and remove the envOverrides workaround.

@aiqubits

aiqubits commented Sep 4, 2026

Copy link
Copy Markdown
Author

@camilamacedo86 I confirmed that controller-runtime v0.25.0 supports disabling the webhook server with Port: -1. I agree that the version bump should land first; afterward, I will rework this PR to use --webhook-port=-1 and remove the envOverrides workaround.

@kubernetes-prow kubernetes-prow Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 9, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

helm/v2-alpha: webhook.enabled=false does not stop the manager's webhook server

4 participants