Automatic CRD Upgrades in VirtRigaud Helm Chart¶
Overview¶
The VirtRigaud Helm chart applies its CRDs on helm install and helm upgrade with a hook Job, so you do not manage CRDs by hand. Helm itself never upgrades CRDs from a chart's crds/ directory; this hook closes that gap.
Upgrading from v0.4.1 to v0.4.2
v0.4.2 adds one optional VirtualMachine status field, status.placement.resizeReservation, so the CRDs must be applied before the new manager starts: the new manager fails readiness against the v0.4.1 CRD. The chart's pre-upgrade hook does this. Upgrade with --reset-then-reuse-values and override any image tag you pinned, or the manager and the hook can stay on older images. See What changes on upgrade from v0.4.1 to v0.4.2 and the Upgrade Guide.
Upgrading from v0.4.0 to v0.4.1
v0.4.1 has no CRD schema change (only the description texts of the CRDs differ, so kubectl explain shows corrected text) and no RBAC or values.yaml change beyond comments. The roll order is the same (CRDs, manager, providers), and helm upgrade --version 0.4.1 re-tags the images. See What changes on upgrade from v0.4.0 to v0.4.1, and the Upgrade Guide for the actions it needs before you roll the Proxmox and libvirt providers.
Upgrading from v0.3.11
v0.4.0 has a required order (CRDs, then cross-namespace grants, then the manager, then the providers) and several breaking changes. Read the Upgrade Guide and the release notes before running helm upgrade.
What changes on upgrade from v0.4.1 to v0.4.2¶
- CRDs: one additive, optional status field on
VirtualMachine,status.placement.resizeReservation(a{cpu, memoryMiB}footprint used for clustered resizes). No other schema change, and existing objects need no migration. The chart still ships all 12 CRDs. - Chart: the manager Deployment passes
--client-qpsand--client-burstfrom the new valuesmanager.clientQPS(default 20) andmanager.clientBurst(default 40), the same limits as before; a zero, negative or non-numeric value fails the render. Nothing else in the templates changed. - kubectl image of the CRD hook:
ghcr.io/projectbeskar/virtrigaud/kubectl:v0.4.2, the upstreamkubectl1.35.10 binary on Alpine 3.24 (was 1.35.9). Its remaining scanner findings are listed in Security. - Order: the hook applies the CRDs before the manager rolls. If you apply CRDs yourself, apply the v0.4.2 CRDs first. A rollback does not run the hook, so the newer CRD stays installed; a v0.4.1 manager works with it (see Rolling back to v0.4.1).
helm get values virtrigaud -n virtrigaud-system # look for pinned image tags first
helm upgrade virtrigaud virtrigaud/virtrigaud --version 0.4.2 \
-n virtrigaud-system --reset-then-reuse-values
What changes on upgrade from v0.4.0 to v0.4.1¶
- CRDs: no schema change. The 12 CRDs differ from v0.4.0's only in
descriptiontexts (fields that nothing acts on now say "Accepted but not acted on in this release.", status fields no controller writes say "Not populated in this release."). One new condition reason,RevertNotPerformed, is a Go constant with no schema effect. Applying the CRDs is safe at any point. - Chart: with
webhooks.enabled=truethe chart renders one more validating webhook entry,vvmclone-customization.kb.io(failure policy alwaysIgnore, timeout 5s), which only returns an admission warning when aVMClonesets a customization field that may hold a secret.config/webhookfor Kustomize gains it too. Nothing else in the templates changed. - kubectl image of the CRD hook: updated to kubectl 1.35.9 on Alpine 3.24 (was 1.32.0 on 3.20), which cuts the HIGH and CRITICAL image-scan findings that have a fix from 37 to 6.
virtrigaud-provider-runtimechart: deprecated and removed in the next minor release. It was never published to the Helm repository; see the Upgrade Guide.
What changes on upgrade from v0.3.11 to v0.4.0¶
The CRD-upgrade hook applies these changes when you upgrade from v0.3.11 with helm upgrade ... --version 0.4.2 (they are the changes of v0.4.0; v0.4.1 adds no schema change, and v0.4.2 adds status.placement.resizeReservation):
- New CRDs:
hosts.infra.virtrigaud.ioandhostpools.infra.virtrigaud.io(clustered libvirt providers). The chart now installs 12 CRDs. spec.consumerNamespaceSelectoronProvider,VMClassandVMImage. A reference to one of these in another namespace is refused (ConsumerNotAllowed) unless this field selects the referencing namespace.VirtualMachine:status.boundProvider,status.placement(clustered placement),status.snapshotRevert(snapshot revert), theSuspendedandUnknownvalues ofstatus.powerState, and an admission rule that makesspec.providerRefimmutable once the VM is bound.Provider:spec.topology(singleorcluster),status.reportedCapabilities.supportsHonestReconfigureandsupportsImageArtifactIdentity, and immutablespec.typeandspec.topology(CEL rules).VMImage:status.providerStatus["<namespace>/<name>"]gainsproviderUID,sourceDigestandtaskRef(prepare state is now per Provider).VMMigration:status.targetVMUID,status.targetVMClaim,status.sourceVMUID,status.storagePVCUID, andstatus.storageInfo.importTarget,stagingDigestandstagingLayout;spec.importedDiskaccepts an emptydiskIDwhilemigrationRefis set (migration into a clustered Provider).VMClone:status.targetUID.VMSnapshot:status.boundProviderandstatus.vmUID.- New RBAC rules for the manager:
geton thevirtualmachines,providers,vmclasses,vmimagesandvmsnapshotsCRDs,get;list;watchonnamespaces, andget;patch;updateonhostpools/status. The chart applies them with the manager; a Kustomize install must reapplyconfig/rbac/role.yaml.
No field is removed. The admission rules (spec.providerRef and spec.type immutability) can reject updates that earlier releases accepted; see the Upgrade Guide. Existing VirtualMachine, Provider, VMSnapshot and VMMigration resources are kept.
Order matters: set consumerNamespaceSelector before the new manager runs
The new manager fails closed on cross-namespace references. If any VirtualMachine, VMClone or VMMigration uses a Provider, VMClass or VMImage from another namespace, apply the new CRDs first, set spec.consumerNamespaceSelector on those objects, and only then roll the manager. The field does not exist until the CRDs are upgraded, and the helm hook applies the CRDs in the same helm upgrade that rolls the manager. Apply the CRDs yourself first:
kubectl apply --server-side --force-conflicts -f config/crd/bases # from the v0.4.2 release checkout
# set spec.consumerNamespaceSelector on the shared objects, then:
helm upgrade virtrigaud virtrigaud/virtrigaud --version 0.4.2 -n virtrigaud-system --reset-then-reuse-values
The manager's readiness probe fails while the VirtualMachine, Provider, VMClass or VMImage CRD lacks a field it needs, so helm upgrade --wait times out instead of running against an old schema.
Carry custom values with --reset-then-reuse-values
--reuse-values reuses the old chart's defaults, so settings added in a newer chart are missing and old defaults linger. Use --reset-then-reuse-values (Helm 3.14+), which applies the new chart's defaults and then your own values.
The Problem¶
By default, Helm has a limitation: - CRDs are installed during helm install - CRDs are NOT upgraded during helm upgrade
This means users had to manually apply CRD updates before upgrading, which was: - Error-prone - Easy to forget - Breaks GitOps workflows - Causes version drift between chart and CRDs
The Solution¶
VirtRigaud uses Helm Hooks with a Kubernetes Job to automatically apply CRDs during both install and upgrade:
kubectl Image¶
VirtRigaud builds and publishes its own kubectl image as part of the release process. This image:
- Based on Alpine Linux for minimal size (~50MB)
- Includes the kubectl binary from official Kubernetes releases (1.35.10 on Alpine 3.24 in v0.4.2; 1.35.9 in v0.4.1; 1.32.0 on Alpine 3.20 before)
- Includes bash and shell for scripting support
- Runs as non-root user (UID 65532)
- Verified with SHA256 checksums
- Signed with Cosign and includes SBOM
- Security scanned but uses official kubectl binary (vulnerabilities tracked upstream)
The image is automatically built and tagged to match each VirtRigaud release version, ensuring version consistency across all components.
Image Location: ghcr.io/projectbeskar/virtrigaud/kubectl:<version>
How It Works¶
- Pre-Upgrade Hook: Before the main upgrade starts, a Job is created
- CRD Application: The Job applies all CRDs using
kubectl apply --server-side - Safe Upgrades: Server-side apply handles conflicts gracefully
- Automatic Cleanup: Job is deleted after successful completion
Architecture¶
helm upgrade virtrigaud
↓
[Pre-Upgrade Hook -10]
↓
ConfigMap with CRDs created
↓
[Pre-Upgrade Hook -5]
↓
ServiceAccount + RBAC created
↓
[Pre-Upgrade Hook 0]
↓
Job applies CRDs via kubectl
↓
[Standard Helm Resources]
↓
Manager & Providers deployed
↓
[Hook Cleanup]
↓
Job & Hook resources deleted
Features¶
Enabled by Default¶
No configuration needed - just works:
Server-Side Apply¶
Uses kubectl apply --server-side for: - Safe conflict resolution - Field management - No ownership conflicts
GitOps Compatible¶
Works seamlessly with: - ArgoCD: Helm hooks execute properly - Flux: Compatible with HelmRelease CRD upgrades - Terraform: Helm provider handles hooks
Configurable¶
Customize the upgrade behavior:
crdUpgrade:
enabled: true # Enable/disable automatic upgrades
image:
repository: ghcr.io/projectbeskar/virtrigaud/kubectl # VirtRigaud kubectl image
tag: "v0.4.2" # Set by the release to match the VirtRigaud version
backoffLimit: 3
ttlSecondsAfterFinished: 300
waitSeconds: 5
resources:
limits:
cpu: 100m
memory: 128Mi
Usage Examples¶
Standard Upgrade (Automatic CRDs)¶
# CRDs are automatically upgraded
helm upgrade virtrigaud virtrigaud/virtrigaud \
-n virtrigaud-system
Disable Automatic CRD Upgrade¶
# Disable if you manage CRDs separately
helm upgrade virtrigaud virtrigaud/virtrigaud \
-n virtrigaud-system \
--set crdUpgrade.enabled=false
Manual CRD Management¶
# Apply CRDs manually before upgrade
kubectl apply -f charts/virtrigaud/crds/
# Then upgrade without CRD management
helm upgrade virtrigaud virtrigaud/virtrigaud \
-n virtrigaud-system \
--set crdUpgrade.enabled=false
Skip CRDs Entirely¶
# Skip CRDs during upgrade (for external CRD management)
helm upgrade virtrigaud virtrigaud/virtrigaud \
-n virtrigaud-system \
--skip-crds \
--set crdUpgrade.enabled=false
GitOps Integration¶
ArgoCD¶
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: virtrigaud
spec:
source:
chart: virtrigaud
targetRevision: 0.4.2
helm:
values: |
crdUpgrade:
enabled: true # Automatic upgrades work!
syncPolicy:
automated:
prune: true
selfHeal: true
Note: ArgoCD executes Helm hooks properly, so CRDs will be upgraded automatically.
Flux¶
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: virtrigaud
spec:
chart:
spec:
chart: virtrigaud
version: 0.4.2
values:
crdUpgrade:
enabled: true # Automatic upgrades work!
install:
crds: CreateReplace
upgrade:
crds: CreateReplace
Note: Flux's crds: CreateReplace works alongside our hook-based upgrades for maximum compatibility.
Troubleshooting¶
Check CRD Upgrade Job¶
# View job status
kubectl get jobs -n virtrigaud-system -l app.kubernetes.io/component=crd-upgrade
# View job logs
kubectl logs -n virtrigaud-system -l app.kubernetes.io/component=crd-upgrade
# View job details
kubectl describe job -n virtrigaud-system -l app.kubernetes.io/component=crd-upgrade
Known Issue: Empty crds/ Directory when Building from Source¶
H2: BackoffLimitExceeded on the CRD-upgrade-job when installing from a source checkout
The charts/virtrigaud/crds/ directory in the git repository contains only a .gitkeep placeholder. The actual CRD YAML files are not committed to git — they are generated at build time by make gen-helm-crds.
Symptom: The CRD-upgrade-job starts, applies an empty ConfigMap, and exits without error, but kubectl get crd shows no VirtRigaud CRDs. Or, if the job runs before the CRDs exist at all, it may reach BackoffLimitExceeded.
Workaround: Install from the published Helm chart rather than rebuilding from source:
helm repo add virtrigaud https://projectbeskar.github.io/virtrigaud
helm repo update
helm install virtrigaud virtrigaud/virtrigaud \
--version 0.4.2 \
--namespace virtrigaud-system \
--create-namespace
If you must install from a source checkout, run make gen-helm-crds first to populate charts/virtrigaud/crds/:
# From the virtrigaud source root
make gen-helm-crds
# Verify the CRD files are populated
ls charts/virtrigaud/crds/
# Now install or upgrade
helm install virtrigaud ./charts/virtrigaud -n virtrigaud-system
Status: Tracked as project issue H2. The published chart at https://projectbeskar.github.io/virtrigaud always includes the CRD files and is not affected.
Common Issues¶
1. RBAC Permissions¶
Symptom: Job fails with "forbidden" errors
Solution: Ensure the ServiceAccount has CRD permissions:
kubectl get clusterrole -l app.kubernetes.io/component=crd-upgrade
kubectl describe clusterrole <role-name>
2. Image Pull Failures¶
Symptom: Job fails to start, ImagePullBackOff
Solution: Check image configuration:
crdUpgrade:
image:
repository: ghcr.io/projectbeskar/virtrigaud/kubectl
tag: "v0.4.2" # Use matching VirtRigaud version
pullPolicy: IfNotPresent
3. CRD Conflicts¶
Symptom: Apply errors about field conflicts
Solution: Server-side apply handles this automatically, but you can force:
4. Job Not Cleaning Up¶
Symptom: Old jobs remain after upgrade
Solution: Adjust TTL or manually clean:
Debug Mode¶
Enable verbose logging:
Migration Guide¶
Migrating from Manual CRD Management¶
If you were previously managing CRDs manually:
-
Enable automatic upgrades:
-
Verify CRDs are upgraded:
-
Remove manual steps from your upgrade process
Migrating to External CRD Management¶
If you want to manage CRDs externally (e.g., separate Helm chart):
-
Disable automatic upgrades:
-
Extract CRDs:
-
Manage CRDs separately:
Technical Details¶
Hook Weights¶
The upgrade process uses weighted hooks for proper ordering:
| Weight | Resource | Purpose |
|---|---|---|
-10 | ConfigMap | Store CRD content |
-5 | RBAC | Create permissions |
0 | Job | Apply CRDs |
Resource Requirements¶
The CRD upgrade job is lightweight:
Security¶
- Runs as non-root user (65532)
- Read-only root filesystem
- No privilege escalation
- Minimal RBAC (only CRD permissions)
- Automatic cleanup after completion
Compatibility¶
- Kubernetes: 1.25+
- Helm: 3.8+
- kubectl: 1.24+ (in Job image)
Best Practices¶
- Use Automatic Upgrades: Enable by default for best UX
- Monitor Job Logs: Check logs during first upgrade
- Test in Dev First: Verify upgrades in non-production
- Backup CRDs: Keep backups before major upgrades
- Review Changelogs: Check for breaking CRD changes
FAQ¶
Q: Will this delete my existing resources?¶
A: No. CRD upgrades are additive and preserve existing Custom Resources.
Q: What happens if the job fails?¶
A: Helm upgrade will fail, leaving your cluster in the previous state. Fix the issue and retry.
Q: Can I use this with ArgoCD?¶
A: Yes! ArgoCD properly executes Helm hooks.
Q: Does this work with Flux?¶
A: Yes! Flux HelmRelease handles hooks correctly.
Q: How do I roll back?¶
A: Use helm rollback. CRDs are not rolled back, and rolling the manager back has side effects (for example a Provider deleted afterwards keeps its in-use finalizer). Read the rollback caveats in the Upgrade Guide first.
Q: Can I customize the kubectl image?¶
A: Yes, via crdUpgrade.image.repository and crdUpgrade.image.tag. The default is VirtRigaud's own ghcr.io/projectbeskar/virtrigaud/kubectl image, whose tag the release sets to the VirtRigaud version.