Skip to content

Commit 4af631c

Browse files
Address comments
1 parent 19f02b6 commit 4af631c

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

cmd/clusterctl/client/tree/tree.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -265,18 +265,22 @@ func (od ObjectTree) GetObjectsByParent(id types.UID) []client.Object {
265265
}
266266

267267
func hasSameAvailableReadyUptoDateStatusAndReason(availableA, availableB, readyA, readyB, upToDateA, upToDateB *metav1.Condition) bool {
268-
if ((availableA == nil) != (availableB == nil)) || ((availableA != nil && availableB != nil) && (availableA.Status != availableB.Status || availableA.Reason != availableB.Reason)) {
268+
if !hasSameStatusAndReason(availableA, availableB) {
269269
return false
270270
}
271-
272-
if ((readyA == nil) != (readyB == nil)) || ((readyA != nil && readyB != nil) && (readyA.Status != readyB.Status || readyA.Reason != readyB.Reason)) {
271+
if !hasSameStatusAndReason(readyA, readyB) {
273272
return false
274273
}
275-
276-
if ((upToDateA == nil) != (upToDateB == nil)) || ((upToDateA != nil && upToDateB != nil) && (upToDateA.Status != upToDateB.Status || upToDateA.Reason != upToDateB.Reason)) {
274+
if !hasSameStatusAndReason(upToDateA, upToDateB) {
277275
return false
278276
}
277+
return true
278+
}
279279

280+
func hasSameStatusAndReason(a, b *metav1.Condition) bool {
281+
if ((a == nil) != (b == nil)) || ((a != nil && b != nil) && (a.Status != b.Status || a.Reason != b.Reason)) {
282+
return false
283+
}
280284
return true
281285
}
282286

cmd/clusterctl/client/tree/util.go

+10
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,20 @@ func GetAvailableV1Beta2Condition(obj client.Object) *metav1.Condition {
5353
if getter, ok := obj.(v1beta2conditions.Getter); ok {
5454
return v1beta2conditions.Get(getter, clusterv1.AvailableV1Beta2Condition)
5555
}
56+
57+
if objUnstructured, ok := obj.(*unstructured.Unstructured); ok {
58+
c, err := v1beta2conditions.UnstructuredGet(objUnstructured, clusterv1.AvailableV1Beta2Condition)
59+
if err != nil {
60+
return nil
61+
}
62+
return c
63+
}
64+
5665
return nil
5766
}
5867

5968
// GetMachineUpToDateV1Beta2Condition returns machine's UpToDate condition, if defined.
69+
// Note: The UpToDate condition only exist on machines, so no need to support reading from unstructured.
6070
func GetMachineUpToDateV1Beta2Condition(obj client.Object) *metav1.Condition {
6171
if getter, ok := obj.(v1beta2conditions.Getter); ok {
6272
return v1beta2conditions.Get(getter, clusterv1.MachineUpToDateV1Beta2Condition)

cmd/clusterctl/cmd/describe_cluster.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ func addObjectRowV1Beta2(prefix string, tbl *tablewriter.Table, objectTree *tree
274274
// NOTE: The object name gets manipulated in order to improve readability.
275275
name := getRowName(obj)
276276

277-
// If we are going to should all conditions from this object, let's drop the condition picked in the rowDescriptor.
277+
// If we are going to show all conditions from this object, let's drop the condition picked in the rowDescriptor.
278278
if tree.IsShowConditionsObject(obj) {
279279
rowDescriptor.status = ""
280280
rowDescriptor.reason = ""

0 commit comments

Comments
 (0)