-
Notifications
You must be signed in to change notification settings - Fork 983
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
Changes from 9 commits
2bdc93f
3a4673d
bcbc8ad
64be346
74d92ed
95e02b0
d10007a
e37185d
ae08a39
7e0a67a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# See https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml | ||
run: | ||
tests: false | ||
|
||
timeout: 5m | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do! |
||
|
||
build-tags: | ||
- aws | ||
|
||
skip-dirs: | ||
- tools | ||
- website | ||
- hack | ||
- charts | ||
- designs | ||
|
||
linters: | ||
enable: | ||
- asciicheck | ||
- errorlint | ||
- gosec | ||
- revive | ||
- stylecheck | ||
- tparallel | ||
- unconvert | ||
- unparam | ||
disable: | ||
- errcheck | ||
- prealloc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only field that diverges from kn IIUC There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my other comment about why |
||
|
||
linters-settings: | ||
gci: | ||
local-prefixes: github.com/awslabs/karpenter |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package aws | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/aws/aws-sdk-go/aws/awserr" | ||
"github.com/awslabs/karpenter/pkg/utils/functional" | ||
) | ||
|
||
var ( | ||
// This is not an exhaustive list, add to it as needed | ||
notFoundErrorCodes = []string{ | ||
"InvalidInstanceID.NotFound", | ||
"InvalidLaunchTemplateName.NotFoundException", | ||
} | ||
) | ||
|
||
// 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 { | ||
JacobGabrielson marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider making this public There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
var awsError awserr.Error | ||
if errors.As(err, &awsError) { | ||
return functional.ContainsString(notFoundErrorCodes, awsError.Code()) | ||
} | ||
return false | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curious why we'd switch to using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably to avoid variations of https://dev.to/kkentzo/the-golang-for-loop-gotcha-1n35 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. However, I totally agree, and don't like this indexing style. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
p := pods.Items[i] | ||
if err := f.isProvisionable(&p, provisioner); err != nil { | ||
logging.FromContext(ctx).Debugf("Ignored pod %s/%s when allocating for provisioner %s, %s", | ||
p.Name, p.Namespace, provisioner.Name, err.Error(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only when it's closed over or its address is taken. |
||
p := pods.Items[i] | ||
if pod.HasFailed(&p) { | ||
continue | ||
} | ||
|
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'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?
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 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.