Skip to content

Commit 648cd71

Browse files
authored
Merge pull request #96 from Jont828/v1beta2-conditions
Add frontend implementation for v1beta2 conditions
2 parents 2038942 + 966e9fa commit 648cd71

File tree

6 files changed

+84
-71
lines changed

6 files changed

+84
-71
lines changed

internal/describe_cluster.go

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ type ClusterResourceNode struct {
3939
CollapseOnClick bool `json:"collapseOnClick"`
4040
Collapsible bool `json:"collapsible"`
4141
Collapsed bool `json:"collapsed"`
42-
Ready bool `json:"ready"`
43-
Severity string `json:"severity"`
44-
HasReady bool `json:"hasReady"`
42+
Status metav1.ConditionStatus `json:"status"`
43+
HasStatus bool `json:"hasStatus"`
4544
Children []*ClusterResourceNode `json:"children"`
4645
}
4746

@@ -123,7 +122,7 @@ func objectTreeToResourceTree(ctx context.Context, objTree *tree.ObjectTree, obj
123122
}
124123
node.Provider = provider
125124

126-
setReadyFields(object, node)
125+
setStatusFields(object, node)
127126

128127
childTrees := []*ClusterResourceNode{}
129128
for _, child := range children {
@@ -170,9 +169,8 @@ func addAddonsGroupNode(_ context.Context, children []*ClusterResourceNode) []*C
170169
CollapseOnClick: true,
171170
Collapsible: true,
172171
Collapsed: false,
173-
HasReady: false,
174-
Ready: true,
175-
Severity: "",
172+
HasStatus: false,
173+
Status: "",
176174
UID: "addons",
177175
}
178176

@@ -229,9 +227,8 @@ func createKindGroupNode(ctx context.Context, namespace string, kind string, pro
229227
CollapseOnClick: true,
230228
Collapsible: true,
231229
Collapsed: true,
232-
HasReady: false,
233-
Ready: true,
234-
Severity: "",
230+
HasStatus: false,
231+
Status: "",
235232
UID: kind + ": ",
236233
}
237234

