Skip to content

Commit 24537cf

Browse files
committed
feat(dashboard): turn the status badge amber while a disk is not populated
The console badge followed Ready alone, and Ready follows the Helm release. A vm-disk install does not wait on its DataVolume, so a disk CDI never populated was painted green. The badge now shows the WorkloadsReady condition while Ready is True and WorkloadsReady is not True with reason DataVolumeNotReady. Other causes of WorkloadsReady=False keep the badge as it was: a stopped VM has no pod and reports not operational on purpose, and turning it amber for every kind needs its own decision. A failing Ready still wins, because it is the more specific cause. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent 6beca3d commit 24537cf

2 files changed

Lines changed: 69 additions & 1 deletion

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { describe, it, expect } from "vitest"
2+
import type { K8sCondition } from "@cozystack/k8s-client"
3+
import type { ApplicationInstance } from "@cozystack/types"
4+
import { readyCondition } from "./status.ts"
5+
6+
function instance(kind: string, ...conditions: K8sCondition[]): ApplicationInstance {
7+
return {
8+
apiVersion: "apps.cozystack.io/v1alpha1",
9+
kind,
10+
metadata: { name: "x" },
11+
status: { conditions },
12+
} as ApplicationInstance
13+
}
14+
15+
const ready: K8sCondition = { type: "Ready", status: "True", reason: "InstallSucceeded" }
16+
17+
describe("readyCondition", () => {
18+
it("returns Ready when the application has no WorkloadsReady", () => {
19+
expect(readyCondition(instance("Postgres", ready))?.status).toBe("True")
20+
})
21+
22+
it("is not ready while a DataVolume is not ready, whatever Ready says", () => {
23+
const got = readyCondition(
24+
instance("VMDisk", ready, {
25+
type: "WorkloadsReady",
26+
status: "False",
27+
reason: "DataVolumeNotReady",
28+
message: "DataVolume x is ImportInProgress",
29+
}),
30+
)
31+
expect(got?.status).toBe("False")
32+
expect(got?.reason).toBe("DataVolumeNotReady")
33+
expect(got?.message).toBe("DataVolume x is ImportInProgress")
34+
})
35+
36+
// A stopped VM has no pod, so its monitor reports it not operational.
37+
it("stays ready for a halted VM whose workloads are not ready for no named reason", () => {
38+
const got = readyCondition(
39+
instance("VMInstance", ready, {
40+
type: "WorkloadsReady",
41+
status: "False",
42+
reason: "WorkloadMonitorCheck",
43+
message: "One or more workloads are not operational",
44+
}),
45+
)
46+
expect(got?.status).toBe("True")
47+
expect(got?.reason).toBe("InstallSucceeded")
48+
})
49+
50+
it("keeps a failing Ready ahead of the workloads", () => {
51+
const failed: K8sCondition = { type: "Ready", status: "False", reason: "InstallFailed" }
52+
const got = readyCondition(
53+
instance("VMDisk", failed, { type: "WorkloadsReady", status: "False", reason: "DataVolumeNotReady" }),
54+
)
55+
expect(got?.reason).toBe("InstallFailed")
56+
})
57+
})

‎packages/system/dashboard/images/console/apps/console/src/lib/status.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
import type { K8sCondition } from "@cozystack/k8s-client"
22
import type { ApplicationInstance } from "@cozystack/types"
33

4+
// Ready follows the Helm release only, so a vm-disk whose DataVolume never
5+
// populates is Ready. Other WorkloadsReady=False causes are left out on purpose:
6+
// a stopped VM has no pod and reports that too.
7+
const dataVolumeNotReady = "DataVolumeNotReady"
8+
49
export function readyCondition(
510
instance: ApplicationInstance | undefined,
611
): K8sCondition | undefined {
7-
return instance?.status?.conditions?.find((c) => c.type === "Ready")
12+
const conditions = instance?.status?.conditions
13+
const ready = conditions?.find((c) => c.type === "Ready")
14+
const workloads = conditions?.find((c) => c.type === "WorkloadsReady")
15+
if (ready?.status === "True" && workloads?.reason === dataVolumeNotReady && workloads.status !== "True") {
16+
return workloads
17+
}
18+
return ready
819
}
920

1021
export function formatAge(timestamp: string | undefined): string {

0 commit comments

Comments
 (0)