Skip to content

Commit 7c739a1

Browse files
authored
fix(cdi): omit the CDI clone strategy override when unset (#4138)
## What this PR does `cdi-cr.yaml` rendered `cloneStrategyOverride` unconditionally, so there was no way to let CDI pick a clone strategy per StorageProfile. The CRD enum is `copy`/`snapshot`/`csi-clone` with no empty member, so neither obvious workaround got there: an empty value rendered `cloneStrategyOverride: ""`, which that enum does not accept, and a null one rendered a bare key. Both checked against `main` with `helm template` rather than assumed. Now the key is guarded on a non-empty value, same as `uploadProxyURLOverride` just below it in the same file. With the field absent, CDI reads the target StorageClass's StorageProfile and uses its clone strategy. Default stays `csi-clone`. Rendered at the default and diffed against `main`, the output is byte-identical, so nothing already deployed moves. ### Tests `tests/clone_strategy_test.yaml` pins both directions: absent when the value is empty, absent when it is null, `csi-clone` on the chart default, `snapshot` through unchanged. It sits alongside the existing `importer-resources` and `standalone_render_test` suites, with its own file and suite name and no shared test names; `make test` runs all three. I checked the suite can fail rather than assuming it works. Reverting the guard reddens the two absent-field cases, deleting the field outright reddens the default and passthrough cases, hardcoding the value reddens the passthrough case, and rendering a bare key reddens all four. The two sibling suites stay green through every one of those, so the reds are attributable to this suite. The null case is pinned as an input rather than argued from `with` treating null and empty alike. It cannot pass vacuously: flipping its assertion to expect the default returns `unknown path`, not a `csi-clone` mismatch, which is what shows the null actually reaches the template instead of the assertion passing on a value that never arrived. ### Known gaps `copy` is accepted by the enum but no test drives it, so the suite does not pin that it reaches the CR. Concretely: wrapping the guard in `{{- if ne . "copy" }}`, which silently drops that one strategy, still passes all nine tests. Named here rather than fixed so the boundary is visible to the next reader instead of being rediscovered. ### Scope Context: #2908. This is the first of the three directions that issue lists, so it does not close it and carries no `Closes`. The default is deliberately left at `csi-clone`, since whether that is the right default is the second direction and a separate decision. The third, `vm-disk` warning on a cross-StorageClass request, is untouched. An operator who has not set `cloneStrategyOverride: ""` sees the reported symptom exactly as before. ### Screenshots Not a UI change. ### Downstream repositories Walked the trigger map against the diff. It is one guarded key in a `packages/system` chart, a values comment, and a test suite: no package added or renamed, no `values.schema.json` (this chart has none), no `ApplicationDefinition`, no namespace, nothing under `hack/`, no platform values key. The `ccp` entry covers `hack/package.mk` and make-target behaviour, and this touches neither. Nothing in the map reaches it. - [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 ```release-note fix(cdi): `cloneStrategyOverride` in the `kubevirt-cdi` package can now be left empty, which omits the field and lets CDI pick a clone strategy per StorageProfile. The default is unchanged at `csi-clone`. ```
2 parents 4b6b1dc + 5db7738 commit 7c739a1

3 files changed

Lines changed: 71 additions & 2 deletions

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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ _cluster: {}
55
uploadProxyURL: ""
66

77
## @param cloneStrategyOverride Strategy CDI uses to clone DataVolumes (golden image -> VM disk).
8-
## One of: csi-clone, snapshot, copy. Defaults to csi-clone (unchanged behavior).
8+
## One of: csi-clone, snapshot, copy, or empty. 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)