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

🌱 Replace disable-grouping with grouping option in clusterctl describe command #5550

Merged
merged 1 commit into from
Dec 3, 2021

Conversation

DiptoChakrabarty
Copy link
Member

🌱

What this PR does / why we need it: This deprecates the disable-grouping(false) option in the clusterctl describe and uses the grouping(true) option as per the issue

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 #5346 (working on)

Comments in the files haven't been updated yet , wanted to know if I am taking the right approach for this

Selection_047

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 1, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @DiptoChakrabarty. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 1, 2021
@ykakarap
Copy link
Contributor

ykakarap commented Nov 2, 2021

/rename 🌱 Replace disable-grouping with grouping option in clusterctl describe command

@ykakarap
Copy link
Contributor

ykakarap commented Nov 2, 2021

/cc

@ykakarap
Copy link
Contributor

ykakarap commented Nov 2, 2021

@DiptoChakrabarty Thanks for the PR!! 🚀

Two PR clean up items:

  • Please squash all the commits into a single one
  • Also, please rename the PR to have 🌱 at the beginning of the name. This way the workflow PRs will pass and then the actual test pipeline will be able to run.

Copy link
Contributor

@ykakarap ykakarap left a comment

Choose a reason for hiding this comment

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

@DiptoChakrabarty Can you also please update the tests to use the new Grouping field. The tests seem to still be using DisableGrouping.

