Skip to content

Commit 45f5698

Browse files
authored
fix(cdi): validate kubevirt-cdi values against a schema (#4417)
## What this PR does This gives the kubevirt-cdi chart a values schema, so a bad clone strategy fails when the chart renders instead of when the CDI object is applied. Today a typo like `csi_clone` renders fine, the CDI CRD refuses it on apply, and the operator finds out from a failed HelmRelease. The schema is generated by `cozyvalues-gen` from annotations in `values.yaml`, through a new `make generate` target, the same way `talos-log-collector` does it. There is no README here, so the target only writes the schema. The clone strategy is checked with a pattern, not with the CRD's enum. The chart uses the empty string to omit the field and let CDI pick a strategy per StorageProfile, and the CRD enum has no member for that. `cozyvalues-gen` also can't emit an empty enum value. So the accepted values are `copy`, `snapshot`, `csi-clone` and `""`. A null still works as before. The key has a chart default, so Helm drops a null for it before validation, and the template omits the field. `uploadProxyURL` only has to be a string. The new test suite refuses `csi_clone` and values of the wrong type, and accepts each of the allowed values and null. Closes #4141 ### Screenshots No UI change. ### Downstream repositories - [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): kubevirt-cdi now validates its values against a schema, so an invalid `cloneStrategyOverride` such as `csi_clone` fails at render time instead of when the CDI object is applied. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Configuration** * Chart values are now validated to ensure the upload proxy URL is a string, importer resources are provided as an object, and clone strategy uses a supported value: `copy`, `snapshot`, `csi-clone`, or an empty value. * Existing defaults for these settings remain unchanged. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 5e46060 + 9c97a7a commit 45f5698

4 files changed

Lines changed: 127 additions & 6 deletions

File tree

‎packages/system/kubevirt-cdi/Makefile‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ SHA256SUM = $(shell command -v sha256sum >/dev/null 2>&1 && echo sha256sum || ec
2525
include ../../../hack/package.mk
2626

2727
# Phony because hack/package.mk's .PHONY line lists only the targets that file
28-
# defines: with neither name declared, a path named `test` or `update` next to
29-
# this Makefile would make that target up to date and skip the recipe.
30-
.PHONY: test update
28+
# defines: with none of these names declared, a path named `test`, `update` or
29+
# `generate` next to this Makefile would make that target up to date and skip
30+
# the recipe.
31+
.PHONY: test update generate
32+
33+
# No -r: this package ships no README for cozyvalues-gen to update.
34+
generate:
35+
cozyvalues-gen -v values.yaml -s values.schema.json
3136

3237
# hack/package.mk defines no `test` target and hack/helm-unit-tests.sh only
3338
# runs a package whose `make -n test` resolves, so a tests/ directory with no
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
suite: cozy-kubevirt-cdi values schema
2+
release:
3+
name: kubevirt-cdi
4+
namespace: cozy-kubevirt-cdi
5+
templates:
6+
- cdi-cr.yaml
7+
tests:
8+
# The CDI CRD rejects anything outside its enum, but only when the object is
9+
# applied, so without the schema a typo surfaces as a failed HelmRelease
10+
# rather than at the value that caused it.
11+
- it: refuses a clone strategy CDI does not know
12+
set:
13+
cloneStrategyOverride: csi_clone
14+
asserts:
15+
- failedTemplate:
16+
errorPattern: "cloneStrategyOverride.*does not match pattern"
17+
18+
- it: refuses a clone strategy that is not a string
19+
set:
20+
cloneStrategyOverride: 1
21+
asserts:
22+
- failedTemplate:
23+
errorPattern: "cloneStrategyOverride.*want string"
24+
25+
# The empty string is the chart's own "omit the field" state, which the
26+
# CRD enum has no member for: copying that enum into the schema would
27+
# refuse it.
28+
- it: accepts the empty clone strategy
29+
set:
30+
cloneStrategyOverride: ""
31+
asserts:
32+
- notFailedTemplate: {}
33+
34+
- it: accepts copy
35+
set:
36+
cloneStrategyOverride: copy
37+
asserts:
38+
- notFailedTemplate: {}
39+
40+
- it: accepts snapshot
41+
set:
42+
cloneStrategyOverride: snapshot
43+
asserts:
44+
- notFailedTemplate: {}
45+
46+
- it: accepts csi-clone
47+
set:
48+
cloneStrategyOverride: csi-clone
49+
asserts:
50+
- notFailedTemplate: {}
51+
52+
# The key has a chart default, so Helm drops a null for it before it
53+
# validates, and the template sees it unset; tests/clone_strategy_test.yaml
54+
# pins what that renders. Without the default, the null would reach the
55+
# schema and be refused.
56+
- it: accepts a null clone strategy
57+
set:
58+
cloneStrategyOverride: null
59+
asserts:
60+
- notFailedTemplate: {}
61+
62+
- it: accepts any string as the upload proxy URL
63+
set:
64+
uploadProxyURL: cdi-uploadproxy.example.com:8443
65+
asserts:
66+
- notFailedTemplate: {}
67+
68+
- it: refuses an upload proxy URL that is not a string
69+
set:
70+
uploadProxyURL:
71+
host: cdi-uploadproxy.example.com
72+
asserts:
73+
- failedTemplate:
74+
errorPattern: "uploadProxyURL.*want string"
75+
76+
- it: refuses importer resources that are not a map
77+
set:
78+
importerResources: 600M
79+
asserts:
80+
- failedTemplate:
81+
errorPattern: "importerResources.*want object"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"title": "Chart Values",
3+
"type": "object",
4+
"properties": {
5+
"uploadProxyURL": {
6+
"description": "Upload proxy URL, set as uploadProxyURLOverride on the CDI object. Empty leaves it unset.",
7+
"type": "string",
8+
"default": ""
9+
},
10+
"cloneStrategyOverride": {
11+
"description": "Strategy CDI uses to clone DataVolumes (golden image -\u003e VM disk): csi-clone, snapshot, copy, or empty.",
12+
"type": "string",
13+
"default": "csi-clone",
14+
"pattern": "^(|copy|snapshot|csi-clone)$"
15+
},
16+
"importerResources": {
17+
"description": "Resources for CDI's importer/uploader/cloner worker pods.",
18+
"type": "object",
19+
"default": {
20+
"limits": {
21+
"cpu": "750m",
22+
"memory": "600M"
23+
},
24+
"requests": {
25+
"cpu": "100m",
26+
"memory": "60M"
27+
}
28+
},
29+
"x-kubernetes-preserve-unknown-fields": true
30+
}
31+
}
32+
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
# default keeps the chart renderable on its own, outside a cluster.
33
_cluster: {}
44

5+
## @param {string} [uploadProxyURL] - Upload proxy URL, set as uploadProxyURLOverride on the CDI object. Empty leaves it unset.
56
uploadProxyURL: ""
67

7-
## @param cloneStrategyOverride Strategy CDI uses to clone DataVolumes (golden image -> VM disk).
8-
## One of: csi-clone, snapshot, copy, or empty. Defaults to csi-clone (unchanged behavior).
8+
## @param {string} [cloneStrategyOverride] - Strategy CDI uses to clone DataVolumes (golden image -> VM disk): csi-clone, snapshot, copy, or empty.
9+
## @pattern ^(|copy|snapshot|csi-clone)$
910
## Empty omits the field, leaving CDI to pick a strategy per StorageProfile.
11+
## That is why this is a pattern and not an enum copied from the CDI CRD: the
12+
## CRD has no empty member, and cozyvalues-gen cannot emit an empty @value.
1013
cloneStrategyOverride: csi-clone
1114

12-
## @param importerResources Resources for CDI's importer/uploader/cloner worker pods.
15+
## @param {object} [importerResources] - Resources for CDI's importer/uploader/cloner worker pods.
1316
## Applied as CDIConfig.podResourceRequirements. The defaults below restate CDI's own
1417
## built-in values rather than changing them: leaving this unset must not move
1518
## production behaviour. Raise the memory ceiling only where an import is shown to

0 commit comments

Comments
 (0)