Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix multiline Ready condition in clusterctl describe for v1beta2 #11781

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tobiasgiese
Copy link
Member

@tobiasgiese tobiasgiese commented Feb 1, 2025

The multiline feature in clusterctl has a bug in the multiline conditions.
If the Ready condition message has multipile lines the multiline prefix is not calculated properly.
To fix this we can use the same logic as for the other conditions and verify if the object is the last object in the tree.

What this PR does / why we need it:

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #11782

/area clusterctl

@k8s-ci-robot k8s-ci-robot added the area/clusterctl Issues or PRs related to clusterctl label Feb 1, 2025
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 1, 2025
Comment on lines +338 to +334
"Object/root",
"│ 2",
"├─Object/child1",
"│ 2",
"└─Object/child2",
Copy link
Member Author

@tobiasgiese tobiasgiese Feb 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the fix (where ? is no prefix)

Object/root              Available: False  NotAvailable  292y  1  
?                                                              2  
├─Object/child1          Available: False  NotAvailable  292y  1  
│                                                              2  
└─Object/child2          Available: False  NotAvailable  292y  1  
                                                               2  

Comment on lines +382 to +369
"Object/root",
"├─Object/child1",
"└─Object/child2",
" │ 2",
" └─Object/child2.1",
Copy link
Member Author

@tobiasgiese tobiasgiese Feb 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the fix

Object/root                  Available: True   Available     292y     
├─Object/child1              Available: True   Available     292y     
└─Object/child2              Available: False  NotAvailable  292y  1  
                                                                   2  
  └─Object/child2.1

@tobiasgiese tobiasgiese force-pushed the fix-multiline-parent-conditions-tests branch 4 times, most recently from 7f71cbc to 79b13f5 Compare February 1, 2025 11:17
@tobiasgiese tobiasgiese changed the title 🐛 Fix multiline Ready condition in clusterctl describe 🐛 Fix multiline Ready condition in clusterctl describe for v1beta2 Feb 1, 2025
@tobiasgiese tobiasgiese force-pushed the fix-multiline-parent-conditions-tests branch 5 times, most recently from c8bfa74 to 8c38475 Compare February 2, 2025 10:52
Comment on lines +451 to +419
"Object/root",
"├─Object/child1",
"├─Object/child2",
"│ │ 2",
"│ └─Object/child2.1",
"│ 2",
"└─Object/child3",
" │ 2",
" └─Object/child3.1",
" 2",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the fix

Object/root                  Available: True   Available     292y     
├─Object/child1              Available: True   Available     292y     
├─Object/child2              Available: False  NotAvailable  292y  1  
│                                                                  2  
│ └─Object/child2.1          Available: False  NotAvailable  292y  1  
│                                                                  2  
└─Object/child3              Available: False  NotAvailable  292y  1  
                                                                   2  
  └─Object/child3.1          Available: False  NotAvailable  292y  1  
                                                                   2 

@tobiasgiese tobiasgiese force-pushed the fix-multiline-parent-conditions-tests branch 4 times, most recently from ac341c5 to 3aa0b3b Compare February 2, 2025 11:32
@sbueringer
Copy link
Member

/assign @fabriziopandini

@tobiasgiese tobiasgiese force-pushed the fix-multiline-parent-conditions-tests branch from 3aa0b3b to eac73ac Compare February 5, 2025 08:21
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from fabriziopandini. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Member

@fabriziopandini fabriziopandini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a first quick pass, really appreciated the test with the example of the output before the change

The multiline feature in clusterctl has a bug in the multiline conditions.
If the Ready condition message has multipile lines the multiline prefix is not calculated properly.
To fix this we can use the same logic as for the other conditions and verify if the object is the last object in the tree.

Signed-off-by: Tobias Giese <[email protected]>
@tobiasgiese tobiasgiese force-pushed the fix-multiline-parent-conditions-tests branch from eac73ac to 3c489c9 Compare February 5, 2025 10:28
Copy link
Member

@fabriziopandini fabriziopandini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tobiasgiese sorry for the delay in the review, there is one last comment to be addressed, otherwise lgtm

Comment on lines +576 to +587
func getOrderedTreeObjects(objectTree *tree.ObjectTree) []ctrlclient.Object {
rootObjs := objectTree.GetObjectsByParent(objectTree.GetRoot().GetUID())
rootObjs = orderChildrenObjects(rootObjs)
objs := []ctrlclient.Object{objectTree.GetRoot()}
for _, obj := range rootObjs {
childrenObjs := objectTree.GetObjectsByParent(obj.GetUID())
childrenObjs = orderChildrenObjects(childrenObjs)
objs = append(objs, obj)
objs = append(objs, childrenObjs...)
}
return objs
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work when the last node is nested two (or more) levels, e.g.

NAME                                                                               REPLICAS  AVAILABLE  READY  UP TO DATE  STATUS            REASON            SINCE  MESSAGE                                                                                              
Cluster/classy-base-8                                                              2/4       0          0      2           Available: False  NotAvailable      ...                                                                                                                                                                                                     
└─Workers                                                                                                                                                                                                                                                                  
  └─MachineDeployment/classy-base-8-md1-4xc49                                      1/1       0          0      1           Available: False  NotAvailable      55m    0 available replicas, at least 1 required (spec.strategy.rollout.maxUnavailable is 0, spec.replicas  
                                                                                                                                                                      is 1)                                                                                                
    └─Machine/classy-base-8-md1-4xc49-w5696-lcdc6                                  1         0          0      1                                                                                                                                                           
            ...

(the line right after MachineDeployment doesn't have the right prefix)

I would also suggest that we compute the last node once up in the call stack (instead of recomputing it many time) and then pass it around

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If nested multiple times it's even worse - let me fix that


Object/root                    Available: True   Available     292y     
└─Object/child1                Available: True   Available     292y     
  └─Object/child2              Available: False  NotAvailable  292y  1  
                                                                     2
    └─Object/child3            Available: False  NotAvailable  292y  1  
    │                                                                2
      └─Object/child4          Available: False  NotAvailable  292y  1  
                                                                     2

Copy link
Member Author

@tobiasgiese tobiasgiese Feb 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also suggest that we compute the last node once up in the call stack (instead of recomputing it many time) and then pass it around

I don't know if this is possible as addObjectRowV1Beta2() is a recursion. If we only want to compute it once we can add a new field e.g. orderedItems to the ObjectTree.

Edit: we can just put the last object as an annotation to the root object on the first call, sounds reasonable to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/clusterctl Issues or PRs related to clusterctl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

V1beta2 clusterctl describe and multiline conditions not printed correctly
4 participants