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

cmd/clusterctl/cmd/describe_cluster.go Outdated Show resolved Hide resolved
cmd/clusterctl/cmd/describe_cluster.go Outdated Show resolved Hide resolved
}(),
expectPrefix: []string{
"Object/root",
"│ 2",
Copy link
Member

Choose a reason for hiding this comment

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

I'm a little bit confused by seeing only the second line of the message (2) and not the first line (1).
Also, why are we not seeing condition status, reason, age?
Is this correct?

Copy link
Member Author

@tobiasgiese tobiasgiese Feb 5, 2025

Choose a reason for hiding this comment

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

It is just like the other/v1beta1 tests, we just check the prefix. We cannot ensure the age, thus we should only verify the prefix here.

tests := []struct {
name string
objectTree *tree.ObjectTree
expectPrefix []string
Copy link
Member

Choose a reason for hiding this comment

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

Should this be

Suggested change
expectPrefix []string
expectOutput []string

or expectedTable given that it is more than the simple prefix

Copy link
Member Author

Choose a reason for hiding this comment

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

Just copied from the v1beta1 test above :) can change it, but I should change it in both cases then

@@ -294,6 +294,154 @@ func Test_TreePrefix(t *testing.T) {
}
}

func Test_V1Beta2TreePrefix(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

might be

Suggested change
func Test_V1Beta2TreePrefix(t *testing.T) {
func Test_addObjectRowV1Beta2(t *testing.T) {

(this is what we are testing)

Copy link
Member Author

Choose a reason for hiding this comment

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

Same again as for the above comments, I copied it from the v1beta1 test

}
// We just want to indent the multiline message for the Ready condition.
// All ├─ should be replaced by |, so all the existing hierarchic dependencies are carried on
multilinePrefix = strings.ReplaceAll(prefix+childrenPipe+filler, firstElemPrefix, pipe)
Copy link
Member

Choose a reason for hiding this comment

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

I'm a little bit confused by having a filler at the end of the prefix given that what comes next goes in a different column (and so it automatically goes in the right position, no need to indent)
Same below for the additional spaces

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a copy from the code for the conditions

childPrefix := getChildPrefix(prefix+childrenPipe+filler, i, len(conditions))
c, status, age, reason, message := v1Beta2ConditionInfo(condition, positivePolarity)

This is necessary as the objects condition might have a multiline message and should be handled exactly as conditions via --show-conditions

Copy link
Member Author

@tobiasgiese tobiasgiese Feb 5, 2025

Choose a reason for hiding this comment

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

Maybe it makes sense to reference addOtherConditionsV1Beta2() and getChildPrefix() in a comment

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
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