-
Notifications
You must be signed in to change notification settings - Fork 348
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
Integrating golangci-lint #1179
Conversation
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 a great first start. Let's discuss further.
cmd/sonobuoy/app/gen.go
Outdated
@@ -279,7 +278,7 @@ func (g *genFlags) resolveConfig() *config.Config { | |||
// Set these values as if the user had requested the defaults. | |||
if g.genflags != nil { | |||
for _, v := range conf.PluginSelections { | |||
g.genflags.Lookup("plugin").Value.Set(v.Name) | |||
g.genflags.Lookup("plugin").Value.Set(v.Name) //nolint:errcheck |
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.
Is //nolint:errcheck
skipping this as an error check ? I see several of these. It may be worth it to actually fix these in another pass instead of having that comment all over the place.
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.
//nolint:errcheck
will tell golangci-lint
to not mark this as errcheck
lint failure. the only resolutions I can think of are:
// practically silencing error
_ = g.genflags.Lookup("plugin").Value.Set(v.Name)
or
// potentially changing behavior, because previously we ignored this error if they exist
err := g.genflags.Lookup("plugin").Value.Set(v.Name)
if err != nil {
...
}
is there other alternatives?
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 may be one more option. Looking at the doc for errcheck
linter, it supports an external file where you can put package, functions, methods to skip.
Take a look here https://github.com/kisielk/errcheck#excluding-functions
fmt.Println(fmt.Sprintf("MinimumKubeVersion: %s", buildinfo.MinimumKubeVersion)) | ||
fmt.Println(fmt.Sprintf("MaximumKubeVersion: %s", buildinfo.MaximumKubeVersion)) | ||
fmt.Println(fmt.Sprintf("GitSHA: %s", buildinfo.GitSHA)) | ||
fmt.Printf("Sonobuoy Version: %s\n", buildinfo.Version) |
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.
Good catch here.
@@ -121,6 +121,12 @@ func (c *SonobuoyClient) RunManifest(cfg *RunConfig, manifest []byte) error { | |||
seenStatus = true | |||
} | |||
|
|||
// if nil below was added for coverage on staticcheck | |||
// TODO: ensure this is the desired behavior | |||
if status == nil { |
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.
Let's discuss this further. Agreed we need to understand this is not adding new side effects.
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.
so after taking another look, it seems that in scenario where status
is nil
, previous behavior would have runtime de-referencing error on switch{}
. so prooooobably ok to have a more channeled error delivery?
pkg/config/loader.go
Outdated
@@ -55,7 +55,7 @@ func LoadConfig() (*Config, error) { | |||
} | |||
defer jsonFile.Close() | |||
|
|||
b, err := ioutil.ReadAll(jsonFile) | |||
b, _ := ioutil.ReadAll(jsonFile) |
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.
Error handling: the error should not be silenced 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.
Same thing here, let's add the error handling logic needed. Probably should add something like this
b, err := ioutil.ReadAll(jsonFile)
if err != nil {
return nil, errors.Wrap(err, "read config")
}
// Only set values if they have values greater than 0 (as in they user specified). | ||
limitBytes := podLogLimits.SizeLimitBytes(0) | ||
sinceSeconds := int64(podLogLimits.TimeLimitDuration(0) / time.Second) | ||
limitBytes := podLogLimits.SizeLimitBytes(0) //nolint:staticcheck |
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 good for now. Lets investigate what would satisfy this check and if it requires package upgrade then we can handle that in a different PR.
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.
some clarifications on changes and responses. I've been defaulting to silencing previously unhandled errors to preserve behavior, but I agree with the general sentiment that we should ensure they are handled appropriately -- whether to ignore (mark as insignificant) or surface it to user.
cmd/sonobuoy/app/gen.go
Outdated
@@ -279,7 +278,7 @@ func (g *genFlags) resolveConfig() *config.Config { | |||
// Set these values as if the user had requested the defaults. | |||
if g.genflags != nil { | |||
for _, v := range conf.PluginSelections { | |||
g.genflags.Lookup("plugin").Value.Set(v.Name) | |||
g.genflags.Lookup("plugin").Value.Set(v.Name) //nolint:errcheck |
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.
//nolint:errcheck
will tell golangci-lint
to not mark this as errcheck
lint failure. the only resolutions I can think of are:
// practically silencing error
_ = g.genflags.Lookup("plugin").Value.Set(v.Name)
or
// potentially changing behavior, because previously we ignored this error if they exist
err := g.genflags.Lookup("plugin").Value.Set(v.Name)
if err != nil {
...
}
is there other alternatives?
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.
Looks good. Left a link for you to check out for the errcheck
linter
cmd/sonobuoy/app/gen.go
Outdated
@@ -279,7 +278,7 @@ func (g *genFlags) resolveConfig() *config.Config { | |||
// Set these values as if the user had requested the defaults. | |||
if g.genflags != nil { | |||
for _, v := range conf.PluginSelections { | |||
g.genflags.Lookup("plugin").Value.Set(v.Name) | |||
g.genflags.Lookup("plugin").Value.Set(v.Name) //nolint:errcheck |
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 may be one more option. Looking at the doc for errcheck
linter, it supports an external file where you can put package, functions, methods to skip.
Take a look here https://github.com/kisielk/errcheck#excluding-functions
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.
Ok, added some comments about error handling in several places.
cmd/sonobuoy/app/worker.go
Outdated
err := runGather(false) | ||
// staticcheck somehow flags err as unused when it's actually returned | ||
// at the end of this function | ||
err := runGather(false) //nolint:staticcheck |
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.
For this one, the static analysis is correct, one of the switch case sleeps forever. So, add a err handling block right after the rungGather call
if err := runGather(flase); err != nil {
return err
}
...
// return nil at the end of func
return nil
pkg/client/interfaces.go
Outdated
@@ -30,6 +30,8 @@ import ( | |||
) | |||
|
|||
// ConfigValidator allows the command configurations to be validated. | |||
// TODO: investigate for removal, currently only used in interfaces_test.go |
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.
If this is only used in a test, I would move this in the test file where it is used.
pkg/config/loader.go
Outdated
@@ -55,7 +55,7 @@ func LoadConfig() (*Config, error) { | |||
} | |||
defer jsonFile.Close() | |||
|
|||
b, err := ioutil.ReadAll(jsonFile) | |||
b, _ := ioutil.ReadAll(jsonFile) |
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.
Same thing here, let's add the error handling logic needed. Probably should add something like this
b, err := ioutil.ReadAll(jsonFile)
if err != nil {
return nil, errors.Wrap(err, "read config")
}
pkg/discovery/discovery.go
Outdated
@@ -152,7 +152,7 @@ func Run(restConf *rest.Config, cfg *config.Config) (errCount int) { | |||
|
|||
// 5. Run the queries | |||
recorder := NewQueryRecorder() | |||
clusterResources, nsResources, err := getAllFilteredResources(apiHelper, cfg.Resources) | |||
clusterResources, nsResources, _ := getAllFilteredResources(apiHelper, cfg.Resources) // TODO: handle error checking |
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.
Same deal here, let's add an error handler
clusterResources, nsResources, err := getAllFilteredResources(apiHelper, cfg.Resources)
if err != nil {
errlog.LogError(errors.Wrap(err, "getting all filtered resources"))
return errCount + 1
}
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.
LGTM
@wilsonehusin Please squash commits and include signoff |
- source code lint with golangci-lint - ignore low-priority errchecks (for now) - add GitHub actions for linting CI Signed-off-by: Wilson E. Husin <[email protected]>
What this PR does / why we need it:
Repository housecleaning.
Which issue(s) this PR fixes
Partially addresses #1176, baby steps towards #1178
Special notes for your reviewer:
Seems like GitHub is not running the actions on this PR as
vmware-tanzu
, but it's available on my forkRelease note: