Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziopandini committed Nov 25, 2024
1 parent 19f02b6 commit 4af631c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
14 changes: 9 additions & 5 deletions cmd/clusterctl/client/tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,18 +265,22 @@ func (od ObjectTree) GetObjectsByParent(id types.UID) []client.Object {
}

func hasSameAvailableReadyUptoDateStatusAndReason(availableA, availableB, readyA, readyB, upToDateA, upToDateB *metav1.Condition) bool {
if ((availableA == nil) != (availableB == nil)) || ((availableA != nil && availableB != nil) && (availableA.Status != availableB.Status || availableA.Reason != availableB.Reason)) {
if !hasSameStatusAndReason(availableA, availableB) {
return false
}

if ((readyA == nil) != (readyB == nil)) || ((readyA != nil && readyB != nil) && (readyA.Status != readyB.Status || readyA.Reason != readyB.Reason)) {
if !hasSameStatusAndReason(readyA, readyB) {
return false
}

if ((upToDateA == nil) != (upToDateB == nil)) || ((upToDateA != nil && upToDateB != nil) && (upToDateA.Status != upToDateB.Status || upToDateA.Reason != upToDateB.Reason)) {
if !hasSameStatusAndReason(upToDateA, upToDateB) {
return false
}
return true
}

func hasSameStatusAndReason(a, b *metav1.Condition) bool {
if ((a == nil) != (b == nil)) || ((a != nil && b != nil) && (a.Status != b.Status || a.Reason != b.Reason)) {
return false
}
return true
}

Expand Down
10 changes: 10 additions & 0 deletions cmd/clusterctl/client/tree/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,20 @@ func GetAvailableV1Beta2Condition(obj client.Object) *metav1.Condition {
if getter, ok := obj.(v1beta2conditions.Getter); ok {
return v1beta2conditions.Get(getter, clusterv1.AvailableV1Beta2Condition)
}

if objUnstructured, ok := obj.(*unstructured.Unstructured); ok {
c, err := v1beta2conditions.UnstructuredGet(objUnstructured, clusterv1.AvailableV1Beta2Condition)
if err != nil {
return nil
}
return c
}

return nil
}

// GetMachineUpToDateV1Beta2Condition returns machine's UpToDate condition, if defined.
// Note: The UpToDate condition only exist on machines, so no need to support reading from unstructured.
func GetMachineUpToDateV1Beta2Condition(obj client.Object) *metav1.Condition {
if getter, ok := obj.(v1beta2conditions.Getter); ok {
return v1beta2conditions.Get(getter, clusterv1.MachineUpToDateV1Beta2Condition)
Expand Down
2 changes: 1 addition & 1 deletion cmd/clusterctl/cmd/describe_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func addObjectRowV1Beta2(prefix string, tbl *tablewriter.Table, objectTree *tree
// NOTE: The object name gets manipulated in order to improve readability.
name := getRowName(obj)

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

0 comments on commit 4af631c

Please sign in to comment.