-
Notifications
You must be signed in to change notification settings - Fork 156
enable CRD upgrades via Helm with feature flags #2809
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
Merged
+4,161
−13
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
727d7c5
enables crd upgrades via Helm with feature flags
ChrisJBurns df0470d
bumps chart
ChrisJBurns 0948f44
Merge branch 'main' into wrap-crds
ChrisJBurns 9274af0
Merge branch 'main' into wrap-crds
ChrisJBurns 5269ff1
Update cmd/thv-operator/Taskfile.yml
ChrisJBurns 489f6b9
adds docs and fixes error paths in wrapper tool
ChrisJBurns 6c0bcbd
Merge branch 'main' into wrap-crds
ChrisJBurns b2b46fb
Merge branch 'main' into wrap-crds
ChrisJBurns 446c2b4
updates crds
ChrisJBurns 809f900
Merge branch 'main' into wrap-crds
ChrisJBurns 774b1cd
updates crds
ChrisJBurns 4caf5c9
bumps chart
ChrisJBurns File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,3 +41,5 @@ cmd/thv-operator/.task/checksum/crdref-gen | |
|
|
||
| # Test coverage | ||
| coverage* | ||
|
|
||
| crd-helm-wrapper | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| # CRD Helm Wrapper | ||
|
|
||
| A Go tool that wraps Kubernetes CRD YAML files with Helm template conditionals for: | ||
| - **Feature flags** (`crds.install.server`, `crds.install.registry`, `crds.install.virtualMcp`) | ||
| - **Resource policy annotations** (`crds.keep` → `helm.sh/resource-policy: keep`) | ||
|
|
||
| ## Why This Tool? | ||
|
|
||
| Helm does not upgrade CRDs during `helm upgrade` operations. CRDs placed in the `crds/` directory are only processed during initial installation. By placing CRDs in `templates/` with conditionals, they are upgraded alongside the chart. | ||
|
|
||
| Raw CRDs generated by `controller-gen` don't have Helm templating. This tool wraps them with conditionals so users can: | ||
| - Enable/disable specific CRD groups via feature flags | ||
| - Prevent Helm from deleting CRDs on uninstall | ||
|
|
||
| ## Usage | ||
|
|
||
| ```bash | ||
| # Run the tool | ||
| go run main.go \ | ||
| -source ../files/crds \ | ||
| -target ../templates \ | ||
| -verbose | ||
| ``` | ||
|
|
||
| ## Flags | ||
|
|
||
| | Flag | Description | Required | | ||
| |------|-------------|----------| | ||
| | `-source` | Source directory containing raw CRD YAML files | Yes | | ||
| | `-target` | Target directory for wrapped Helm templates | Yes | | ||
| | `-verbose` | Enable verbose output | No | | ||
|
|
||
| ## Feature Flag Groups | ||
|
|
||
| CRDs are grouped by feature flags. Some CRDs belong to multiple groups: | ||
|
|
||
| | Flag | CRDs | | ||
| |------|------| | ||
| | `crds.install.server` | mcpservers, mcpremoteproxies, mcptoolconfigs, mcpgroups | | ||
| | `crds.install.registry` | mcpregistries | | ||
| | `crds.install.virtualMcp` | virtualmcpservers, virtualmcpcompositetooldefinitions | | ||
| | `crds.install.server` OR `crds.install.virtualMcp` | mcpexternalauthconfigs (shared) | | ||
|
|
||
| ## Output Format | ||
|
|
||
| For single-flag CRDs: | ||
|
|
||
| ```yaml | ||
| {{- if .Values.crds.install.server }} | ||
| apiVersion: apiextensions.k8s.io/v1 | ||
| kind: CustomResourceDefinition | ||
| metadata: | ||
| annotations: | ||
| {{- if .Values.crds.keep }} | ||
| helm.sh/resource-policy: keep | ||
| {{- end }} | ||
| controller-gen.kubebuilder.io/version: v0.17.3 | ||
| name: mcpservers.toolhive.stacklok.dev | ||
| spec: | ||
| ... | ||
| {{- end }} | ||
| ``` | ||
|
|
||
| For shared CRDs (multiple groups): | ||
|
|
||
| ```yaml | ||
| {{- if or .Values.crds.install.server .Values.crds.install.virtualMcp }} | ||
| apiVersion: apiextensions.k8s.io/v1 | ||
| kind: CustomResourceDefinition | ||
| metadata: | ||
| annotations: | ||
| {{- if .Values.crds.keep }} | ||
| helm.sh/resource-policy: keep | ||
| {{- end }} | ||
| controller-gen.kubebuilder.io/version: v0.17.3 | ||
| name: mcpexternalauthconfigs.toolhive.stacklok.dev | ||
| spec: | ||
| ... | ||
| {{- end }} | ||
| ``` | ||
|
|
||
| ## Values Configuration | ||
|
|
||
| The wrapped CRDs expect these values: | ||
|
|
||
| ```yaml | ||
| crds: | ||
| # Whether to add the "helm.sh/resource-policy: keep" annotation | ||
| keep: true | ||
| # Feature flags for CRD groups | ||
| install: | ||
| server: true | ||
| registry: true | ||
| virtualMcp: true | ||
| ``` | ||
|
|
||
| ## Template Escaping | ||
|
|
||
| CRD descriptions may contain Go template-like syntax (e.g., `{{.steps.step_id.output}}`). The tool automatically escapes these to prevent Helm from interpreting them as template directives. | ||
|
|
||
| ## Template Files | ||
|
|
||
| The tool uses embedded template files in the `templates/` directory: | ||
|
|
||
| | File | Purpose | | ||
| |------|---------| | ||
| | `header.tpl` | Opening conditional with `__FEATURE_CONDITION__` placeholder | | ||
| | `footer.tpl` | Closing `{{- end }}` | | ||
| | `keep-annotation.tpl` | Conditional `helm.sh/resource-policy: keep` annotation | | ||
|
|
||
| ## Adding New CRD Groups | ||
|
|
||
| To add a new feature flag group, update the `crdFeatureFlags` map in `main.go`: | ||
|
|
||
| ```go | ||
| var crdFeatureFlags = map[string][]string{ | ||
| "newcrdtype": {"newFeature"}, | ||
| // For shared CRDs: | ||
| "sharedcrd": {"server", "newFeature"}, | ||
| } | ||
| ``` | ||
|
|
||
| Then add the corresponding value to `values.yaml`. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.