Skip to content

Commit ed20c53

Browse files
authored
fix(vm-disk): refuse to clone a golden image that does not exist (cozystack#4567)
<!-- Thank you for making a contribution! Here are some tips for you: - Use Conventional Commits for the PR title: `type(scope): description` - Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore - Scopes are not an exhaustive list — pick the most specific scope for the change and extend the list when a genuinely new area appears. Examples: - System components: dashboard, platform, operator, cilium, kube-ovn, linstor, fluxcd, cluster-api - Managed apps: postgres, mariadb, redis, kafka, clickhouse, virtual-machine, kubernetes - Development and maintenance: api, hack, tests, ci, docs, maintenance - Breaking changes: append `!` after type/scope (`feat(api)!: ...`) or add a `BREAKING CHANGE:` footer - If it's a work in progress, consider creating this PR as a draft. - Don't hesistate to ask for opinion and review in the community chats, even if it's still a draft. - Add the label `kind/backport` if it's a bugfix that needs to be backported to a previous version. --> ## What this PR does Stacked on cozystack#4392, so the base is `fix/vm-default-images-health-check`. Retarget to `main` once cozystack#4392 merges. A new vm-disk with `source.image` now fails to render when the golden image it names does not exist, and the error names the image and `cozy-public`. Before this the chart cloned `cozy-public/vm-default-images-<name>` without looking, and CDI waited for that PVC forever while the VMDisk stayed Ready. That happens on a typo, and on every cluster where the opt-in `cozystack.vm-default-images` package is off, so the message also says to add it to `bundles.enabledPackages`. The golden counts as missing only when neither its DataVolume nor its PVC exists. CDI clones the PVC, so a PVC with no DataVolume is still a usable source, and a DataVolume whose PVC is not created yet is an import about to start. Under `helm template` every lookup is empty, so the check runs only when the release namespace itself is visible. The same trick is already used in the kubernetes and seaweedfs charts. Existing disks are exempt the same way cozystack#4392 exempts them, because their DataVolume spec is immutable. A disk refused while the catalog is off renders by itself once the golden appears, since app HelmReleases retry on failure. Tests are in `packages/apps/vm-disk/tests/dv_golden_image_test.yaml`: refusal of a missing golden, a PVC without a DataVolume, a DataVolume before its PVC, rendering with no cluster, and an existing disk whose golden was removed. Closes cozystack#4548 ### Screenshots <!-- REQUIRED for UI changes: attach screenshots or screen recordings demonstrating the visual impact of your changes. PRs with UI changes without screenshots will not be merged. --> No UI change. ### Downstream repositories <!-- Cozystack is upstream for repositories that are NOT kept in sync with it automatically, and nothing in CI compares the two sides, so a change here can break them silently. Which change forces what, and which file to touch, is the trigger map in docs/agents/contributing.md under "Downstream Repositories". Walk it before you tick anything. IF YOU ARE AN AI AGENT OR AN LLM, THIS IS PART OF THE TASK, NOT A FORM TO FILL IN: 1. Walk the trigger map against the actual diff of this PR, file by file. Do not decide from the PR title or from your memory of what you changed. 2. For every repository you tick, open the follow-up PR there and link it on the same line. A ticked box with no link claims work that does not exist, which is worse than an empty box. Search that repository for an open PR or issue covering it first, and link that instead of filing a duplicate. 3. When the follow-up is out of scope, or needs a decision that is not yours to make, open an issue in that repository instead, link that, and say so in the PR body. Do not push a speculative PR into another repository just to fill a line here. 4. Do not tick "No downstream repository is affected" to make the checklist go away. If you are unsure, leave every box empty and say so in the PR body, so a human decides. --> - [x] No downstream repository is affected by this change - [ ] [cozystack/website](https://github.com/cozystack/website) - follow-up: - [ ] [cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack) - follow-up: - [ ] [cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack) - follow-up: - [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up: - [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up: - [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) - follow-up: - [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) - follow-up: - [ ] [cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server) - follow-up: - [ ] [cozystack/external-apps-example](https://github.com/cozystack/external-apps-example) - follow-up: - [ ] [cozystack/examples](https://github.com/cozystack/examples) - follow-up: - [ ] [cozystack/community](https://github.com/cozystack/community) - follow-up: ### Release note <!-- Write a release note: - Explain what has changed internally and for users. - Start with the same `type(scope):` prefix as in the PR title - Follow the guidelines at https://github.com/kubernetes/community/blob/master/contributors/guide/release-notes.md. --> ```release-note fix(vm-disk): a new disk with source.image now fails with a clear error when the golden image does not exist in cozy-public, instead of waiting forever for a clone that never starts. ```
2 parents c7b8009 + 3d5f9f2 commit ed20c53

2 files changed

Lines changed: 113 additions & 9 deletions

File tree

‎packages/apps/vm-disk/templates/dv.yaml‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@
1111
{{- end }}
1212
{{- if hasKey .Values.source "image" }}
1313
{{- $desiredSource = dict "pvc" (dict "name" (printf "vm-default-images-%s" (required "A valid .Values.source.image.name entry required!" .Values.source.image.name)) "namespace" "cozy-public") }}
14-
{{- /* Refuse only a golden whose import Failed: CDI never populates it, so the
15-
clone would wait forever. A golden still importing is left alone because
16-
CDI holds the clone until the source is populated. An existing disk is
17-
exempt: its DataVolume spec is immutable, so failing the render cannot
18-
rescue it and would only block this release's upgrades. */}}
14+
{{- /* Refuse a golden that is missing or whose import Failed: CDI never
15+
populates it, so the clone would wait forever. A golden still importing
16+
is left alone because CDI holds the clone until the source is populated.
17+
Missing means neither the DataVolume nor the PVC CDI clones exists, as
18+
the DataVolume can precede its PVC, and counts only when the release
19+
namespace is visible: helm template has no cluster and every lookup
20+
comes back empty. An existing disk is exempt: its DataVolume spec is
21+
immutable, so failing the render cannot rescue it and would only block
22+
this release's upgrades. */}}
1923
{{- if not $existingDV }}
2024
{{- $golden := lookup "cdi.kubevirt.io/v1beta1" "DataVolume" "cozy-public" $desiredSource.pvc.name }}
2125
{{- if eq (dig "status" "phase" "" $golden | toString) "Failed" }}
2226
{{- fail (printf "source.image %q: golden DataVolume %q in cozy-public failed to import (phase Failed), so a clone of it would never complete. Ask the platform administrator to check the importer pod in cozy-public, then delete that DataVolume to retry the import." .Values.source.image.name $desiredSource.pvc.name) }}
27+
{{- else if and (not $golden) (not (lookup "v1" "PersistentVolumeClaim" "cozy-public" $desiredSource.pvc.name)) (lookup "v1" "Namespace" "" .Release.Namespace) }}
28+
{{- fail (printf "source.image %q: golden image %q not found in cozy-public, so a clone of it would never start. Check the image name, or ask the platform administrator to add cozystack.vm-default-images to bundles.enabledPackages." .Values.source.image.name $desiredSource.pvc.name) }}
2329
{{- end }}
2430
{{- end }}
2531
{{- else if hasKey .Values.source "http" }}

‎packages/apps/vm-disk/tests/dv_golden_image_test.yaml‎

Lines changed: 102 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
suite: vm-disk refuses to clone a golden image whose import failed
2-
# A golden whose import Failed is never populated, and CDI holds a clone of it
3-
# forever, so a new disk on it would sit pending with nothing pointing at the
4-
# image. Only Failed is refused: a golden still importing is safe to clone
1+
suite: vm-disk refuses to clone a golden image that is missing or failed
2+
# A golden that is missing or whose import Failed is never populated, and CDI
3+
# holds a clone of it forever, so a new disk on it would sit pending with
4+
# nothing pointing at the image. A golden still importing is safe to clone
55
# because CDI waits for it, and helm template has no cluster to look it up in.
66
release:
77
name: test-vm-disk
@@ -17,6 +17,12 @@ tests:
1717
"cdi.kubevirt.io/v1beta1/DataVolume":
1818
gvr: {group: cdi.kubevirt.io, version: v1beta1, resource: datavolumes}
1919
namespaced: true
20+
"v1/Namespace":
21+
gvr: {group: "", version: v1, resource: namespaces}
22+
namespaced: false
23+
"v1/PersistentVolumeClaim":
24+
gvr: {group: "", version: v1, resource: persistentvolumeclaims}
25+
namespaced: true
2026
objects:
2127
- kind: DataVolume
2228
apiVersion: cdi.kubevirt.io/v1beta1
@@ -32,10 +38,16 @@ tests:
3238
kubernetesProvider:
3339
scheme: *scheme
3440
objects:
41+
- kind: Namespace
42+
apiVersion: v1
43+
metadata: {name: tenant-test}
3544
- kind: DataVolume
3645
apiVersion: cdi.kubevirt.io/v1beta1
3746
metadata: {name: vm-default-images-ubuntu, namespace: cozy-public}
3847
status: {phase: Succeeded}
48+
- kind: PersistentVolumeClaim
49+
apiVersion: v1
50+
metadata: {name: vm-default-images-ubuntu, namespace: cozy-public}
3951
asserts:
4052
- equal:
4153
path: spec.source.pvc
@@ -47,10 +59,16 @@ tests:
4759
kubernetesProvider:
4860
scheme: *scheme
4961
objects:
62+
- kind: Namespace
63+
apiVersion: v1
64+
metadata: {name: tenant-test}
5065
- kind: DataVolume
5166
apiVersion: cdi.kubevirt.io/v1beta1
5267
metadata: {name: vm-default-images-ubuntu, namespace: cozy-public}
5368
status: {phase: ImportInProgress}
69+
- kind: PersistentVolumeClaim
70+
apiVersion: v1
71+
metadata: {name: vm-default-images-ubuntu, namespace: cozy-public}
5472
asserts:
5573
- equal:
5674
path: spec.source.pvc
@@ -87,3 +105,83 @@ tests:
87105
storage: {resources: {requests: {storage: 5Gi}}, storageClassName: replicated}
88106
asserts:
89107
- notFailedTemplate: {}
108+
109+
- it: refuses a new disk on a golden that does not exist
110+
set:
111+
source: {image: {name: nosuch}}
112+
kubernetesProvider:
113+
scheme: *scheme
114+
objects: &releaseNamespace
115+
- kind: Namespace
116+
apiVersion: v1
117+
metadata: {name: tenant-test}
118+
asserts:
119+
- failedTemplate:
120+
errorPattern: 'source.image "nosuch": golden image "vm-default-images-nosuch" not found in cozy-public'
121+
122+
- it: clones a golden PVC that has no DataVolume
123+
set:
124+
source: {image: {name: ubuntu}}
125+
kubernetesProvider:
126+
scheme: *scheme
127+
objects:
128+
- kind: Namespace
129+
apiVersion: v1
130+
metadata: {name: tenant-test}
131+
- kind: PersistentVolumeClaim
132+
apiVersion: v1
133+
metadata: {name: vm-default-images-ubuntu, namespace: cozy-public}
134+
asserts:
135+
- equal:
136+
path: spec.source.pvc
137+
value: {name: vm-default-images-ubuntu, namespace: cozy-public}
138+
139+
- it: leaves an existing disk alone when its golden was later removed
140+
set:
141+
source: {image: {name: ubuntu}}
142+
kubernetesProvider:
143+
scheme: *scheme
144+
objects:
145+
- kind: Namespace
146+
apiVersion: v1
147+
metadata: {name: tenant-test}
148+
- kind: DataVolume
149+
apiVersion: cdi.kubevirt.io/v1beta1
150+
metadata:
151+
name: test-vm-disk
152+
namespace: tenant-test
153+
annotations:
154+
vm-disk.cozystack.io/source: '{"image":{"name":"ubuntu"}}'
155+
vm-disk.cozystack.io/storage-class: replicated
156+
spec:
157+
source: {pvc: {name: vm-default-images-ubuntu, namespace: cozy-public}}
158+
storage: {resources: {requests: {storage: 5Gi}}, storageClassName: replicated}
159+
asserts:
160+
- notFailedTemplate: {}
161+
162+
- it: does not look the golden up for a source other than an image
163+
set:
164+
source: {http: {url: "https://example.com/disk.img"}}
165+
kubernetesProvider:
166+
scheme: *scheme
167+
objects: *releaseNamespace
168+
asserts:
169+
- notFailedTemplate: {}
170+
171+
- it: clones a golden whose DataVolume exists before CDI created its PVC
172+
set:
173+
source: {image: {name: ubuntu}}
174+
kubernetesProvider:
175+
scheme: *scheme
176+
objects:
177+
- kind: Namespace
178+
apiVersion: v1
179+
metadata: {name: tenant-test}
180+
- kind: DataVolume
181+
apiVersion: cdi.kubevirt.io/v1beta1
182+
metadata: {name: vm-default-images-ubuntu, namespace: cozy-public}
183+
status: {phase: ImportScheduled}
184+
asserts:
185+
- equal:
186+
path: spec.source.pvc
187+
value: {name: vm-default-images-ubuntu, namespace: cozy-public}

0 commit comments

Comments
 (0)