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

upup/pkg/fi-fix staticcheck #8193

Merged

Conversation

Aresforchina
Copy link
Contributor

ref:#7800
special notes:
upup/pkg/fi/cloudup/apply_cluster.go:300:15: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006)
upup/pkg/fi/cloudup/apply_cluster.go:307:15: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006)
upup/pkg/fi/cloudup/apply_cluster.go:1003:14: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006)
upup/pkg/fi/cloudup/apply_cluster.go:1010:14: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006)
upup/pkg/fi/cloudup/apply_cluster.go:1014:14: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006)
upup/pkg/fi/cloudup/apply_cluster.go:1025:14: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006)
upup/pkg/fi/cloudup/apply_cluster.go:1069:14: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006)
upup/pkg/fi/cloudup/apply_cluster.go:1076:14: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006)
upup/pkg/fi/cloudup/apply_cluster.go:1080:14: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006)
upup/pkg/fi/cloudup/apply_cluster.go:1091:14: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006)
upup/pkg/fi/cloudup/awstasks/sshkey.go:206:79: argument a is overwritten before first use (SA4009)
upup/pkg/fi/cloudup/loader.go:58:2: field templates is unused (U1000)
upup/pkg/fi/executor.go:162:6: type runnable is unused (U1000)

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Dec 24, 2019
@k8s-ci-robot
Copy link
Contributor

Hi @Aresforchina. Thanks for your PR.

I'm waiting for a kubernetes 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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Dec 24, 2019
@Aresforchina
Copy link
Contributor Author

/assign @chrisz100

@tanjunchen
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 Dec 24, 2019
@Aresforchina
Copy link
Contributor Author

/test pull-kops-e2e-kubernetes-aws

@@ -208,7 +208,7 @@ func (_ *SSHKey) RenderCloudformation(t *cloudformation.CloudformationTarget, a,

klog.Warningf("Cloudformation does not manage SSH keys; pre-creating SSH key")

a, err := e.find(cloud)
_, err := e.find(cloud)
Copy link
Member

Choose a reason for hiding this comment

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

this a variable is used by line 216, correct? I don't think replacing it with _ is the correct fix here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this instance shouldn't get flagged – because it is only being set conditionally, in one branch.or can you give me some advice,please?

Copy link
Member

Choose a reason for hiding this comment

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

The mechanical fix would be to change the parameter a to _. But then, why is there a parameter? Is the e.find(cloud) call needed?

Copy link
Member

@rifelpet rifelpet Dec 25, 2019

Choose a reason for hiding this comment

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

This function is called using reflection, so changing its signature may not be feasible:

kops/upup/pkg/fi/context.go

Lines 218 to 223 in 5cb2d36

rendererArgs = append(rendererArgs, reflect.ValueOf(a))
rendererArgs = append(rendererArgs, reflect.ValueOf(e))
rendererArgs = append(rendererArgs, reflect.ValueOf(changes))
klog.V(11).Infof("Calling method %s on %T", renderer.Name, e)
m := v.MethodByName(renderer.Name)
rv := m.Call(rendererArgs)

Renaming the parameter to _ might be the best approach. I'm sure there are other tasks that have unused a parameters in some of their Render functions, perhaps we look at how it is handled elsewhere?

Copy link
Member

Choose a reason for hiding this comment

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

My question was more along the lines of "Is the value of the a parameter semantically different than the a obtained from e.find(cloud)? If not, the call wouldn't be needed.

Copy link
Member

@rifelpet rifelpet Dec 26, 2019

Choose a reason for hiding this comment

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

After reviewing the commit that added these lines, I understand the context a bit more. For reference, a is the "actual" state of the task, e is the "expected" state of the task.

For CloudFormation (and Terraform) targets we dont care about the actual state of the resource in AWS, we're generating the same cloudformation/terraform output regardless. Therefor most tasks' RenderTerraform functions don't use their a parameters. SSHKey is an exception because CloudFormation doesnt support creating them, so Kops needs to create the key AWS directly, which requires knowing the actual state of the ssh key. Now the question becomes "does the a parameter get populated with the true actual state of the resource even for cloudformation targets?" and based on some testing I believe the answer is yes. Therefor I think we can get rid of this line and the error checking directly below it.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry I misspoke, a does not get populated with cloudformation target, therefor the best fix would be to do what other tasks do and use a different variable name, perhaps keypair.

@Aresforchina Aresforchina force-pushed the fix-staticheckout-pkg-resource02 branch from 1a837c8 to 567dc77 Compare December 30, 2019 08:31
@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. 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. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Dec 30, 2019
@Aresforchina
Copy link
Contributor Author

/test pull-kops-verify-staticcheck

@tanjunchen
Copy link
Member

@Aresforchina
can you fix the conflicts , thanks

@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Dec 31, 2019
@Aresforchina
Copy link
Contributor Author

@tanjunchen yes,I will fix them,thanks!

@tanjunchen
Copy link
Member

/test pull-kops-verify-staticcheck

@Aresforchina Aresforchina force-pushed the fix-staticheckout-pkg-resource02 branch 2 times, most recently from ce1a3ad to 528f422 Compare January 2, 2020 06:47
@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 Jan 2, 2020
fmt.Printf("\n")
fmt.Printf("A new kubernetes version is available: %s\n", recommended)
fmt.Printf("Upgrading is recommended (try kops upgrade cluster)\n")
fmt.Printf("\n")
fmt.Printf("More information: %s\n", buildPermalink("upgrade_k8s", recommended.String()))
fmt.Printf("\n")
fmt.Printf(starline)
fmt.Print(starline)
Copy link
Member

Choose a reason for hiding this comment

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

To keep the same style, same in a few other places:

Suggested change
fmt.Print(starline)
fmt.Printf("%s\n"), starline)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes,sir.I have fixed them together.

@Aresforchina Aresforchina force-pushed the fix-staticheckout-pkg-resource02 branch 2 times, most recently from 4ffb3a7 to 6ef2e19 Compare January 6, 2020 04:34
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 6, 2020
@Aresforchina Aresforchina force-pushed the fix-staticheckout-pkg-resource02 branch from 6ef2e19 to e870727 Compare January 6, 2020 05:58
Copy link
Member

@hakman hakman left a comment

Choose a reason for hiding this comment

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

I think there are a bit too many changes in apply_cluster.go now. I suggest to check this version.
https://gist.githubusercontent.com/hakman/b980c8140305393e475c96952fca6d7e/raw/1fe983c96b6750f2091ef8d06974cf512830bd91/apply_cluster.go

@Aresforchina
Copy link
Contributor Author

Aresforchina commented Jan 7, 2020

@hakman you give me this version file that print style as println() ,but last time suggest me update it into fmt.Printf("%s\n"), starline). so could I entirely change print style into println() in apply_cluster.go now?

@@ -299,14 +299,14 @@ func (c *ApplyClusterCmd) Run() error {

if warn {
fmt.Println("")
fmt.Println(starline)
fmt.Printf(("%s\n"), starline)
Copy link
Member

Choose a reason for hiding this comment

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

Why all the extra parentheses?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is my syntax fault .Thank you for pointing it out.

@hakman
Copy link
Member

hakman commented Jan 7, 2020

@Aresforchina sorry for the confusion. I wanted to suggest to change that in areas where there was mostly printf.

As @johngmyers pointed out, there were also some extra parenthesis and new lines in the current version. Seemed easier to just provide a full file as suggestion.

@Aresforchina
Copy link
Contributor Author

@hakman Thanks for your patience. I will fix it as soon as possible.

@Aresforchina Aresforchina force-pushed the fix-staticheckout-pkg-resource02 branch from e870727 to 87904db Compare January 7, 2020 06:57
@Aresforchina Aresforchina force-pushed the fix-staticheckout-pkg-resource02 branch from 87904db to f312f7c Compare January 7, 2020 07:51
@Aresforchina
Copy link
Contributor Author

/test pull-kops-e2e-kubernetes-aws

@Aresforchina
Copy link
Contributor Author

/cc @rifelpet can you give me advice in this pr,please?

@johngmyers
Copy link
Member

/retest

@justinsb
Copy link
Member

I think this looks good - thanks for sticking with it @Aresforchina

/approve
/lgtm

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Aresforchina, justinsb

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 Jan 11, 2020
@k8s-ci-robot k8s-ci-robot merged commit 5561759 into kubernetes:master Jan 11, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.18 milestone Jan 11, 2020
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.

None yet

8 participants