Repository navigation
feat(chart): add CRD upgrader hook - #199
Conversation
WalkthroughAdds a configurable pre-install/pre-upgrade Helm hook that stores bundled CRDs in a ConfigMap, grants narrowly scoped RBAC, and runs a hardened ChangesCRD upgrader hook
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Helm
participant CRDConfigMap
participant CRDUpgraderJob
participant KubernetesAPI
Helm->>CRDConfigMap: Render bundled CRDs
Helm->>CRDUpgraderJob: Run pre-install/pre-upgrade hook
CRDUpgraderJob->>KubernetesAPI: Apply CRDs server-side
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds a configurable pre-install/pre-upgrade Helm hook that stores bundled CRDs in a ConfigMap, grants narrowly scoped RBAC, and runs a hardened ChangesCRD upgrader hook
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Helm
participant CRDConfigMap
participant CRDUpgraderJob
participant KubernetesAPI
Helm->>CRDConfigMap: Render bundled CRDs
Helm->>CRDUpgraderJob: Run pre-install/pre-upgrade hook
CRDUpgraderJob->>KubernetesAPI: Apply CRDs server-side
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@charts/karta/templates/hooks/pre/crd-upgrader-job.yaml`:
- Line 34: Update the hook Job command in the pre-CRD upgrader manifest to use
the kubectl image’s actual executable path, /kubectl, or remove the command
override so the image entrypoint is used.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Enterprise
Run ID: b6de0ab2-521e-4907-9a05-84f1b06a2fad
📒 Files selected for processing (4)
charts/karta/templates/hooks/pre/crd-upgrader-configmap.yamlcharts/karta/templates/hooks/pre/crd-upgrader-job.yamlcharts/karta/templates/hooks/pre/crd-upgrader-rbac.yamlcharts/karta/values.yaml
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@Makefile`:
- Line 143: Update the CRD ConfigMap size-check recipe around the helm template
pipeline so Helm renders into a temporary file first, explicitly fails when helm
template returns a nonzero status, and only then measures the file size with wc.
Preserve the existing size-limit validation and error messaging, and clean up
the temporary file regardless of the render or size-check outcome.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
Helm applies files in crds/ only on first install and never upgrades them, so bumping the kartas.run.ai schema in a new release leaves existing clusters on the old CRD. Add a pre-install/pre-upgrade Job that runs kubectl apply --server-side --force-conflicts over the bundled CRD, so every helm upgrade rolls the schema forward and the Job takes field ownership from Helm's install-time apply. The CRD stays in crds/ (Helm still installs it on first install and never deletes it on uninstall, so user Kartas survive). The Job reads the CRD from a ConfigMap built with .Files.Get and runs a stock registry.k8s.io/kubectl image, so no custom image is needed. RBAC is a ServiceAccount plus a ClusterRole scoped by resourceNames to kartas.run.ai. All hook resources use hook-delete-policy hook-succeeded,before-hook-creation, which keeps repeated helm upgrade runs idempotent. Gated by crdUpgrader.enabled (default true), independent of operator.enabled so a CRD-only install still upgrades its CRD. helm-validate fails if the CRD ConfigMap grows past the ~1 MiB etcd object limit, so a too-large CRD is caught at PR time. Refs #43 Signed-off-by: aviadh <aviad.hayumi@gmail.com>
5a9c9b4 to
e5b34d6
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
charts/karta/templates/hooks/pre/crd-upgrader-rbac.yaml (1)
11-14: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick winAdd
hook-failedto the Job hook only.
hook-faileddeletes only the hook resource that fails. It cleans up a failedJob, but it does not delete the earlier successful ConfigMap or RBAC resources. Use a separate cleanup mechanism for failed-upgrade RBAC cleanup.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@charts/karta/templates/hooks/pre/crd-upgrader-rbac.yaml` around lines 11 - 14, Add hook-failed only to the Job hook annotations in charts/karta/templates/hooks/pre/crd-upgrader-job.yaml (lines 11-14). Leave the existing hook-delete-policy unchanged in charts/karta/templates/hooks/pre/crd-upgrader-rbac.yaml (lines 11-14) and charts/karta/templates/hooks/pre/crd-upgrader-configmap.yaml (lines 11-14); use a separate mechanism for failed-upgrade RBAC cleanup.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@charts/karta/templates/hooks/pre/crd-upgrader-rbac.yaml`:
- Line 23: Update the CRD upgrader RBAC resource name using a release- and
namespace-specific naming helper or values that include both release identity
and namespace, rather than the current karta.fullname expression. Apply the same
unique naming consistently to the related ClusterRole, ServiceAccount, and
ClusterRoleBinding references so each release binds only its own upgrader
account.
---
Nitpick comments:
In `@charts/karta/templates/hooks/pre/crd-upgrader-rbac.yaml`:
- Around line 11-14: Add hook-failed only to the Job hook annotations in
charts/karta/templates/hooks/pre/crd-upgrader-job.yaml (lines 11-14). Leave the
existing hook-delete-policy unchanged in
charts/karta/templates/hooks/pre/crd-upgrader-rbac.yaml (lines 11-14) and
charts/karta/templates/hooks/pre/crd-upgrader-configmap.yaml (lines 11-14); use
a separate mechanism for failed-upgrade RBAC cleanup.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Enterprise
Run ID: 1a7cb4d4-bff4-40ee-8f84-3d922fa89001
📒 Files selected for processing (5)
Makefilecharts/karta/templates/hooks/pre/crd-upgrader-configmap.yamlcharts/karta/templates/hooks/pre/crd-upgrader-job.yamlcharts/karta/templates/hooks/pre/crd-upgrader-rbac.yamlcharts/karta/values.yaml
🚧 Files skipped from review as they are similar to previous changes (2)
- Makefile
- charts/karta/values.yaml
karta.fullname ignores the release name and namespace, so the crd-upgrader ClusterRole and ClusterRoleBinding were named the same across releases. Two installs in different namespaces would collide on those cluster-scoped objects, and before-hook-creation could delete one release's RBAC and bind the wrong ServiceAccount. Suffix the ClusterRole and ClusterRoleBinding (and its roleRef) with .Release.Namespace so each install gets its own; the ServiceAccount stays namespaced. Refs #43 Signed-off-by: aviadh <aviad.hayumi@gmail.com>
The crd-upgrader hook resources were named from karta.fullname, which ignores the release name and namespace, so two releases could share the cluster-scoped ClusterRole and ClusterRoleBinding (and same-namespace releases the namespaced ones too). before-hook-creation could then delete one release's hook resources and rebind another's. Add a karta.crdUpgrader.name helper that folds in the release namespace and name, and use it for every hook resource (ServiceAccount, ConfigMap, Job, ClusterRole, ClusterRoleBinding, and their references) so each release gets its own set. Refs #43 Signed-off-by: aviadh <aviad.hayumi@gmail.com>
What does this PR do?
Helm applies the CRD under
crds/only on the firsthelm install, never onhelm upgrade. So once the chart is installed, bumping thekartas.run.aischema in a later release never reaches the cluster, and users hit a missing field with no error to explain it.This adds a
pre-install,pre-upgradeJob that runskubectl apply --server-side --force-conflictsover the bundled CRD, sohelm upgraderolls the schema forward.--force-conflictsis there so the Job can take the field manager over from Helm's install-time apply. The CRD still ships incrds/, so a fresh install gets it up front, and since Helm never deletescrds/CRDs on uninstall, existing Kartas survive an uninstall without aresource-policy: keepannotation.The Job reads the CRD from a ConfigMap (
.Files.Get) and runs the stockregistry.k8s.io/kubectlimage, so there is no custom image to build or publish.make helm-validate(run in CI) fails if that ConfigMap grows past ~1MB, so a CRD that would outgrow the etcd object limit is caught in review instead of at install. RBAC is a ServiceAccount plus a ClusterRole scoped byresourceNamestokartas.run.aiwithcreateandpatch. Gated bycrdUpgrader.enabled(default true), independent ofoperator.enabledso a CRD-only install still upgrades its CRD.Same approach as KAI-Scheduler, which ships the same hook. It bakes the CRDs into a dedicated image because its CRDs are large; ours is one ~110KB CRD so a ConfigMap is enough:
https://github.com/NVIDIA/KAI-Scheduler/blob/main/deployments/kai-scheduler/templates/hooks/pre/crd-upgrader.yaml
New files live under
charts/karta/templates/hooks/pre/, plus thecrdUpgraderblock incharts/karta/values.yaml.Testing
Ran it on kind: fresh install, upgrade rolls the schema forward (with the hook off it stays stale, which is the bug), installed real Kartas from
docs/catalog/and upgraded the CRD while they were live (they survive with the same uid,storedVersionsunchanged), the--skip-crdscreate path, and uninstall keeps the CRD.make checkpasses.Related issue(s)
Fixes #43
Checklist
git commit -s)make check)Summary by CodeRabbit
New Features
Bug Fixes
Chores