From 6cbc2c1b5745361e73a21376a2b4207cfb19c113 Mon Sep 17 00:00:00 2001 From: Martin Jackson Date: Thu, 12 Nov 2026 13:09:59 -0600 Subject: [PATCH 1/3] Allow setting storageclass on external data volumes --- Chart.yaml | 2 +- README.md | 3 +- README.md.gotmpl | 1 + templates/external-data-volumes.yaml | 1 + tests/external-data-volumes_test.yaml | 79 +++++++++++++++++++++++++++ values.yaml | 3 + 6 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 tests/external-data-volumes_test.yaml diff --git a/Chart.yaml b/Chart.yaml index 6519a18..e99ff8c 100644 --- a/Chart.yaml +++ b/Chart.yaml @@ -2,5 +2,5 @@ apiVersion: v2 name: edge-gitops-vms description: Edge GitOps VMs type: application -version: 0.5.3 +version: 0.5.4 dependencies: [ ] diff --git a/README.md b/README.md index cbb3731..d8f8638 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # edge-gitops-vms -![Version: 0.5.3](https://img.shields.io/badge/Version-0.5.3-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) +![Version: 0.5.4](https://img.shields.io/badge/Version-0.5.4-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) Edge GitOps VMs @@ -8,6 +8,7 @@ This chart is used to set up Edge GitOps VMs in conjunction with OpenShift Virtu ### Notable changes +* v0.5.4: Allow setting dataSource storageclass, defaulting to vmDefault or one set by the edv object. * v0.5.3: Extend set-default-virt-storageclass job to wait until VM DataSources are Ready and their CSI driver/provisioner matches vmDefaults.storageClassName (prevents CDI host-assisted clone fallback onto the wrong StorageClass) * v0.5.2: Add optional additionalPvcDisks with default PVC creation; set create: false to attach existing PVCs * v0.5.1: Add optional job to set the default KubeVirt storage class from vmDefaults.storageClassName diff --git a/README.md.gotmpl b/README.md.gotmpl index 0c42592..dee4957 100644 --- a/README.md.gotmpl +++ b/README.md.gotmpl @@ -9,6 +9,7 @@ This chart is used to set up Edge GitOps VMs in conjunction with OpenShift Virtu ### Notable changes +* v0.5.4: Allow setting dataSource storageclass, defaulting to vmDefault or one set by the edv object. * v0.5.3: Extend set-default-virt-storageclass job to wait until VM DataSources are Ready and their CSI driver/provisioner matches vmDefaults.storageClassName (prevents CDI host-assisted clone fallback onto the wrong StorageClass) * v0.5.2: Add optional additionalPvcDisks with default PVC creation; set create: false to attach existing PVCs * v0.5.1: Add optional job to set the default KubeVirt storage class from vmDefaults.storageClassName diff --git a/templates/external-data-volumes.yaml b/templates/external-data-volumes.yaml index df23c39..8d8aac5 100644 --- a/templates/external-data-volumes.yaml +++ b/templates/external-data-volumes.yaml @@ -31,6 +31,7 @@ spec: resources: requests: storage: {{ $edv.size }} + storageClassName: {{ coalesce $edv.storageClassName $def.storageClassName }} {{- end }} --- apiVersion: cdi.kubevirt.io/v1beta1 diff --git a/tests/external-data-volumes_test.yaml b/tests/external-data-volumes_test.yaml new file mode 100644 index 0000000..42f131c --- /dev/null +++ b/tests/external-data-volumes_test.yaml @@ -0,0 +1,79 @@ +--- +suite: external-data-volumes +templates: + - templates/external-data-volumes.yaml +release: + name: test + namespace: gitops-vms +tests: + - it: defaults the DataVolume storageClassName to vmDefaults + set: + externalDataSources: + - name: quay-windows + type: registry + url: "docker://quay.io/eduffy/win2k22-dv:thin" + size: 50G + documentSelector: + path: kind + value: DataVolume + asserts: + - equal: + path: metadata.name + value: quay-windows + - equal: + path: spec.storage.storageClassName + value: ocs-storagecluster-ceph-rbd-virtualization + + - it: lets each externalDataSource override the storageClassName + set: + externalDataSources: + - name: quay-windows + type: registry + url: "docker://quay.io/eduffy/win2k22-dv:thin" + size: 50G + storageClassName: gp3-csi + documentSelector: + path: kind + value: DataVolume + asserts: + - equal: + path: spec.storage.storageClassName + value: gp3-csi + + - it: uses the vmDefaults storageClassName when overridden globally + set: + vmDefaults: + storageClassName: gp3-csi + externalDataSources: + - name: ubuntu-installer + type: http + url: https://releases.ubuntu.com/24.04.4/ubuntu-24.04.4-live-server-amd64.iso + size: 10G + documentSelector: + path: kind + value: DataVolume + asserts: + - equal: + path: spec.storage.storageClassName + value: gp3-csi + + - it: renders a DataSource referencing the DataVolume + set: + externalDataSources: + - name: quay-windows + type: registry + url: "docker://quay.io/eduffy/win2k22-dv:thin" + size: 50G + documentSelector: + path: kind + value: DataSource + asserts: + - equal: + path: metadata.name + value: quay-windows + - equal: + path: spec.source.pvc.name + value: quay-windows + - equal: + path: spec.source.pvc.namespace + value: openshift-virtualization-os-images diff --git a/values.yaml b/values.yaml index 23e7ef4..5a532dd 100644 --- a/values.yaml +++ b/values.yaml @@ -100,6 +100,8 @@ externalDataSources: {} # type: registry # url: "docker://quay.io/eduffy/win2k22-dv:thin" # size: 50G +# # storageClassName optional (defaults to vmDefaults.storageClassName) +# storageClassName: ocs-storagecluster-ceph-rbd-virtualization # registryCredentialsSecret: quay-creds # You will need to create either manually or using registryCredentialExternalSecrets above # Example downloaded from url @@ -107,6 +109,7 @@ externalDataSources: {} # type: http # url: https://releases.ubuntu.com/24.04.4/ubuntu-24.04.4-live-server-amd64.iso # size: 10G +# storageClassName: gp3-csi # This field will disable ExternalSecrets for fetching SSH Authorized Keys and From 159ea0dbdc8f1a84041c427e26094a336bb158cf Mon Sep 17 00:00:00 2001 From: Martin Jackson Date: Thu, 12 Nov 2026 17:33:34 -0600 Subject: [PATCH 2/3] Make wait jobs drain-cancelable The set-default-virt-storageclass and wait-for-metal-node jobs are poll loops that can run for a long time (e.g. waiting for ODF), and jobTerminationGracePeriod was 3600, so a node drain evicting one of these pods blocked the MCO drain for up to an hour. - SIGTERM trap exits 143 so a cancelled run is never marked successful - podFailurePolicy ignores DisruptionTarget drain evictions and exit code 143, so evictions do not burn backoffLimit and a replacement pod resumes the wait - Reduce jobTerminationGracePeriod 3600 -> 60 Regenerate README.md via make helm-docs. Co-Authored-By: Claude Code --- README.md | 3 ++- README.md.gotmpl | 1 + templates/job-setDefaultVirtStorageClass.yaml | 17 ++++++++++++++ templates/job-waitForMetalNode.yaml | 15 ++++++++++++ tests/set-default-virt-storageclass_test.yaml | 23 +++++++++++++++++++ values.yaml | 5 +++- 6 files changed, 62 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d8f8638..3add8ab 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ This chart is used to set up Edge GitOps VMs in conjunction with OpenShift Virtu ### Notable changes +* v0.5.4: Make wait jobs drain-cancelable: SIGTERM trap exits nonzero (a cancelled run is never marked successful), podFailurePolicy ignores DisruptionTarget drain evictions so a replacement pod resumes instead of burning backoffLimit, and jobTerminationGracePeriod defaults 3600s to 60s. * v0.5.4: Allow setting dataSource storageclass, defaulting to vmDefault or one set by the edv object. * v0.5.3: Extend set-default-virt-storageclass job to wait until VM DataSources are Ready and their CSI driver/provisioner matches vmDefaults.storageClassName (prevents CDI host-assisted clone fallback onto the wrong StorageClass) * v0.5.2: Add optional additionalPvcDisks with default PVC creation; set create: false to attach existing PVCs @@ -34,7 +35,7 @@ This chart is used to set up Edge GitOps VMs in conjunction with OpenShift Virtu | global.clusterDomain | string | `"example.com"` | | | global.pattern | string | `"ansible-edge-gitops"` | | | job.image | string | `"image-registry.openshift-image-registry.svc:5000/openshift/cli:latest"` | | -| jobTerminationGracePeriod | int | `3600` | | +| jobTerminationGracePeriod | int | `60` | Grace period before SIGKILL when a wait job pod is cancelled by a node drain. Keep this short: the jobs trap SIGTERM and exit promptly, and a long grace period blocks MCO drains/rollouts for its full duration. | | rbac.roleBindings[0].createBinding | bool | `true` | | | rbac.roleBindings[0].name | string | `"view-machine-api"` | | | rbac.roleBindings[0].roleRef.kind | string | `"ClusterRole"` | | diff --git a/README.md.gotmpl b/README.md.gotmpl index dee4957..db779f4 100644 --- a/README.md.gotmpl +++ b/README.md.gotmpl @@ -9,6 +9,7 @@ This chart is used to set up Edge GitOps VMs in conjunction with OpenShift Virtu ### Notable changes +* v0.5.4: Make wait jobs drain-cancelable: SIGTERM trap exits nonzero (a cancelled run is never marked successful), podFailurePolicy ignores DisruptionTarget drain evictions so a replacement pod resumes instead of burning backoffLimit, and jobTerminationGracePeriod defaults 3600s to 60s. * v0.5.4: Allow setting dataSource storageclass, defaulting to vmDefault or one set by the edv object. * v0.5.3: Extend set-default-virt-storageclass job to wait until VM DataSources are Ready and their CSI driver/provisioner matches vmDefaults.storageClassName (prevents CDI host-assisted clone fallback onto the wrong StorageClass) * v0.5.2: Add optional additionalPvcDisks with default PVC creation; set create: false to attach existing PVCs diff --git a/templates/job-setDefaultVirtStorageClass.yaml b/templates/job-setDefaultVirtStorageClass.yaml index a178367..54f0509 100644 --- a/templates/job-setDefaultVirtStorageClass.yaml +++ b/templates/job-setDefaultVirtStorageClass.yaml @@ -8,6 +8,18 @@ metadata: name: job-set-default-virt-storageclass namespace: {{ .Values.vmNamespace }} spec: + # A drain-evicted (cancelled) pod is ignored rather than counted as a + # failure: the Job stays incomplete and a replacement pod resumes the + # wait. Only genuine failures count toward backoffLimit. + podFailurePolicy: + rules: + - action: Ignore + onExitCodes: + containerName: set-default-virt-storageclass + values: [143] + - action: Ignore + onDisruptionConditions: + - type: DisruptionTarget template: spec: containers: @@ -17,6 +29,11 @@ spec: - -c - | set -euo pipefail + # Exit promptly with a nonzero code on SIGTERM so node drains can + # cancel this Job without it ever being marked successful. The + # poll loop only blocks for SLEEP_SECS at a time, so the trap + # fires quickly. + trap 'echo "Cancelled by SIGTERM; exiting 143 without success"; exit 143' TERM TARGET_SC="{{ .Values.vmDefaults.storageClassName }}" DS_NAMESPACE="{{ .Values.vmDefaults.externalDataSourceNamespace }}" # Space-separated DataSource names derived from chart VMs (may be empty) diff --git a/templates/job-waitForMetalNode.yaml b/templates/job-waitForMetalNode.yaml index 18e5cd8..c4e8e7b 100644 --- a/templates/job-waitForMetalNode.yaml +++ b/templates/job-waitForMetalNode.yaml @@ -7,6 +7,18 @@ metadata: name: job-wait-for-metal-node namespace: {{ .Values.vmNamespace }} spec: + # A drain-evicted (cancelled) pod is ignored rather than counted as a + # failure: the Job stays incomplete and a replacement pod resumes the + # wait. Only genuine failures count toward backoffLimit. + podFailurePolicy: + rules: + - action: Ignore + onExitCodes: + containerName: wait-for-metal-node + values: [143] + - action: Ignore + onDisruptionConditions: + - type: DisruptionTarget template: spec: containers: @@ -15,6 +27,9 @@ spec: - /bin/bash - -c - | + # Exit promptly with a nonzero code on SIGTERM so node drains can + # cancel this Job without it being marked successful. + trap 'echo "Cancelled by SIGTERM; exiting 143 without success"; exit 143' TERM while [ 1 ]; do nodes=$(oc get machinesets.machine.openshift.io -n openshift-machine-api -l 'edge-gitops-role=kubevirt-worker' -o jsonpath='{.items[*].status.availableReplicas}' | sed -e 's/ //g') diff --git a/tests/set-default-virt-storageclass_test.yaml b/tests/set-default-virt-storageclass_test.yaml index 3b0d408..f282a4f 100644 --- a/tests/set-default-virt-storageclass_test.yaml +++ b/tests/set-default-virt-storageclass_test.yaml @@ -40,6 +40,29 @@ tests: path: spec.template.spec.containers[0].command[2] pattern: openshift-virtualization-os-images + - it: is cancelable without being marked successful + asserts: + # SIGTERM trap exits 143 (nonzero) so the Job never completes on cancel + - matchRegex: + path: spec.template.spec.containers[0].command[2] + pattern: trap '.*exit 143' TERM + - equal: + path: spec.template.spec.terminationGracePeriodSeconds + value: 60 + # Drain evictions are ignored, not counted as failures + - equal: + path: spec.podFailurePolicy.rules[0].action + value: Ignore + - equal: + path: spec.podFailurePolicy.rules[0].onExitCodes.values + value: [143] + - equal: + path: spec.podFailurePolicy.rules[1].action + value: Ignore + - equal: + path: spec.podFailurePolicy.rules[1].onDisruptionConditions[0].type + value: DisruptionTarget + - it: embeds DataSource names from VMs set: setDefaultVirtStorageClass: true diff --git a/values.yaml b/values.yaml index 5a532dd..c927e6c 100644 --- a/values.yaml +++ b/values.yaml @@ -12,7 +12,10 @@ vmNamespace: gitops-vms waitForMetalNode: false setDefaultVirtStorageClass: true -jobTerminationGracePeriod: 3600 +# -- Grace period before SIGKILL when a wait job pod is cancelled by a node +# drain. Keep this short: the jobs trap SIGTERM and exit promptly, and a +# long grace period blocks MCO drains/rollouts for its full duration. +jobTerminationGracePeriod: 60 vmDefaults: role: generic From 000c9331ccaa51893736d04180cb4e2e98283d3a Mon Sep 17 00:00:00 2001 From: Martin Jackson Date: Fri, 13 Nov 2026 08:41:38 -0600 Subject: [PATCH 3/3] Fix invalid podFailurePolicy rules in wait jobs The podFailurePolicy added in 159ea0d was rejected by the API server: - onExitCodes requires an operator field (In/NotIn); add operator: In - onDisruptionConditions is not a valid field; the API server saw rule[1] as having no matcher at all. Replace it with onPodConditions matching the DisruptionTarget condition, which is the documented way to ignore drain evictions. Fix both job templates (set-default-virt-storageclass, wait-for-metal-node) and update the unit test assertions to match. Co-Authored-By: Claude Code --- templates/job-setDefaultVirtStorageClass.yaml | 3 ++- templates/job-waitForMetalNode.yaml | 3 ++- tests/set-default-virt-storageclass_test.yaml | 5 ++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/templates/job-setDefaultVirtStorageClass.yaml b/templates/job-setDefaultVirtStorageClass.yaml index 54f0509..87c1f98 100644 --- a/templates/job-setDefaultVirtStorageClass.yaml +++ b/templates/job-setDefaultVirtStorageClass.yaml @@ -16,9 +16,10 @@ spec: - action: Ignore onExitCodes: containerName: set-default-virt-storageclass + operator: In values: [143] - action: Ignore - onDisruptionConditions: + onPodConditions: - type: DisruptionTarget template: spec: diff --git a/templates/job-waitForMetalNode.yaml b/templates/job-waitForMetalNode.yaml index c4e8e7b..810be31 100644 --- a/templates/job-waitForMetalNode.yaml +++ b/templates/job-waitForMetalNode.yaml @@ -15,9 +15,10 @@ spec: - action: Ignore onExitCodes: containerName: wait-for-metal-node + operator: In values: [143] - action: Ignore - onDisruptionConditions: + onPodConditions: - type: DisruptionTarget template: spec: diff --git a/tests/set-default-virt-storageclass_test.yaml b/tests/set-default-virt-storageclass_test.yaml index f282a4f..8719da8 100644 --- a/tests/set-default-virt-storageclass_test.yaml +++ b/tests/set-default-virt-storageclass_test.yaml @@ -53,6 +53,9 @@ tests: - equal: path: spec.podFailurePolicy.rules[0].action value: Ignore + - equal: + path: spec.podFailurePolicy.rules[0].onExitCodes.operator + value: In - equal: path: spec.podFailurePolicy.rules[0].onExitCodes.values value: [143] @@ -60,7 +63,7 @@ tests: path: spec.podFailurePolicy.rules[1].action value: Ignore - equal: - path: spec.podFailurePolicy.rules[1].onDisruptionConditions[0].type + path: spec.podFailurePolicy.rules[1].onPodConditions[0].type value: DisruptionTarget - it: embeds DataSource names from VMs