Skip to content

Commit 8051d49

Browse files
committed
fix(vm-default-images): wait for golden images to import before Ready
Every image is a DataVolume with immediate bind, so its import starts at install, but nothing waited for it: the HelmRelease went Ready as soon as helm applied the DataVolumes. An image that failed or stalled left the component green, and the failure surfaced later on a vm-disk cloning from it, far from the cause. Gate the release on the DataVolume phase. Only Succeeded counts as ready, and a Failed phase, when CDI sets one, ends the wait at once. Every other phase, and a missing status, keeps the wait open until the install window expires. There is no per-component timeout, so a download longer than that window is retried as an upgrade until it finishes, and the retry strategy never uninstalls the volumes. Signed-off-by: Aleksei Sviridkin <[email protected]> Assisted-by: LLM
1 parent a759190 commit 8051d49

3 files changed

Lines changed: 85 additions & 0 deletions

File tree

‎internal/operator/package_reconciler_test.go‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"encoding/json"
2121
"os"
2222
"path/filepath"
23+
"reflect"
2324
"testing"
2425
"time"
2526

@@ -281,3 +282,48 @@ func TestPackageSourceCRDHasUpgradeCRDsEnum(t *testing.T) {
281282
}
282283
}
283284
}
285+
286+
// TestVMDefaultImagesHelmReleaseWaitsForImport builds the HelmRelease spec from
287+
// the shipped vm-default-images PackageSource. Its DataVolumes start importing
288+
// at install, and without the gate the release is Ready before any image
289+
// exists, so the failure surfaces later on a vm-disk cloning from one.
290+
func TestVMDefaultImagesHelmReleaseWaitsForImport(t *testing.T) {
291+
path := filepath.Join("..", "..", "packages", "core", "platform", "sources", "vm-default-images.yaml")
292+
data, err := os.ReadFile(path)
293+
if err != nil {
294+
t.Fatalf("read %s: %v", path, err)
295+
}
296+
var ps cozyv1alpha1.PackageSource
297+
if err := yaml.Unmarshal(data, &ps); err != nil {
298+
t.Fatalf("unmarshal %s: %v", path, err)
299+
}
300+
301+
var install *cozyv1alpha1.ComponentInstall
302+
for _, v := range ps.Spec.Variants {
303+
for _, c := range v.Components {
304+
if c.Name == "vm-default-images" {
305+
install = c.Install
306+
}
307+
}
308+
}
309+
if install == nil {
310+
t.Fatalf("%s: component vm-default-images has no install block", path)
311+
}
312+
313+
spec := (&PackageReconciler{}).buildHelmReleaseSpec(install, "x")
314+
315+
want := []kustomize.CustomHealthCheck{{
316+
APIVersion: "cdi.kubevirt.io/v1beta1",
317+
Kind: "DataVolume",
318+
HealthCheckExpressions: kustomize.HealthCheckExpressions{
319+
Failed: "has(status.phase) && status.phase == 'Failed'",
320+
Current: "has(status.phase) && status.phase == 'Succeeded'",
321+
},
322+
}}
323+
if !reflect.DeepEqual(spec.HealthCheckExprs, want) {
324+
t.Errorf("HealthCheckExprs = %+v, want %+v", spec.HealthCheckExprs, want)
325+
}
326+
if spec.WaitStrategy == nil || spec.WaitStrategy.Name != helmv2.WaitStrategyPoller {
327+
t.Errorf("WaitStrategy = %+v, want poller: the expressions are not evaluated under any other strategy", spec.WaitStrategy)
328+
}
329+
}

‎packages/core/platform/sources/vm-default-images.yaml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,15 @@ spec:
2020
install:
2121
namespace: cozy-system
2222
releaseName: vm-default-images
23+
# Ready only once every image has imported: vm-disk clones from
24+
# these volumes and cannot tell an unfinished import from a done
25+
# one. Any phase other than Succeeded or Failed matches neither
26+
# expression and flux keeps waiting. There is no per-component
27+
# timeout, so a slow download outlasts the operator-wide install
28+
# window and is retried as an upgrade until it finishes; nothing
29+
# is uninstalled in between.
30+
healthCheckExprs:
31+
- apiVersion: cdi.kubevirt.io/v1beta1
32+
kind: DataVolume
33+
failed: "has(status.phase) && status.phase == 'Failed'"
34+
current: "has(status.phase) && status.phase == 'Succeeded'"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
suite: vm-default-images waits for its golden images to import
2+
# Every image is a DataVolume with immediate bind, so the import starts at
3+
# install. Without healthCheckExprs the HelmRelease goes Ready as soon as helm
4+
# has applied the DataVolumes, and an image that never imports stays green until
5+
# a vm-disk cloning from it breaks. current must hold only on Succeeded: a looser
6+
# expression lets an unfinished import pass.
7+
templates:
8+
- templates/sources.yaml
9+
release:
10+
name: cozystack
11+
namespace: cozy-system
12+
tests:
13+
- it: gates the vm-default-images component on DataVolume Succeeded
14+
documentSelector:
15+
path: metadata.name
16+
value: cozystack.vm-default-images
17+
asserts:
18+
- equal:
19+
path: spec.variants[0].components[0].name
20+
value: vm-default-images
21+
- equal:
22+
path: spec.variants[0].components[0].install.healthCheckExprs
23+
value:
24+
- apiVersion: cdi.kubevirt.io/v1beta1
25+
kind: DataVolume
26+
failed: "has(status.phase) && status.phase == 'Failed'"
27+
current: "has(status.phase) && status.phase == 'Succeeded'"

0 commit comments

Comments
 (0)