-
Notifications
You must be signed in to change notification settings - Fork 494
CNTRLPLANE-3510: Enable additional golangci-lint linters #8567
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9a01d02
chore: enable additional golangci-lint linters
bryan-cox 92766c6
fix: resolve all errorlint violations across the codebase
bryan-cox 533e2c4
fix: suppress intentional nilerr violations with nolint directives
bryan-cox d22f557
fix: resolve all noctx violations across the codebase
bryan-cox 40830a2
fix: resolve all usestdlibvars violations across the codebase
bryan-cox a6e6d7c
fix: resolve all dupword violations across the codebase
bryan-cox 7d7f0b0
test: add unit tests for linter fix error paths
bryan-cox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package util | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| . "github.com/onsi/gomega" | ||
|
|
||
| "github.com/aws/aws-sdk-go-v2/config" | ||
|
|
||
| utilerrors "k8s.io/apimachinery/pkg/util/errors" | ||
| ) | ||
|
|
||
| func TestIsErrorRetryable(t *testing.T) { | ||
| t.Parallel() | ||
| tests := []struct { | ||
| name string | ||
| err error | ||
| expected bool | ||
| }{ | ||
| { | ||
| name: "When error is a generic error it should be retryable", | ||
| err: errors.New("some transient error"), | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "When error is a credential load error it should not be retryable", | ||
| err: config.SharedConfigLoadError{}, | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "When error is a wrapped credential load error it should not be retryable", | ||
| err: fmt.Errorf("loading config: %w", config.SharedConfigLoadError{}), | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "When aggregate has single generic error it should be retryable", | ||
| err: utilerrors.NewAggregate([]error{errors.New("transient")}), | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "When aggregate has single credential load error it should not be retryable", | ||
| err: utilerrors.NewAggregate([]error{config.SharedConfigLoadError{}}), | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "When aggregate has only credential load errors it should not be retryable", | ||
| err: utilerrors.NewAggregate([]error{ | ||
| config.SharedConfigLoadError{}, | ||
| config.SharedConfigLoadError{}, | ||
| }), | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "When aggregate has mixed errors it should be retryable", | ||
| err: utilerrors.NewAggregate([]error{ | ||
| config.SharedConfigLoadError{}, | ||
| errors.New("some other error"), | ||
| }), | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "When wrapped aggregate has single generic error it should be retryable", | ||
| err: fmt.Errorf("operation failed: %w", utilerrors.NewAggregate([]error{errors.New("transient")})), | ||
| expected: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| g := NewWithT(t) | ||
| g.Expect(IsErrorRetryable(tt.err)).To(Equal(tt.expected)) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Handle context cancellation to stop the probe loop.
Line 120 currently retries forever. Once
ctxis canceled,Do(req)will keep failing and this loop never exits.Suggested fix
for ; ; time.Sleep(sleepTime) { + select { + case <-ctx.Done(): + log.Info("probe canceled, exiting", "reason", ctx.Err()) + return + default: + } req, err := http.NewRequestWithContext(ctx, http.MethodGet, target.String(), nil) if err != nil { log.Error(err, "Failed to create request, retrying...") continue } response, err := client.Do(req) if err != nil { + if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { + log.Info("probe canceled, exiting", "reason", err) + return + } log.Error(err, "Request failed, retrying...") continue }As per coding guidelines "Do not leak goroutines — ensure they exit cleanly".
📝 Committable suggestion
🤖 Prompt for AI Agents