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

feat: delete cluster flag completion #3166

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

iyear
Copy link

@iyear iyear commented Apr 13, 2023

#3163

Preview:

asciicast

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 13, 2023
@k8s-ci-robot k8s-ci-robot requested a review from aojea April 13, 2023 10:42
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: iyear
Once this PR has been reviewed and has the lgtm label, please assign bentheelder for approval. For more information see the Kubernetes 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

@k8s-ci-robot
Copy link
Contributor

Welcome @iyear!

It looks like this is your first PR to kubernetes-sigs/kind 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/kind has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 13, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @iyear. 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 Apr 13, 2023
@@ -48,9 +48,14 @@ func NewCommand(logger log.Logger, streams cmd.IOStreams) *cobra.Command {
return deleteCluster(logger, flags)
},
}

var (
name = "name"
Copy link
Member

Choose a reason for hiding this comment

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

Nit: This should be a const not a var and it should have a more descriptive name or else just explicitly paste "name" into each location. It's not really clearer to have `const name = "name" and it's strictly worse to have it as a var.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks. Updated.


cobra.CheckErr(cmd.RegisterFlagCompletionFunc(name, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
clusters, err := cluster.NewProvider(
cluster.ProviderWithLogger(logger),
Copy link
Member

Choose a reason for hiding this comment

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

What happens when podman support is stable and we move from KIND_EXPERIMENTAL_PROVIDER to KIND_PROVIDER as a default for a --provider flag? Can flag completion check for other flag values?

This feature seems like it may unfortunately be at least as problematic to maintain as it is useful.

Using KIND_CLUSTER_NAME is another option to get around repeatedly typing these.

Copy link
Author

@iyear iyear Apr 18, 2023

Choose a reason for hiding this comment

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

What happens when podman support is stable and we move from KIND_EXPERIMENTAL_PROVIDER to KIND_PROVIDER as a default for a --provider flag?

Does this mean that the implementation of kind get clusters will change? The code in PR is copied from get clusters

Can flag completion check for other flag values?

Yes it can.

or extract get clusters as a common function, and we pass in the existing args and flags then get results.

Copy link
Member

Choose a reason for hiding this comment

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

Does this mean that the implementation of kind get clusters will change? The code in PR is copied from get clusters

Yes. It's defaulting based on availability or the env currently.

Copy link
Author

Choose a reason for hiding this comment

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

And how about extract kind get clusters runE as a common function ? IMO, the completion is like an alias of get clusters.

Copy link
Member

Choose a reason for hiding this comment

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

Sure, I've just never used a tool where one flag completed based on another flag and didn't know if cobra can support this. If it can then let's go ahead :-)

@iyear iyear force-pushed the feat/delete-cluster-flag-completion branch from 3a12be2 to 2b04d6d Compare April 18, 2023 05:25
Copy link
Member

@BenTheElder BenTheElder left a comment

Choose a reason for hiding this comment

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

sorry, i missed that my review comments were left in pending state

@@ -48,9 +48,14 @@ func NewCommand(logger log.Logger, streams cmd.IOStreams) *cobra.Command {
return deleteCluster(logger, flags)
},
}

const (
nameFlag = "name"
Copy link
Member

Choose a reason for hiding this comment

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

I still don't think this is more descriptive that "name" which is only used in two places anyhow ...

Copy link
Member

Choose a reason for hiding this comment

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

+1

Copy link
Author

Choose a reason for hiding this comment

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

Agreed. Done


cobra.CheckErr(cmd.RegisterFlagCompletionFunc(name, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
clusters, err := cluster.NewProvider(
cluster.ProviderWithLogger(logger),
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean that the implementation of kind get clusters will change? The code in PR is copied from get clusters

Yes. It's defaulting based on availability or the env currently.

@BenTheElder BenTheElder 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 May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants