-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
upup/pkg/fi-fix staticcheck #8193
Conversation
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 Once the patch is verified, the new status will be reflected by the 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. |
/assign @chrisz100 |
/ok-to-test |
/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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
1a837c8
to
567dc77
Compare
/test pull-kops-verify-staticcheck |
@Aresforchina |
@tanjunchen yes,I will fix them,thanks! |
/test pull-kops-verify-staticcheck |
ce1a3ad
to
528f422
Compare
upup/pkg/fi/cloudup/apply_cluster.go
Outdated
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) |
There was a problem hiding this comment.
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:
fmt.Print(starline) | |
fmt.Printf("%s\n"), starline) |
There was a problem hiding this comment.
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.
4ffb3a7
to
6ef2e19
Compare
6ef2e19
to
e870727
Compare
There was a problem hiding this 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
@hakman you give me this version file that print style as |
upup/pkg/fi/cloudup/apply_cluster.go
Outdated
@@ -299,14 +299,14 @@ func (c *ApplyClusterCmd) Run() error { | |||
|
|||
if warn { | |||
fmt.Println("") | |||
fmt.Println(starline) | |||
fmt.Printf(("%s\n"), starline) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
@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. |
@hakman Thanks for your patience. I will fix it as soon as possible. |
e870727
to
87904db
Compare
87904db
to
f312f7c
Compare
/test pull-kops-e2e-kubernetes-aws |
/cc @rifelpet can you give me advice in this pr,please? |
/retest |
I think this looks good - thanks for sticking with it @Aresforchina /approve |
[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 |
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)