Skip to content

Commit 9c1a5bf

Browse files
committed
feat(kubevirt): expose migration configuration through platform values
Signed-off-by: Yan Bondarenko <[email protected]>
1 parent ae7a711 commit 9c1a5bf

8 files changed

Lines changed: 194 additions & 1 deletion

File tree

‎packages/core/platform/templates/bundles/iaas.yaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
{{- if $disabledFeatureGates -}}
2727
{{- $_ := set $kubevirtValues "disabledFeatureGates" $disabledFeatureGates -}}
2828
{{- end -}}
29+
{{- with (.Values.kubevirt).migrations -}}
30+
{{- $_ := set $kubevirtValues "migrations" . -}}
31+
{{- end -}}
2932
{{- /*
3033
When cozystack.gpu-operator is enabled the platform mirrors the variant
3134
into the KubeVirt CR: the HostDevices feature gate, without which the

‎packages/core/platform/tests/bundles_gpu_kubevirt_wiring_test.yaml‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,8 @@ tests:
511511
asserts:
512512
- notExists:
513513
path: spec.components.kubevirt.values.disabledFeatureGates
514+
- notExists:
515+
path: spec.components.kubevirt.values.migrations
514516
- equal:
515517
path: spec.components
516518
value:
@@ -537,6 +539,100 @@ tests:
537539
value: Package
538540
- notExists:
539541
path: spec.components.kubevirt.values.disabledFeatureGates
542+
- notExists:
543+
path: spec.components.kubevirt.values.migrations
544+
545+
- it: forwards kubevirt.migrations into the kubevirt component values
546+
set:
547+
bundles:
548+
system:
549+
enabled: true
550+
variant: isp-full
551+
iaas:
552+
enabled: true
553+
enabledPackages: []
554+
kubevirt:
555+
migrations:
556+
bandwidthPerMigration: 625M
557+
parallelMigrationsPerCluster: 2
558+
parallelOutboundMigrationsPerNode: 1
559+
documentSelector:
560+
path: metadata.name
561+
value: cozystack.kubevirt
562+
asserts:
563+
- equal:
564+
path: spec.components.kubevirt.values
565+
value:
566+
cpuAllocationRatio: 10
567+
migrations:
568+
bandwidthPerMigration: 625M
569+
parallelMigrationsPerCluster: 2
570+
parallelOutboundMigrationsPerNode: 1
571+
572+
- it: omits empty kubevirt.migrations
573+
set:
574+
bundles:
575+
system:
576+
enabled: true
577+
variant: isp-full
578+
iaas:
579+
enabled: true
580+
enabledPackages: []
581+
kubevirt:
582+
migrations: {}
583+
documentSelector:
584+
path: metadata.name
585+
value: cozystack.kubevirt
586+
asserts:
587+
- equal:
588+
path: spec.components.kubevirt.values
589+
value:
590+
cpuAllocationRatio: 10
591+
592+
- it: omits null kubevirt.migrations
593+
set:
594+
bundles:
595+
system:
596+
enabled: true
597+
variant: isp-full
598+
iaas:
599+
enabled: true
600+
enabledPackages: []
601+
kubevirt:
602+
migrations: null
603+
documentSelector:
604+
path: metadata.name
605+
value: cozystack.kubevirt
606+
asserts:
607+
- equal:
608+
path: spec.components.kubevirt.values
609+
value:
610+
cpuAllocationRatio: 10
611+
612+
- it: preserves false and zero kubevirt.migrations values
613+
set:
614+
bundles:
615+
system:
616+
enabled: true
617+
variant: isp-full
618+
iaas:
619+
enabled: true
620+
enabledPackages: []
621+
kubevirt:
622+
migrations:
623+
allowAutoConverge: false
624+
completionTimeoutPerGiB: 0
625+
documentSelector:
626+
path: metadata.name
627+
value: cozystack.kubevirt
628+
asserts:
629+
- equal:
630+
path: spec.components.kubevirt.values
631+
value:
632+
cpuAllocationRatio: 10
633+
migrations:
634+
allowAutoConverge: false
635+
completionTimeoutPerGiB: 0
540636

541637
- it: appends user-supplied pciHostDevices in vgpu mode so post-kubevirt#16890 SR-IOV vGPU VFs can be advertised alongside the platform mediated defaults
542638
set:

‎packages/core/platform/values.yaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,9 @@ kubevirt:
713713
# render and names the gate rather than ship a CR the cluster would reject
714714
# on update and misread on install.
715715
disabledFeatureGates: []
716+
# Passed to spec.configuration.migrations on the KubeVirt CR.
717+
# Empty keeps KubeVirt's defaults. bandwidthPerMigration is bytes/second.
718+
migrations: {}
716719
# GPU host-device wiring for VirtualMachine workloads. Merged into the KubeVirt
717720
# CR's permittedHostDevices when bundles.enabledPackages contains
718721
# cozystack.gpu-operator and bundles.iaas.gpuOperatorVariant is one of the two

‎packages/system/kubevirt/Makefile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ update:
5353
@# sanity-check tail below.
5454
grep -q '{{- with .Values.permittedHostDevices }}' $(CR_FILE) || sed -i '/^ evictionStrategy:/i\ {{- with .Values.permittedHostDevices }}\n permittedHostDevices:\n {{- toYaml . | nindent 6 }}\n {{- end }}' $(CR_FILE)
5555
grep -q '{{- with .Values.mediatedDevicesConfiguration }}' $(CR_FILE) || sed -i '/^ evictionStrategy:/i\ {{- with .Values.mediatedDevicesConfiguration }}\n mediatedDevicesConfiguration:\n {{- toYaml . | nindent 6 }}\n {{- end }}' $(CR_FILE)
56+
grep -q '{{- with .Values.migrations }}' $(CR_FILE) || sed -i '/^ evictionStrategy:/i\ {{- with .Values.migrations }}\n migrations:\n {{- toYaml . | nindent 6 }}\n {{- end }}' $(CR_FILE)
5657
@# Sanity-check: every cozystack patch MUST end up in the file. If the
5758
@# hand-merge step moved or renamed an anchor (developerConfiguration:,
5859
@# - VMExport, featureGates:, evictionStrategy:) the sed silently no-ops and the chart
@@ -88,3 +89,4 @@ update:
8889
@grep -q '{{- $$staticDisabledFeatureGates := ' $(CR_FILE) || { echo "ERROR: marker '{{- \$$staticDisabledFeatureGates := ' missing from the guard header — the disabledFeatureGates block below references it and the render would fail. Restore the header block at the top of $(CR_FILE)" >&2; exit 1; }
8990
@grep -q '{{- with .Values.permittedHostDevices }}' $(CR_FILE) || { echo "ERROR: directive '{{- with .Values.permittedHostDevices }}' not inserted — restore the 'evictionStrategy:' anchor in $(CR_FILE) and re-run" >&2; exit 1; }
9091
@grep -q '{{- with .Values.mediatedDevicesConfiguration }}' $(CR_FILE) || { echo "ERROR: directive '{{- with .Values.mediatedDevicesConfiguration }}' not inserted — restore the 'evictionStrategy:' anchor in $(CR_FILE) and re-run" >&2; exit 1; }
92+
@grep -q '{{- with .Values.migrations }}' $(CR_FILE) || { echo "ERROR: directive '{{- with .Values.migrations }}' not inserted — restore the 'evictionStrategy:' anchor in $(CR_FILE) and re-run" >&2; exit 1; }

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ spec:
119119
mediatedDevicesConfiguration:
120120
{{- toYaml . | nindent 6 }}
121121
{{- end }}
122+
{{- with .Values.migrations }}
123+
migrations:
124+
{{- toYaml . | nindent 6 }}
125+
{{- end }}
122126
evictionStrategy: LiveMigrate
123127
virtualMachineOptions:
124128
disableSerialConsoleLog: {}

‎packages/system/kubevirt/tests/kubevirt_cr_test.yaml‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,48 @@ tests:
3535
path: spec.configuration.permittedHostDevices
3636
- notExists:
3737
path: spec.configuration.mediatedDevicesConfiguration
38+
- notExists:
39+
path: spec.configuration.migrations
40+
41+
- it: omits migrations when explicitly empty
42+
set:
43+
migrations: {}
44+
asserts:
45+
- notExists:
46+
path: spec.configuration.migrations
47+
48+
- it: omits migrations when explicitly null
49+
set:
50+
migrations: null
51+
asserts:
52+
- notExists:
53+
path: spec.configuration.migrations
54+
55+
- it: renders migration limits without changing their values
56+
set:
57+
migrations:
58+
bandwidthPerMigration: 625M
59+
parallelMigrationsPerCluster: 2
60+
parallelOutboundMigrationsPerNode: 1
61+
asserts:
62+
- equal:
63+
path: spec.configuration.migrations
64+
value:
65+
bandwidthPerMigration: 625M
66+
parallelMigrationsPerCluster: 2
67+
parallelOutboundMigrationsPerNode: 1
68+
69+
- it: preserves false and zero migration values
70+
set:
71+
migrations:
72+
allowAutoConverge: false
73+
completionTimeoutPerGiB: 0
74+
asserts:
75+
- equal:
76+
path: spec.configuration.migrations
77+
value:
78+
allowAutoConverge: false
79+
completionTimeoutPerGiB: 0
3880

3981
- it: emits cpuAllocationRatio under developerConfiguration when set
4082
set:

‎packages/system/kubevirt/tests/update_idempotency_test.sh‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ trap 'rm -rf "$tmpdir"' EXIT
6161
PHD='{{- with .Values.permittedHostDevices }}'
6262
MDC='{{- with .Values.mediatedDevicesConfiguration }}'
6363
DFG='{{- range .Values.disabledFeatureGates }}'
64+
MIG='{{- with .Values.migrations }}'
6465

6566
# The disabledFeatureGates block, comment lines included, ending on the
6667
# featureGates: line that follows it. Cases below either delete this range or
@@ -108,7 +109,8 @@ for guard in \
108109
'{{- range .Values.extraFeatureGates }}' \
109110
"$DFG" \
110111
"$PHD" \
111-
"$MDC"; do
112+
"$MDC" \
113+
"$MIG"; do
112114
assert_count 1 "$guard" "$missing_mdev"
113115
done
114116

@@ -237,4 +239,38 @@ if ! grep -qF 'staticDisabledFeatureGates := ' "$headerless_log"; then
237239
fail "make update did not name the missing guard-header line: $(cat "$headerless_log")"
238240
fi
239241

242+
# A hand-merge may drop migrations while preserving both device blocks.
243+
# Restoring it must reproduce the committed template, including the YAML key
244+
# and indentation, rather than merely reintroduce the directive.
245+
missing_migrations="$tmpdir/missing-migrations.yaml"
246+
sed '/{{- with .Values.migrations }}/,/{{- end }}/d' "$src" >"$missing_migrations"
247+
assert_absent "$MIG" "$missing_migrations"
248+
assert_present "$PHD" "$missing_migrations"
249+
assert_present "$MDC" "$missing_migrations"
250+
if ! run_update "$missing_migrations"; then
251+
fail "make update exited non-zero on a template missing only migrations"
252+
fi
253+
assert_present "$MIG" "$missing_migrations"
254+
if ! diff -u "$src" "$missing_migrations" >/dev/null; then
255+
fail "make update rebuilt migrations differently from the committed template"
256+
fi
257+
run_update "$missing_migrations"
258+
assert_count 1 "$MIG" "$missing_migrations"
259+
if ! diff -u "$src" "$missing_migrations" >/dev/null; then
260+
fail "repeated make update changed the restored migrations template"
261+
fi
262+
263+
# sed succeeds even when its insertion anchor is absent; the target's sanity
264+
# check must reject a hand-merged CR that cannot restore migration settings.
265+
anchorless_migrations="$tmpdir/anchorless-migrations.yaml"
266+
sed -e '/{{- with .Values.migrations }}/,/{{- end }}/d' \
267+
-e '/^ evictionStrategy:/d' "$src" >"$anchorless_migrations"
268+
anchorless_migrations_log="$tmpdir/anchorless-migrations.log"
269+
if run_update_logged "$anchorless_migrations" "$anchorless_migrations_log"; then
270+
fail "make update exited zero without the migrations block or its evictionStrategy anchor"
271+
fi
272+
if ! grep -qF "directive '$MIG' not inserted" "$anchorless_migrations_log"; then
273+
fail "make update did not name the missing migrations directive: $(cat "$anchorless_migrations_log")"
274+
fi
275+
240276
echo "PASS update_idempotency_test"

‎packages/system/kubevirt/values.yaml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,10 @@ permittedHostDevices: {}
7070
# mediatedDeviceTypes:
7171
# - nvidia-740
7272
mediatedDevicesConfiguration: {}
73+
74+
# Passed to spec.configuration.migrations on the KubeVirt CR.
75+
# Empty leaves KubeVirt's migration defaults unchanged.
76+
# bandwidthPerMigration is a quantity in bytes per second.
77+
# Set through spec.components.platform.values.kubevirt.migrations
78+
# on the cozystack.cozystack-platform Package.
79+
migrations: {}

0 commit comments

Comments
 (0)