@@ -252,9 +249,8 @@ func createKindGroupNode(ctx context.Context, namespace string, kind string, pro
252249
Collapsible: true,
253250
Collapsed: true,
254251
Children: []*ClusterResourceNode{},
255-
HasReady: false,
256-
Ready: true,
257-
Severity: "",
252+
HasStatus: false,
253+
Status: "",
258254
UID: kind + ": ",
259255
}
260256
}
@@ -269,14 +265,12 @@ func createKindGroupNode(ctx context.Context, namespace string, kind string, pro
269265
groupParent.Group = child.Group
270266
groupParent.Version = child.Version
271267
groupParent.UID += child.UID + " "
272-
if child.HasReady {
273-
groupNode.HasReady = true
274-
groupNode.Ready = child.Ready && groupNode.Ready
275-
groupNode.Severity = updateSeverityIfMoreSevere(groupNode.Severity, child.Severity)
276-
// Set severity based on most severe child, i.e. Error > Warning > Info > Success
277-
groupParent.HasReady = true
278-
groupParent.Ready = child.Ready && groupParent.Ready
279-
groupParent.Severity = updateSeverityIfMoreSevere(groupParent.Severity, child.Severity)
268+
if child.HasStatus {
269+
groupNode.HasStatus = true
270+
groupNode.Status = updateStatusIfMoreSevere(groupNode.Status, child.Status)
271+
// Set severity based on most severe child, i.e. False > Unknown > True (assuming positive polarity)
272+
groupParent.HasStatus = true
273+
groupParent.Status = updateStatusIfMoreSevere(groupParent.Status, child.Status)
280274
}
281275
} else {
282276
resultChildren = append(resultChildren, child)

internal/helpers.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,22 @@ func getObjList(ctx context.Context, c ctrlclient.Client, typeMeta metav1.TypeMe
4141
return objList, nil
4242
}
4343

44-
// updateSeverityIfMoreSevere takes an existing severity and a new severity and returns the more severe of the two based on the rule that Error > Warning > Info > None.
45-
// This is used to determine the severity of a group node, i.e. a node representing 2 Machines in the DescribeCluster resource tree.
46-
func updateSeverityIfMoreSevere(existingSev string, newSev string) string {
44+
// updateStatusIfMoreSevere takes an existing Status and a new Status and returns the more severe of the two based on the rule that False > Unknown > True.
45+
// Since Ready and Available conditions are used to determine the status of an object, both of which have positive polarity, we do not need to consider negative polarity conditions here.
46+
// This is used to determine the Status of a group node, i.e. a node representing 2 Machines in the DescribeCluster resource tree.
47+
func updateStatusIfMoreSevere(existingStatus metav1.ConditionStatus, newStatus metav1.ConditionStatus) metav1.ConditionStatus {
4748
switch {
48-
case existingSev == "":
49-
return newSev
50-
case existingSev == "Info":
51-
if newSev == "Error" || newSev == "Warning" {
52-
return newSev
53-
}
54-
return existingSev
55-
case existingSev == "Warning":
56-
if newSev == "Error" {
57-
return newSev
58-
}
59-
return existingSev
60-
case existingSev == "Error":
61-
return existingSev
49+
case existingStatus == "":
50+
return newStatus
51+
case existingStatus == metav1.ConditionTrue:
52+
return newStatus
53+
case existingStatus == metav1.ConditionFalse:
54+
return existingStatus
55+
case existingStatus == metav1.ConditionUnknown && newStatus == metav1.ConditionFalse:
56+
return newStatus
6257
}
6358

64-
return existingSev
59+
return existingStatus
6560
}
6661

6762
// getProvider returns the provider type for an object in the Cluster resource tree. If the object is a virtual object and its kind is
@@ -135,12 +130,17 @@ func getDisplayName(object ctrlclient.Object) string {
135130
return displayName
136131
}
137132

138-
// setReadyFields sets a marker on if an object has a ready condtion, and if so, whether it is ready or not and the severity of the condition.
139-
func setReadyFields(object ctrlclient.Object, node *ClusterResourceNode) {
140-
if readyCondition := tree.GetReadyCondition(object); readyCondition != nil {
141-
node.HasReady = true
142-
node.Ready = readyCondition.Status == metav1.ConditionTrue // string comparison
143-
node.Severity = "" // No Severity field; optionally use readyCondition.Reason or Message if needed
133+
// setStatusFields sets a marker on if an object has a ready condtion, and if so, whether it is ready or not and the severity of the condition.
134+
func setStatusFields(object ctrlclient.Object, node *ClusterResourceNode) {
135+
// Note: Ready and Available conditions always have positive polarity.
136+
137+
// Available condition takes precedence over Ready condition. Note, clusterctl uses Ready over Available for Machines, which have both.
138+
if available := tree.GetAvailableCondition(object); available != nil {
139+
node.HasStatus = true
140+
node.Status = available.Status
141+
} else if readyCondition := tree.GetReadyCondition(object); readyCondition != nil {
142+
node.HasStatus = true
143+
node.Status = readyCondition.Status
144144
}
145145
}
146146

web/src/components/CustomResourceDefinition.vue

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
<v-tooltip
7474
:top="scrollY <= 20"
7575
:bottom="scrollY > 20"
76-
:disabled="condition.status === 'True'"
7776
>
7877
<template v-slot:activator="{ on, attrs }">
7978
<v-chip
@@ -90,7 +89,7 @@
9089
v-on="on"
9190
>
9291
<StatusIcon
93-
:type="condition.status === 'True' ? 'success' : (condition.Status === 'Unknown' ? 'unknown' : (condition.severity ? condition.severity.toLowerCase() : 'unknown' ))"
92+
:type="getIconType(condition)"
9493
:spinnerWidth="2"
9594
left
9695
>
@@ -99,10 +98,7 @@
9998
{{ condition.type }}
10099
</v-chip>
101100
</template>
102-
<span v-if="condition.severity && condition.reason">{{ condition.severity }}: {{ condition.reason }}</span>
103-
<span v-else-if="condition.severity">{{ condition.severity }}</span>
104-
<span v-else-if="condition.reason">{{ condition.reason }}</span>
105-
<span v-else>Unknown</span>
101+
<span> {{ condition.reason }}</span>
106102
</v-tooltip>
107103
</div>
108104
</div>
@@ -189,6 +185,15 @@ export default {
189185
conditions: [],
190186
url: "",
191187
scrollY: 0,
188+
negativePolarityConditions: new Set([
189+
"Paused",
190+
"Deleting",
191+
"RollingOut",
192+
"ScalingUp",
193+
"ScalingDown",
194+
"MachineUpdating",
195+
"Remediating",
196+
]),
192197
};
193198
},
194199
mounted() {
@@ -202,10 +207,25 @@ export default {
202207
console.log("URL is", this.url);
203208
},
204209
methods: {
210+
getIconType(condition) {
211+
let negativePolarity = this.negativePolarityConditions.has(condition.type);
212+
if (condition.status === "True") {
213+
if (negativePolarity) return "error";
214+
return "success";
215+
} else if (condition.status === "False") {
216+
if (negativePolarity) return "success";
217+
return "error";
218+
} else {
219+
return "unknown";
220+
}
221+
},
205222
getType(condition) {
206-
if (condition.status === "True") return "success";
207-
else if (condition.isError || !condition.severity || condition.status === "Unknown") return "error"; // if severity is undefined, we assume it's an error
208-
else return "warning";
223+
let type = this.getIconType(condition);
224+
if (type === "unknown") {
225+
return "warning";
226+
} else {
227+
return type;
228+
}
209229
},
210230
onScroll(e) {
211231
this.scrollY = window.scrollY;

web/src/components/DescribeClusterTree.vue

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@
110110
</v-hover>
111111

112112
<StatusBadge
113-
v-if="node.hasReady"
114-
:type="(node.ready) ? 'success' : node.severity.toLowerCase()"
113+
v-if="node.hasStatus"
114+
:type="getStatusType(node)"
115115
:size="18"
116116
></StatusBadge>
117117
</div>
@@ -175,6 +175,18 @@ export default {
175175
selectedNode: Object,
176176
legend: Object,
177177
},
178+
methods: {
179+
getStatusType(node) {
180+
// Note:
181+
if (node.status === "True") {
182+
return "success";
183+
} else if (node.status === "False") {
184+
return "error";
185+
} else { // Handles the case for node.status === "Unknown"
186+
return "warning";
187+
}
188+
},
189+
}
178190
};
179191
</script>
180192

web/src/components/StatusBadge.vue

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,6 @@ export default {
6060
return this.$vuetify.theme.dark ? "dark" : "light";
6161
},
6262
},
63-
methods: {
64-
getColor() {
65-
switch (this.type) {
66-
case "ready":
67-
return colors.green.base;
68-
case "error":
69-
return colors.red.accent2;
70-
case "loading":
71-
return colors.orange.darken1;
72-
default:
73-
return colors.grey;
74-
}
75-
},
76-
},
7763
};
7864
</script>
7965

web/src/components/StatusIcon.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,10 @@ export default {
125125
},
126126
methods: {
127127
getColor(type) {
128+
console.log("Getting color for type", type);
128129
if (!this.circle) return "";
129130
130-
if (type === "unknown") return "error";
131+
if (type == "unknown") return "error";
131132
132133
if (this.spinner && (type === "warning" || type === "info"))
133134
return "warning";

0 commit comments

Comments
 (0)