@@ -58,7 +58,7 @@ type describeClusterOptions struct {
showOtherConditions string
showMachineSets bool
disableNoEcho bool
disableGrouping bool
Grouping bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Grouping bool
grouping bool

The field can remain private.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done with this

@@ -110,7 +110,7 @@ func init() {

describeClusterClusterCmd.Flags().BoolVar(&dc.disableNoEcho, "disable-no-echo", false, ""+
"Disable hiding of a MachineInfrastructure and BootstrapConfig when ready condition is true or it has the Status, Severity and Reason of the machine's object.")
describeClusterClusterCmd.Flags().BoolVar(&dc.disableGrouping, "disable-grouping", false,
describeClusterClusterCmd.Flags().BoolVar(&dc.Grouping, "grouping", true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
describeClusterClusterCmd.Flags().BoolVar(&dc.Grouping, "grouping", true,
describeClusterClusterCmd.Flags().BoolVar(&dc.grouping, "grouping", true,

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -138,7 +138,7 @@ func runDescribeCluster(name string) error {
ShowOtherConditions: dc.showOtherConditions,
ShowMachineSets: dc.showMachineSets,
DisableNoEcho: dc.disableNoEcho,
DisableGrouping: dc.disableGrouping,
Grouping: dc.Grouping,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Grouping: dc.Grouping,
Grouping: dc.grouping,

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

cmd/clusterctl/client/describe.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/tree/discovery.go Outdated Show resolved Hide resolved
Comment on lines 46 to 51
// DisableGrouping disables grouping sibling objects in case the ready condition
// has the same Status, Severity and Reason
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as the other places.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -140,7 +140,7 @@ func (od ObjectTree) Add(parent, obj client.Object, opts ...AddObjectOption) (ad
// If it is requested that the child of this node should be grouped in case the ready condition
// has the same Status, Severity and Reason, add the GroupingObjectAnnotation to signal
// this to the presentation layer.
if addOpts.GroupingObject && !od.options.DisableGrouping {
if addOpts.GroupingObject && !od.options.Grouping {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if addOpts.GroupingObject && !od.options.Grouping {
if addOpts.GroupingObject && od.options.Grouping {

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 2, 2021
@DiptoChakrabarty DiptoChakrabarty changed the title Replace disable-grouping with grouping option in clusterctl describe command 🌱 🌱 Replace disable-grouping with grouping option in clusterctl describe command Nov 2, 2021
@DiptoChakrabarty
Copy link
Member Author

Two PR clean up items:

Done both

@fabriziopandini
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 5, 2021
cmd/clusterctl/client/tree/discovery_test.go Outdated Show resolved Hide resolved
@@ -110,6 +111,9 @@ func init() {

describeClusterClusterCmd.Flags().BoolVar(&dc.disableNoEcho, "disable-no-echo", false, ""+
"Disable hiding of a MachineInfrastructure and BootstrapConfig when ready condition is true or it has the Status, Severity and Reason of the machine's object.")
describeClusterClusterCmd.Flags().BoolVar(&dc.grouping, "grouping", true,
"Disable grouping machines when ready condition has the same Status, Severity and Reason.")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"Disable grouping machines when ready condition has the same Status, Severity and Reason.")
"Groups machines when ready condition has the same Status, Severity and Reason.")

cmd/clusterctl/cmd/describe_cluster.go Show resolved Hide resolved
@fabriziopandini
Copy link
Member

Note.
What is important is to not remove the flag and deprecate it, given that a flag is a user contract.
Instead, it is fine to remove the field in DescribeClusterOptions.
@DiptoChakrabarty let me know if you need more clarifications about this point

@DiptoChakrabarty
Copy link
Member Author

Instead, it is fine to remove the field in DescribeClusterOptions.

Okay so if I am understanding correctly instead of having the DisableGrouping option it is fine to use the Grouping option in the DescribeClusterOptions(

type DescribeClusterOptions struct {
// Kubeconfig defines the kubeconfig to use for accessing the management cluster. If empty,
// default rules for kubeconfig discovery will be used.
Kubeconfig Kubeconfig
// Namespace where the workload cluster is located. If unspecified, the current namespace will be used.
Namespace string
// ClusterName to be used for the workload cluster.
ClusterName string
// ShowOtherConditions is a list of comma separated kind or kind/name for which we should add the ShowObjectConditionsAnnotation
// to signal to the presentation layer to show all the conditions for the objects.
ShowOtherConditions string
// ShowMachineSets instructs the discovery process to include machine sets in the ObjectTree.
ShowMachineSets bool
// DisableNoEcho disable hiding MachineInfrastructure or BootstrapConfig objects if the object's ready condition is true
// or it has the same Status, Severity and Reason of the parent's object ready condition (it is an echo)
DisableNoEcho bool
// DisableGrouping disable grouping machines objects in case the ready condition
// has the same Status, Severity and Reason
DisableGrouping bool
)

however in case of the disable-grouping flag that must be set to false as default opposite of the grouping flag set to true

So when disable-grouping option is provided grouping will not occur , however when grouping option is provided the output is grouped(all managed by the Grouping option in the DescribeClusterOptions) am I thinking correctly

@fabriziopandini
Copy link
Member

yes, or in other words
DescribeClusterOptions.Grouping = (grouping flag) && !(disable-grouping flag)

@DiptoChakrabarty
Copy link
Member Author

Okay working on it

@@ -138,7 +140,7 @@ func runDescribeCluster(name string) error {
ShowOtherConditions: dc.showOtherConditions,
ShowMachineSets: dc.showMachineSets,
DisableNoEcho: dc.disableNoEcho,
DisableGrouping: dc.disableGrouping,
Grouping: dc.grouping,
Copy link
Member

Choose a reason for hiding this comment

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

this should be

Suggested change
Grouping: dc.grouping,
Grouping: dc.grouping && !dc.disableGrouping,

Copy link
Member Author

Choose a reason for hiding this comment

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

added it

describeClusterClusterCmd.Flags().BoolVar(&dc.disableGrouping, "disable-grouping", false,
describeClusterClusterCmd.Flags().BoolVar(&dc.grouping, "grouping", true,
"Groups machines when ready condition has the same Status, Severity and Reason.")
describeClusterClusterCmd.Flags().BoolVar(&dc.grouping, "disable-grouping", false,
Copy link
Member

Choose a reason for hiding this comment

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

You can't have two flags using the same variable

Suggested change
describeClusterClusterCmd.Flags().BoolVar(&dc.grouping, "disable-grouping", false,
describeClusterClusterCmd.Flags().BoolVar(&dc.disableGrouping, "disable-grouping", false,

Also the flag should be deprecated as per https://pkg.go.dev/github.com/spf13/pflag#readme-deprecating-a-flag-or-its-shorthand

Copy link
Member Author

Choose a reason for hiding this comment

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

yes marked it as deprecated

cmd/clusterctl/cmd/describe_cluster.go Show resolved Hide resolved
@ykakarap
Copy link
Contributor

ykakarap commented Nov 8, 2021

@DiptoChakrabarty After addressing @fabriziopandini comments, please swash all the commits into a single commit. :)

@DiptoChakrabarty
Copy link
Member Author

Hey I am not sure why the test is failing in the control plane grouping check case in this line

g.Expect(IsGroupingObject(obj)).To(BeTrue())

I tried checking the condition which enables the grouping annotation based on here

if addOpts.GroupingObject && !od.options.DisableGrouping {
addAnnotation(obj, GroupingObjectAnnotation, "True")
}
and what I can assume is that the second part of the condition is not being fulfilled in the control plane case (ie od.options.Grouping is not true in this case which has been modified in my PR)

I tried printing them while running it
image
this is coming as false , I am not sure what I am doing wrong here or what I need to fix

@fabriziopandini
Copy link
Member

I will try to get a look at the error asap

@fabriziopandini
Copy link
Member

@DiptoChakrabarty The "Discovery with default discovery settings" test is failing because it was written under the assumption that grouping should be disabled by default. With the changes introduced by this PR to achieve the default configuration in this change you now have to change

discoverOptions: DiscoverOptions{},

into

				discoverOptions: DiscoverOptions{
					Grouping: true,
				},

Also, please note that the flag deprecation is not yet properly implemented.
Could you change:

describeClusterClusterCmd.Flags().MarkDeprecated("disable-grouping",
"--Deprecated use grouping option instead,Disable grouping machines when ready condition has the same Status, Severity and Reason.")

Into

	describeClusterClusterCmd.Flags().BoolVar(&dc.disableGrouping, "disable-grouping", false,
		"Disable grouping machines when ready condition has the same Status, Severity and Reason.")
	describeClusterClusterCmd.Flags().MarkDeprecated("disable-grouping",
		"use --grouping instead.")

If you don't mind, the last two nits:

clusterctl describe cluster test-1 --disable-grouping

should be changed into

		clusterctl describe cluster test-1 --grouping=false

And

clusterctl describe cluster test-1`),

Is missing the --disable-no-echo flag, so it should be modified into

		clusterctl describe cluster test-1 --disable-no-echo`),

With this changes everything should be ok (tested locally), so please squash commits

@DiptoChakrabarty
Copy link
Member Author

grouping should be disabled by default. With the changes introduced by this PR to achieve the default configuration in this change you now have to change

okay sure doing it

@DiptoChakrabarty
Copy link
Member Author

Updated them

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.

@DiptoChakrabarty thanks!
@ykakarap PTAL

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 30, 2021
Copy link
Contributor

@ykakarap ykakarap left a comment

Choose a reason for hiding this comment

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

Overall LGTM.
Just some minor nits.

// has the same Status, Severity and Reason
DisableGrouping bool
// Grouping groups machines objects in case the ready conditions
// have the same Status, Severity and Reason
Copy link
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change
// have the same Status, Severity and Reason
// have the same Status, Severity and Reason.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

// has the same Status, Severity and Reason
DisableGrouping bool
// Grouping groups machine objects in case the ready conditions
// have the same Status, Severity and Reason
Copy link
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change
// have the same Status, Severity and Reason
// have the same Status, Severity and Reason.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@@ -442,15 +442,15 @@ func Test_Add_setsGroupingObjectAnnotation(t *testing.T) {
{
name: "should add the annotation if requested to",
Copy link
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change
name: "should add the annotation if requested to",
name: "should add the annotation if requested to and grouping is enabled",

Copy link
Member Author

Choose a reason for hiding this comment

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

added

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 2, 2021
@DiptoChakrabarty
Copy link
Member Author

/retest

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Dec 2, 2021

@DiptoChakrabarty: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cluster-api-apidiff-main e333b97 link false /test pull-cluster-api-apidiff-main

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

Copy link
Contributor

@ykakarap ykakarap left a comment

Choose a reason for hiding this comment

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

Thanks for all the fixes :)

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 2, 2021
@ykakarap
Copy link
Contributor

ykakarap commented Dec 2, 2021

@fabriziopandini Out of curiosity: When we want to replace public functions we deprecate the old function and add a new one. Do we also have to do the same for public fields in public types?

@fabriziopandini
Copy link
Member

@fabriziopandini Out of curiosity: When we want to replace public functions we deprecate the old function and add a new one. Do we also have to do the same for public fields in public types?

We provide guarantees for API and CLI surface, while instead of for code we are allowed to do breaking changes between minor releases. more in https://github.com/kubernetes-sigs/cluster-api/blob/main/CONTRIBUTING.md

@fabriziopandini
Copy link
Member

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fabriziopandini

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

The pull request process is described 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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 3, 2021
@k8s-ci-robot k8s-ci-robot merged commit 6780524 into kubernetes-sigs:main Dec 3, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.1 milestone Dec 3, 2021
@DiptoChakrabarty DiptoChakrabarty deleted the describe branch December 29, 2021 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possible improvements for clusterctl describe
4 participants