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

golangci added to verify target, fixes #746

Merged
merged 10 commits into from
Oct 15, 2021
Merged

Conversation

JacobGabrielson
Copy link
Contributor

1. Issue, if available:

N/A

2. Description of changes:

Per @ellistarn add golangci config; fix errors found by same

3. Does this change impact docs?

  • Yes, PR includes docs updates
  • Yes, issue opened: link to issue
  • No

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@netlify
Copy link

netlify bot commented Oct 15, 2021

✔️ Deploy Preview for karpenter-docs-prod canceled.

🔨 Explore the source changes: 7e0a67a

🔍 Inspect the deploy log: https://app.netlify.com/sites/karpenter-docs-prod/deploys/6169af90d15e2e0007f9e355

@JacobGabrielson JacobGabrielson changed the title [WIP] golangci added to verify target, fixes golangci added to verify target, fixes Oct 15, 2021
@JacobGabrielson JacobGabrielson marked this pull request as ready for review October 15, 2021 04:57
run:
tests: false

timeout: 5m
Copy link
Contributor

Choose a reason for hiding this comment

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

you can remove the --timeout 5m arg in the Makefile now since we have this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do!

pkg/cloudprovider/aws/errors.go Show resolved Hide resolved
@@ -39,7 +39,8 @@ func (f *Filter) GetProvisionablePods(ctx context.Context, provisioner *v1alpha4
}
// 2. Filter pods that aren't provisionable
provisionable := []*v1.Pod{}
for _, p := range pods.Items {
for i := range pods.Items {
Copy link
Contributor

Choose a reason for hiding this comment

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

curious why we'd switch to using i here rather than just ranging over the actual pod? We do the range over the object ignoring the index in other loops.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

However, I totally agree, and don't like this indexing style.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ellistarn that's right about the for loop gotcha - is there a different style you'd prefer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bwagner5 the difference is that in other loops, the address of the range object isn't being taken (and there's no closure going on either), so the linter isn't warning about those.

@@ -86,7 +86,8 @@ func (r *Emptiness) isEmpty(ctx context.Context, n *v1.Node) (bool, error) {
if err := r.kubeClient.List(ctx, pods, client.MatchingFields{"spec.nodeName": n.Name}); err != nil {
return false, fmt.Errorf("listing pods for node %s, %w", n.Name, err)
}
for _, p := range pods.Items {
for i := range pods.Items {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm seeing this pattern in a lot of places now. Is this a lint recommendation? I'm not sure I agree that this is better. Is this supposed to protect against the pointer location changing out from under the local loop var?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only when it's closed over or its address is taken.

// isNotFound returns true if the err is an AWS error (even if it's
// wrapped) and is a known to mean "not found" (as opposed to a more
// serious or unexpected error)
func isNotFound(err error) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

consider making this public

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just curious why? I kinda got the impression public-ness was a signal that the function would be used outside of the aws package?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd agree on keeping this private. Limits the IDE-oopsy of importing this into another pkg that's not in aws cloud provider

@@ -0,0 +1,33 @@
# See https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd trust the knative folks to have landed on a set of sensible defaults: https://github.com/knative-sandbox/sample-controller/blob/main/.golangci.yaml. WDTY?

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 started with those, but they had chosen a few that weren't a good idea. For example, one of them exhorted one to use make to pre-allocate slices. Which, while sometimes a good idea, can be a pretty dangerous change to make without a lot of testing as the semantics do change subtly.

- unparam
disable:
- errcheck
- prealloc
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the only field that diverges from kn IIUC

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See my other comment about why prealloc isn't a good idea.

Copy link
Contributor

@bwagner5 bwagner5 left a comment

Choose a reason for hiding this comment

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

/lgtm

@JacobGabrielson JacobGabrielson merged commit 58875ec into aws:main Oct 15, 2021
@JacobGabrielson JacobGabrielson deleted the glci branch October 15, 2021 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants