Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

camilamacedo86
Copy link
Member

@camilamacedo86 camilamacedo86 commented Aug 27, 2025

Introduce helm/v2-alpha Plugin: Dynamic Helm Chart Generation

This PR introduces a completely rewritten Helm plugin (helm/v2-alpha) that dynamically generates Helm charts based on the actual kustomize output from make build-installer, replacing the previous hardcoded template approach in helm/v1-alpha.

The existing helm/v1-alpha plugin used static templates that didn't reflect user customizations (environment variables, labels, annotations, security contexts, etc.) made in their kustomize configuration. This led to inconsistencies between kubectl apply -f dist/install.yaml and helm install.

Key Features

  • Dynamic generation: Charts generated from actual kustomize output (dist/install.yaml)
  • Smart organization: Resources split into logical directories (metrics/, webhook/, cert-manager/, rbac/, crd/)
  • Conditional logic: Only includes resources that actually exist (certManager, webhooks, metrics)
  • Individual files: CRDs, RBAC, and certificates as separate files for better maintainability
  • Enhanced values.yaml: Dynamic configuration based on detected project features

Changes

  • Deprecated Helm v1-alpha in favour of v2
  • Add docs and tests for Helm v2
  • Update all samples
  • Address all feedback raised so far

Documentation

📖 Preview docs: https://deploy-preview-5058--kubebuilder.netlify.app/plugins/available/helm-v2-alpha

How to Review

  • Documentation: Check the docs link above for complete feature overview
  • Core implementation: Focus on pkg/plugins/optional/helm/v2alpha/ for the actual code changes
  • File changes context: Most changes under testdata/ and docs/ are sample updates with helm/v2-alpha
  • Test coverage: Comprehensive unit tests added with GitHub workflow integration for e2e testing via Prow
  • Play with in your solutions 🙏

Usage

# Generate Helm chart from kustomize output
kubebuilder edit --plugins=helm.kubebuilder.io/v2-alpha

# Custom output directory  
kubebuilder edit --plugins=helm.kubebuilder.io/v2-alpha --output=charts

Closes:

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 27, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: camilamacedo86

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

The pull request process is described here

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 27, 2025
@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Aug 27, 2025
@camilamacedo86 camilamacedo86 force-pushed the helm-change-manager branch 7 times, most recently from cb1ee39 to 1acfef2 Compare August 28, 2025 09:58
@camilamacedo86 camilamacedo86 changed the title WIP Add helm/v2-alpha and deprecated helm/v1-alpha ✨ Add helm/v2-alpha addressing all feedbacks and lessons learned. Deprecated helm/v1-alpha in favor of helm/v2-alpha Aug 28, 2025
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 28, 2025
@camilamacedo86 camilamacedo86 force-pushed the helm-change-manager branch 2 times, most recently from d9d172d to 2a5c5be Compare August 28, 2025 10:48
@camilamacedo86 camilamacedo86 changed the title ✨ Add helm/v2-alpha addressing all feedbacks and lessons learned. Deprecated helm/v1-alpha in favor of helm/v2-alpha WIP ✨ Add helm/v2-alpha addressing all feedbacks and lessons learned. Deprecated helm/v1-alpha in favor of helm/v2-alpha Aug 28, 2025
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 28, 2025
@camilamacedo86 camilamacedo86 force-pushed the helm-change-manager branch 4 times, most recently from 8203eed to 1cb0ec1 Compare August 29, 2025 18:18
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 29, 2025
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 29, 2025
@camilamacedo86 camilamacedo86 force-pushed the helm-change-manager branch 3 times, most recently from 16b3fca to 1863d2e Compare August 31, 2025 00:57
@mkarlheim
Copy link

Hi @mkarlheim

The chart. labels were added 👍 to allow adding extra labels. However, note that these are the labels defined in Kustomize, and we should retain them. The goal of Helm charts is to package the solution, so the labels should be identical.

Regards the CRDs, see:

Although Helm best practices recommend placing CRDs under a top-level crds/ directory, the Kubebuilder Helm plugin intentionally places them under templates/crd.**

This was a conscious design decision aafter lengthydiscussions in the design proposal and community threads (Slack discussion link).

The reason: CRDs in crds/ are not upgraded by Helm. Keeping them under templates/ ensures CRDs are correctly managed and updated together with releases, avoiding drift. While this means you cannot bundle custom resources directly in the chart (a current Helm limitation), it provides a more straightforward and more reliable workflow for projects generated by Kubebuilder. See; #3632 (comment)

Alternatively, here we could create a chart only for the CRDs, such as a two-chart flow (API first, then operator/app), with a simple readiness/wait check. However, if we change it, it would be better in a follow-up discussion where we can address it. Let's keep the cards under the templates, which is the most adopted approach.

Thanks for clarifying.

@tchinmai7
Copy link

tchinmai7 commented Sep 11, 2025

This looks great!. the new plugin's chart output is close to kustomize. The managed-by label is rightly pointing to helm now, and only the namespace resource is missing - which is ok, helm charts can be installed with the --create-namespace option. Thank you for working on this!

@camilamacedo86
Copy link
Member Author

Hey

@tchinmai7 @bavarianbidi @calind @vaidikcode @mkarlheim @abhijith-darshan @klaudworks @FishyFishPat @pabhi18

I would like to ask your help on reviews and I would appreciate LGTMs if you are satisfied with the proposed changes .. Really thank you for your interest on this one and all your collab !!!

It would be great if we could delivery it with the next release

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 13, 2025
@abhijith-darshan
Copy link

abhijith-darshan commented Sep 13, 2025

Hey

@tchinmai7 @bavarianbidi @calind @vaidikcode @mkarlheim @abhijith-darshan @klaudworks @FishyFishPat @pabhi18

I would like to ask your help on reviews and I would appreciate LGTMs if you are satisfied with the proposed changes .. Really thank you for your interest on this one and all your collab !!!

It would be great if we could delivery it with the next release

Hey @camilamacedo86,

Thank you so much for this amazing implementation 🚀

Building the binary from source camilamacedo86:helm-change-manager and using it to generate charts -

  • changes to kustomize manifest is reflected on to chart templates (solves the original issue I opened) 🎉
  • tested with basic controller, admission webhooks and conversion webhook 👍

However I see one improvement necessary -

The args for controller-manager container needs to be templated and available in values.yaml (with defaults or empty [ ] )
Otherwise it won't be possible to dynamically include args.

Currently only static values in the manifest is carried over to the manager.yaml in chart/templates

## Helm template manager.yaml
      containers:
      - command:
        - /manager
        args:
          - --leader-elect
          - --health-probe-bind-address=:8081
          - --leader-lease-duration=15s
          - --leader-renew-timeout=10s
          - --leader-retry-period=2s
        image: controller:latest
        name: manager

Instead it can be something like this -

## Helm template manager.yaml
        spec:
            containers:
                - args:
                    - --metrics-bind-address=:8443
                    - --health-probe-bind-address=:8081
                    {{- range .Values.controllerManager.args }}
                    - {{ . }}
                    {{- end }}
                    {{- if .Values.certManager.enable }}
                    - --webhook-cert-path=/tmp/k8s-webhook-server/serving-certs
                    {{- end }}
...

values.yaml

# Configure the controller manager deployment
controllerManager:
  replicas: 1
  args:
    - --leader-elect
    - --leader-lease-duration=15s
    - --leader-renew-timeout=10s
    - --leader-retry-period=2s

@camilamacedo86
Copy link
Member Author

HI @abhijith-darshan

The args might be a good thought, but I think we could check this one in a follow-up, wdyt?

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 14, 2025
@abhijith-darshan
Copy link

abhijith-darshan commented Sep 14, 2025

HI @abhijith-darshan

The args might be a good thought, but I think we could check this one in a follow-up, wdyt?

Sure. Once this is in, I can contribute towards enhancements as well, thanks.

For now, LGTM 🚀

@camilamacedo86
Copy link
Member Author

/retest-required

@camilamacedo86 camilamacedo86 force-pushed the helm-change-manager branch 2 times, most recently from c37628c to 99911fe Compare September 19, 2025 12:19
Comment on lines +58 to +59
return "helm/v1-alpha plugin is deprecated, use helm/v2-alpha instead which " +
"provides dynamic Helm chart generation from kustomize output"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: could we have a single string here instead of concatenation?

Copy link
Member Author

Choose a reason for hiding this comment

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

That would cause the lint check lll fail

return nil
}

const helmHelpersTemplate = `{{` + "`" + `{{/*
Copy link
Contributor

Choose a reason for hiding this comment

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

for the future maintenance, would it helpful to move this and similar content into standalone files and use go:embed directive to access it?

Copy link
Member Author

Choose a reason for hiding this comment

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

All templates in Kubebuilder are currently done this way. I might not have fully understood the reasoning, but if we decide to change the approach, it would probably make sense to update all places consistently. That said, we’re always open to ideas—feel free to open a PR to propose the change and demonstrate what it would look like.

Comment on lines 190 to 192
# kubectl wait --namespace cert-manager --for=condition=available --timeout=300s deployment/cert-manager
# kubectl wait --namespace cert-manager --for=condition=available --timeout=300s deployment/cert-manager-cainjector
# kubectl wait --namespace cert-manager --for=condition=available --timeout=300s deployment/cert-manager-webhook`
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can get incorporate this waiting into the previous helm install step by doing something like:

helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --set crds.enabled=true --wait --timeout 300s
#

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems a good idea. 🚀

@camilamacedo86
Copy link
Member Author

/test pull-kubebuilder-e2e-k8s-1-33-0

…`) that dynamically generates Helm charts based on the actual kustomize output from `make build-installer`, replacing the previous hardcoded template approach in `helm/v1-alpha`.

The existing `helm/v1-alpha` plugin used static templates that didn't reflect user customizations (environment variables, labels, annotations, security contexts, etc.) made in their kustomize configuration. This led to inconsistencies between `kubectl apply -f dist/install.yaml` and `helm install`.

- Deprecated Helm v1-alpha in favour of v2
- Add docs and tests for Helm v2
- Update all samples
- Address all feedbacks raised so far

Assisted-by: OpenAI
@camilamacedo86
Copy link
Member Author

We have enough reviews/lgtm so far
Also, to allow contributions on top of those changes we need get this one merged
So, I am letting it move forward.
We have up to the next release to enhance or change what might be required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants