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

Add validate cluster command to clusterctl #203

Merged
merged 1 commit into from
May 30, 2018

Conversation

wangzhen127
Copy link
Contributor

@wangzhen127 wangzhen127 commented May 23, 2018

What this PR does / why we need it:
This PR adds validate cluster command to clusterctl. It does not have real implementations yet. This is part of #168 and there will be follow-up PRs.

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 #

Special notes for your reviewer:

Release note:

NONE

@kubernetes/kube-deploy-reviewers

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels May 23, 2018
@k8s-ci-robot
Copy link
Contributor

Hi @wangzhen127. Thanks for your PR.

I'm waiting for a kubernetes or 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.

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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 23, 2018
@wangzhen127
Copy link
Contributor Author

Note that the 1st commit is basically #202. The 2nd commit is the actual PR that will be merged to add validate cluster command.

/cc @karan @jessicaochen

@wangzhen127
Copy link
Contributor Author

/hold
Should rebase and merge after #202 is merged first.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 23, 2018
@karan
Copy link
Contributor

karan commented May 24, 2018

I can't review this PR with 11k files. Can you take out the vendor changes and only have the core change in this PR please?

@wangzhen127
Copy link
Contributor Author

The benefit of including the 1st commit (vendor changes) are:

  1. It gives you the context and why this PR depends on Use i18n for clusterctl command descriptions and update dep #202.
  2. This PR itself is complete and can compile and run. This is important because in terms of dev workflow, I need to check this PR works.
  3. You can still review this PR easily. If you click on the commits tab, you will see 2 commits. The 2nd commit contains the actual changes. There are only 2 files and should be easy to review.

@wangzhen127
Copy link
Contributor Author

Since I split the commits in #202, I rebased this PR. Now there are 3 commits. You can see them in commits tab.

}

func init() {
validateClusterCmd.Flags().StringVarP(&vco.Name, "name", "n", "", "Cluster name")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please see jessica's comment here: #119 (comment)

Please leave all flags out of the skeleton. They can be filled in as code uses them. This ensures the the flags actually do something when they appear and also ensure they are defined in a way that works and is accurate to the behavior of the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. I just removed it. Will add them in follow-up PRs.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels May 26, 2018
@wangzhen127
Copy link
Contributor Author

Since we decided to drop internalization in #202 for now, I updated this PR to remove those changes. I also updated the PR description. PTAL

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 26, 2018
},
}

func RunValidateCluster() error {
Copy link
Contributor

Choose a reason for hiding this comment

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

There should be an associated _test.go file for this file. Please add a validate_cluster_test.go file, it can have a test that calls Run and verifies that errors.NotImplementedError is returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}

func init() {
validateCmd.AddCommand(validateClusterCmd)
Copy link
Contributor

Choose a reason for hiding this comment

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

To reduce confusion, we should be consistent with who is responsible for adding a sub-command. Since the validate command adds itself to the RootCmd on line 31, then it seems like we should remove line 30 and have the ValidateClusterCmd add itself to the ValidateCmd.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not very clear to me which style to follow. createCmd is added in root.go. deleteCmd is added in delete.go instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By the way, is there a repo wide style guideline?

Copy link
Contributor

Choose a reason for hiding this comment

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

As you pointed out there's inconsistency in the repo. We can fix that in a follow up PR. Let's follow the style laid out in the cobra examples [1] where a given command adds itself to its parent. So that means the create command should be added in create.go. And in this case, the validateClusterCommand would add itself to the validate command in validate_cluster.go.

[1] https://github.com/spf13/cobra

Copy link
Contributor

Choose a reason for hiding this comment

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

FYI opened up a standardization PR here: #228 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

@spew - thanks for standardizing
+1 for following the standardized pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@karan karan left a comment

Choose a reason for hiding this comment

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

lgtm (will leave the actual "/" approval up to the next reviewer)

var validateCmd = &cobra.Command{
Use: "validate",
Short: "Validate an API resource created by cluster API.",
Long: "Validate an API resource created by cluster API.",
Copy link
Contributor

Choose a reason for hiding this comment

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

This can use a little more details. Validate in what way?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would actually suggest more details on the validate cluster command instead of the validate command as I suspect validation will be cluster API resource-specific.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with Jessica.

And I think it is very early and there is no real implementation yet. I intend to update the help message as I add more stuff in follow-up PRs.

}

func init() {
validateCmd.AddCommand(validateClusterCmd)
Copy link
Contributor

Choose a reason for hiding this comment

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

@spew - thanks for standardizing
+1 for following the standardized pattern.

var validateCmd = &cobra.Command{
Use: "validate",
Short: "Validate an API resource created by cluster API.",
Long: "Validate an API resource created by cluster API.",
Copy link
Contributor

Choose a reason for hiding this comment

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

I would actually suggest more details on the validate cluster command instead of the validate command as I suspect validation will be cluster API resource-specific.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 29, 2018
@wangzhen127
Copy link
Contributor Author

Updated the PR with fixes. PTAL

@spew
Copy link
Contributor

spew commented May 29, 2018

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 29, 2018
@spew
Copy link
Contributor

spew commented May 29, 2018

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: spew, wangzhen127

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 approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 29, 2018
@wangzhen127
Copy link
Contributor Author

I just noticed that testify was not in vendor/ from the failed test. So I added it in Gopkg.toml and ran dep ensure. Currently I put them as separate commits for easier review. I will squash after someone take a look.

@spew
Copy link
Contributor

spew commented May 30, 2018

So to date we have been avoiding testify in this repository and have been relying on writing out if statements. The reasoning comes from the golang FAQ:

https://golang.org/doc/faq#testing_framework

A related point is that testing frameworks tend to develop into mini-languages 
of their own, with conditionals and controls and printing mechanisms, but Go 
already has all those capabilities; why recreate them? We'd rather write tests 
in Go; it's one fewer language to learn and the approach keeps the tests 
straightforward and easy to understand.

I think we need a decision on this and make it a repository mandate or not. Maybe we can conduct this discussion in Slack or have an issue vote.

@spew
Copy link
Contributor

spew commented May 30, 2018

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 30, 2018
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels May 30, 2018
@wangzhen127
Copy link
Contributor Author

OK. I updated the test to use if statement. PTAL

@spew
Copy link
Contributor

spew commented May 30, 2018

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 30, 2018
@k8s-ci-robot k8s-ci-robot merged commit f69bdf5 into kubernetes-sigs:master May 30, 2018
@wangzhen127 wangzhen127 deleted the add-validate branch May 31, 2018 17:57
jayunit100 pushed a commit to jayunit100/cluster-api that referenced this pull request Jan 31, 2020
fxierh pushed a commit to fxierh/cluster-api that referenced this pull request Sep 14, 2024
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. 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.

5 participants