Skip to content

Commit 650ada1

Browse files
committed
fix(cdi): omit the CDI clone strategy override when unset
templates/cdi-cr.yaml rendered cloneStrategyOverride unconditionally, so the chart's values offered no way to leave the choice to CDI's own per-StorageProfile selection. The CRD enum takes copy, snapshot and csi-clone and carries no empty member, so an empty value rendered cloneStrategyOverride: "" which that enum does not accept, and a null one rendered a bare key. Guard the field on a non-empty value, the way uploadProxyURLOverride is already guarded just below it. The default stays csi-clone, so a release that overrides nothing renders what it rendered before. Whether csi-clone is the right default is a separate question, untouched here. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent 4f337d6 commit 650ada1

3 files changed

Lines changed: 70 additions & 1 deletion

File tree

‎packages/system/kubevirt-cdi/templates/cdi-cr.yaml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ kind: CDI
33
metadata:
44
name: cdi
55
spec:
6-
cloneStrategyOverride: {{ quote .Values.cloneStrategyOverride }}
6+
{{- with .Values.cloneStrategyOverride }}
7+
cloneStrategyOverride: {{ quote . }}
8+
{{- end }}
79
config:
810
{{- with .Values.uploadProxyURL }}
911
uploadProxyURLOverride: {{ quote . }}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
suite: cozy-kubevirt-cdi clone strategy
2+
release:
3+
name: kubevirt-cdi
4+
namespace: cozy-kubevirt-cdi
5+
tests:
6+
# The CRD enum takes copy, snapshot and csi-clone and carries no empty
7+
# member, so the only way to ask CDI for its own per-StorageProfile choice
8+
# is for the field to be absent. An empty value used to render
9+
# cloneStrategyOverride: "", which that enum does not accept; this pins
10+
# against it coming back.
11+
- it: omits the field when no strategy is configured
12+
template: cdi-cr.yaml
13+
documentSelector:
14+
path: kind
15+
value: CDI
16+
matchMany: false
17+
set:
18+
cloneStrategyOverride: ""
19+
asserts:
20+
- notExists:
21+
path: spec.cloneStrategyOverride
22+
23+
# An operator writing `cloneStrategyOverride: ~` by hand is a separate input
24+
# from the empty string, and it used to render a bare key. It reaches the
25+
# same falsy branch of `with`, but that is a claim about behaviour, so it is
26+
# pinned rather than argued. The case cannot pass vacuously: were the null
27+
# not reaching the template, the chart default would render csi-clone here
28+
# and the assertion below would fail.
29+
- it: omits the field when the strategy is null
30+
template: cdi-cr.yaml
31+
documentSelector:
32+
path: kind
33+
value: CDI
34+
matchMany: false
35+
set:
36+
cloneStrategyOverride: null
37+
asserts:
38+
- notExists:
39+
path: spec.cloneStrategyOverride
40+
41+
- it: keeps the chart default
42+
template: cdi-cr.yaml
43+
documentSelector:
44+
path: kind
45+
value: CDI
46+
matchMany: false
47+
asserts:
48+
- equal:
49+
path: spec.cloneStrategyOverride
50+
value: csi-clone
51+
52+
# The other direction: a configured value still has to reach the CR verbatim.
53+
# A test that only covered the empty case would pass against a template that
54+
# dropped the field unconditionally.
55+
- it: passes a configured strategy through unchanged
56+
template: cdi-cr.yaml
57+
documentSelector:
58+
path: kind
59+
value: CDI
60+
matchMany: false
61+
set:
62+
cloneStrategyOverride: snapshot
63+
asserts:
64+
- equal:
65+
path: spec.cloneStrategyOverride
66+
value: snapshot

‎packages/system/kubevirt-cdi/values.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ uploadProxyURL: ""
66

77
## @param cloneStrategyOverride Strategy CDI uses to clone DataVolumes (golden image -> VM disk).
88
## One of: csi-clone, snapshot, copy. Defaults to csi-clone (unchanged behavior).
9+
## Empty omits the field, leaving CDI to pick a strategy per StorageProfile.
910
cloneStrategyOverride: csi-clone
1011

1112
## @param importerResources Resources for CDI's importer/uploader/cloner worker pods.

0 commit comments

Comments
 (0)