Skip to content

Commit 522ee20

Browse files
committed
feat(api): show WorkloadsReady in the Application table
Ready follows the Helm release, so for a kind whose install does not wait on its workloads, a vm-disk among them, READY in kubectl get says only that the manifests were applied. Whether the workloads came up lives in WorkloadsReady, which the default table did not show, so a disk CDI never populated looked healthy on the surface an operator reads first. The table now carries a WORKLOADS column beside READY. It reads <none> for an Application with no WorkloadMonitor, which has no WorkloadsReady condition at all. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent 761b293 commit 522ee20

2 files changed

Lines changed: 63 additions & 6 deletions

File tree

‎pkg/registry/apps/application/rest.go‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,7 @@ func (r *REST) buildTableFromApplications(apps []appsv1alpha1.Application) metav
18331833
ColumnDefinitions: []metav1.TableColumnDefinition{
18341834
{Name: "NAME", Type: "string", Description: "Name of the Application", Priority: 0},
18351835
{Name: "READY", Type: "string", Description: "Ready status of the Application", Priority: 0},
1836+
{Name: "WORKLOADS", Type: "string", Description: "Status of the WorkloadsReady condition, <none> when the Application has no WorkloadMonitor", Priority: 0},
18361837
{Name: "AGE", Type: "string", Description: "Age of the Application", Priority: 0},
18371838
{Name: "VERSION", Type: "string", Description: "Version of the Application", Priority: 0},
18381839
},
@@ -1843,7 +1844,7 @@ func (r *REST) buildTableFromApplications(apps []appsv1alpha1.Application) metav
18431844
for i := range apps {
18441845
app := &apps[i]
18451846
row := metav1.TableRow{
1846-
Cells: []any{app.GetName(), getReadyStatus(app.Status.Conditions), computeAge(app.GetCreationTimestamp().Time, now), getVersion(app.Status.Version)},
1847+
Cells: []any{app.GetName(), conditionStatus(app.Status.Conditions, "Ready", "Unknown"), conditionStatus(app.Status.Conditions, "WorkloadsReady", "<none>"), computeAge(app.GetCreationTimestamp().Time, now), getVersion(app.Status.Version)},
18471848
Object: runtime.RawExtension{Object: app},
18481849
}
18491850
table.Rows = append(table.Rows, row)
@@ -1858,6 +1859,7 @@ func (r *REST) buildTableFromApplication(app appsv1alpha1.Application) metav1.Ta
18581859
ColumnDefinitions: []metav1.TableColumnDefinition{
18591860
{Name: "NAME", Type: "string", Description: "Name of the Application", Priority: 0},
18601861
{Name: "READY", Type: "string", Description: "Ready status of the Application", Priority: 0},
1862+
{Name: "WORKLOADS", Type: "string", Description: "Status of the WorkloadsReady condition, <none> when the Application has no WorkloadMonitor", Priority: 0},
18611863
{Name: "AGE", Type: "string", Description: "Age of the Application", Priority: 0},
18621864
{Name: "VERSION", Type: "string", Description: "Version of the Application", Priority: 0},
18631865
},
@@ -1867,7 +1869,7 @@ func (r *REST) buildTableFromApplication(app appsv1alpha1.Application) metav1.Ta
18671869

18681870
a := app
18691871
row := metav1.TableRow{
1870-
Cells: []any{app.GetName(), getReadyStatus(app.Status.Conditions), computeAge(app.GetCreationTimestamp().Time, now), getVersion(app.Status.Version)},
1872+
Cells: []any{app.GetName(), conditionStatus(app.Status.Conditions, "Ready", "Unknown"), conditionStatus(app.Status.Conditions, "WorkloadsReady", "<none>"), computeAge(app.GetCreationTimestamp().Time, now), getVersion(app.Status.Version)},
18711873
Object: runtime.RawExtension{Object: &a},
18721874
}
18731875
table.Rows = append(table.Rows, row)
@@ -1897,10 +1899,11 @@ func computeAge(creationTime, currentTime time.Time) string {
18971899
return duration.HumanDuration(ageDuration)
18981900
}
18991901

1900-
// getReadyStatus returns the ready status based on conditions
1901-
func getReadyStatus(conditions []metav1.Condition) string {
1902+
// conditionStatus returns the status of the condition of the given type, or
1903+
// absent when there is none.
1904+
func conditionStatus(conditions []metav1.Condition, conditionType, absent string) string {
19021905
for _, condition := range conditions {
1903-
if condition.Type == "Ready" {
1906+
if condition.Type == conditionType {
19041907
switch condition.Status {
19051908
case metav1.ConditionTrue:
19061909
return "True"
@@ -1911,7 +1914,7 @@ func getReadyStatus(conditions []metav1.Condition) string {
19111914
}
19121915
}
19131916
}
1914-
return "Unknown"
1917+
return absent
19151918
}
19161919

19171920
// computeTenantNamespace computes the namespace for a Tenant application based on the specified logic
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package application
2+
3+
import (
4+
"testing"
5+
6+
appsv1alpha1 "github.com/cozystack/cozystack/pkg/apis/apps/v1alpha1"
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
)
9+
10+
func TestTableShowsWorkloadsReadyNextToReady(t *testing.T) {
11+
appWith := func(name string, conditions ...metav1.Condition) appsv1alpha1.Application {
12+
app := appsv1alpha1.Application{ObjectMeta: metav1.ObjectMeta{Name: name}}
13+
app.SetConditions(conditions)
14+
return app
15+
}
16+
ready := metav1.Condition{Type: "Ready", Status: metav1.ConditionTrue}
17+
cases := []struct {
18+
name string
19+
app appsv1alpha1.Application
20+
want string
21+
}{
22+
{"workloads not ready", appWith("a", ready, metav1.Condition{Type: "WorkloadsReady", Status: metav1.ConditionFalse}), "False"},
23+
{"workloads ready", appWith("b", ready, metav1.Condition{Type: "WorkloadsReady", Status: metav1.ConditionTrue}), "True"},
24+
{"workloads unknown", appWith("c", ready, metav1.Condition{Type: "WorkloadsReady", Status: metav1.ConditionUnknown}), "Unknown"},
25+
{"no workload monitor", appWith("d", ready), "<none>"},
26+
}
27+
r := &REST{}
28+
for _, tc := range cases {
29+
t.Run(tc.name, func(t *testing.T) {
30+
for _, table := range []metav1.Table{
31+
r.buildTableFromApplications([]appsv1alpha1.Application{tc.app}),
32+
r.buildTableFromApplication(tc.app),
33+
} {
34+
var names []string
35+
for _, c := range table.ColumnDefinitions {
36+
names = append(names, c.Name)
37+
}
38+
if len(names) < 3 || names[1] != "READY" || names[2] != "WORKLOADS" {
39+
t.Fatalf("columns = %v, want WORKLOADS right after READY", names)
40+
}
41+
if table.ColumnDefinitions[2].Priority != 0 {
42+
t.Errorf("WORKLOADS priority = %d, want 0 so kubectl shows it by default", table.ColumnDefinitions[2].Priority)
43+
}
44+
row := table.Rows[0].Cells
45+
if len(row) != len(names) {
46+
t.Fatalf("row has %d cells for %d columns", len(row), len(names))
47+
}
48+
if row[1] != "True" || row[2] != tc.want {
49+
t.Errorf("READY=%v WORKLOADS=%v, want True and %s", row[1], row[2], tc.want)
50+
}
51+
}
52+
})
53+
}
54+
}

0 commit comments

Comments
 (0)