Add golangci-lint CI workflow and Makefile target - #1004
Conversation
Add a GitHub Actions workflow using golangci/golangci-lint-action@v9 to lint Go code on pushes and PRs to master. Add a `make lint` target for local use, and a minimal .golangci.yml config with vendor mode and the standard linter set. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: parametalol The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @parametalol. Thanks for your PR. I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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-sigs/prow repository. |
$ make lint
golangci-lint run ./...
bundle-hack/update_csv.go:37:17: Error return value of `enc.Close` is not checked (errcheck)
defer enc.Close()
^
cmd/manager/daemon.go:279:25: Error return value of `http.ListenAndServe` is not checked (errcheck)
go http.ListenAndServe(pprofAddr, mux)
^
cmd/manager/daemon_util.go:85:15: Error return value of `f.Close` is not checked (errcheck)
defer f.Close()
^
cmd/manager/logcollector_util.go:115:12: Error return value of `enc.Close` is not checked (errcheck)
enc.Close()
^
cmd/manager/logcollector_util.go:120:12: Error return value of `pw.Close` is not checked (errcheck)
pw.Close()
^
cmd/manager/operator.go:105:13: Error return value of `flags.Parse` is not checked (errcheck)
flags.Parse(args)
^
pkg/common/name.go:25:16: Error return value of `io.WriteString` is not checked (errcheck)
io.WriteString(hasher, friendlyName)
^
tests/e2e/helpers.go:2158:16: Error return value of `podLogs.Close` is not checked (errcheck)
podLogs.Close()
^
tests/e2e/helpers.go:2330:21: Error return value of `logFile.Close` is not checked (errcheck)
defer logFile.Close()
^
tests/e2e/helpers.go:2335:14: Error return value of `logFile.Sync` is not checked (errcheck)
logFile.Sync()
^
tests/framework/resource.go:120:56: inline: Call of context.TODO should be inlined (govet)
_, err := ctx.kubeclient.CoreV1().Namespaces().Create(context.TODO(), namespaceObj, metav1.CreateOptions{})
^
tests/framework/resource.go:129:54: inline: Call of context.TODO should be inlined (govet)
return ctx.kubeclient.CoreV1().Namespaces().Delete(context.TODO(), ns, opts)
^
bundle-hack/update_csv.go:89:8: ineffectual assignment to ok (ineffassign)
spec, ok := csv["spec"].(map[string]interface{})
^
bundle-hack/update_csv.go:16:3: S1038: should use log.Fatalf(...) instead of log.Fatal(fmt.Sprintf(...)) (staticcheck)
log.Fatal(fmt.Sprintf("Error: Failed to read file '%s'", csvFilename))
^
bundle-hack/update_csv.go:21:3: S1038: should use log.Fatalf(...) instead of log.Fatal(fmt.Sprintf(...)) (staticcheck)
log.Fatal(fmt.Sprintf("Error: Failed to unmarshal yaml file '%s'", csvFilename))
^
bundle-hack/update_csv.go:28:3: S1038: should use log.Fatalf(...) instead of log.Fatal(fmt.Sprintf(...)) (staticcheck)
log.Fatal(fmt.Sprintf("Error: Failed to remofe file '%s'", csvFilename))
^
bundle-hack/update_csv.go:95:2: S1038: should use fmt.Printf instead of fmt.Println(fmt.Sprintf(...)) (but don't forget the newline) (staticcheck)
fmt.Println(fmt.Sprintf("Updating version references from %s to %s", oldVersion, newVersion))
^
bundle-hack/update_csv.go:105:2: S1038: should use fmt.Printf instead of fmt.Println(fmt.Sprintf(...)) (but don't forget the newline) (staticcheck)
fmt.Println(fmt.Sprintf("Updated version references from %s to %s", oldVersion, newVersion))
^
bundle-hack/update_csv.go:130:2: S1038: should use fmt.Printf instead of fmt.Println(fmt.Sprintf(...)) (but don't forget the newline) (staticcheck)
fmt.Println(fmt.Sprintf("Updated the operator image to use icon in %s", iconPath))
^
cmd/manager/daemon.go:303:46: SA1016: syscall.SIGKILL cannot be trapped (did you mean syscall.SIGTERM?) (staticcheck)
signal.Notify(sigTermChan, syscall.SIGTERM, syscall.SIGKILL)
^
cmd/manager/daemon_util.go:37:2: ST1019: package "k8s.io/apimachinery/pkg/apis/meta/v1" is being imported more than once (staticcheck)
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
^
cmd/manager/daemon_util.go:38:2: ST1019(related information): other import of "k8s.io/apimachinery/pkg/apis/meta/v1" (staticcheck)
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
^
cmd/manager/logcollector.go:43:4: QF1003: could use tagged switch on lastResult (staticcheck)
if lastResult == -1 || lastResult == 18 {
^
cmd/manager/loops.go:27:2: ST1019: package "k8s.io/apimachinery/pkg/apis/meta/v1" is being imported more than once (staticcheck)
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
^
cmd/manager/loops.go:28:2: ST1019(related information): other import of "k8s.io/apimachinery/pkg/apis/meta/v1" (staticcheck)
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
^
cmd/manager/loops.go:270:18: SA1019: watch2.NewRetryWatcher is deprecated: use NewRetryWatcherWithContext instead. (staticcheck)
watcher, err := watch2.NewRetryWatcher(initialVersion, listWatcher)
^
cmd/manager/loops.go:291:2: S1023: redundant return statement (staticcheck)
return
^
pkg/common/name.go:29:14: ST1005: error strings should not be capitalized (staticcheck)
return "", fmt.Errorf("Cannot shorten '%s' with prefix %s", friendlyName, hashPrefix)
^
pkg/common/util.go:535:22: QF1008: could remove embedded field "ObjectMeta" from selector (staticcheck)
for k, v := range s.ObjectMeta.Labels {
^
pkg/common/util.go:543:17: QF1008: could remove embedded field "ObjectMeta" from selector (staticcheck)
Name: s.ObjectMeta.Name,
^
pkg/common/util.go:544:17: QF1008: could remove embedded field "ObjectMeta" from selector (staticcheck)
Namespace: s.ObjectMeta.Namespace,
^
pkg/controller/fileintegrity/fileintegrity_controller.go:74:14: QF1008: could remove embedded field "Client" from selector (staticcheck)
if err := r.Client.Get(context.TODO(), types.NamespacedName{
^
pkg/controller/fileintegrity/fileintegrity_controller.go:82:15: QF1008: could remove embedded field "Client" from selector (staticcheck)
if err := r.Client.Create(context.TODO(), aideReinitScript()); err != nil {
^
pkg/controller/fileintegrity/fileintegrity_controller.go:88:15: QF1008: could remove embedded field "Client" from selector (staticcheck)
if err := r.Client.Update(context.TODO(), aideReinitScript()); err != nil {
^
pkg/controller/fileintegrity/fileintegrity_controller.go:233:4: QF1008: could remove embedded field "Metrics" from selector (staticcheck)
r.Metrics.IncFileIntegrityReinitDaemonsetUpdate()
^
pkg/controller/fileintegrity/fileintegrity_controller.go:523:7: QF1008: could remove embedded field "Metrics" from selector (staticcheck)
r.Metrics.IncFileIntegrityReinitByDemand()
^
pkg/controller/fileintegrity/fileintegrity_controller.go:526:7: QF1008: could remove embedded field "Metrics" from selector (staticcheck)
r.Metrics.IncFileIntegrityReinitByConfig()
^
pkg/controller/fileintegrity/fileintegrity_controller.go:562:50: QF1008: could remove embedded field "Time" from selector (staticcheck)
shouldScheduleAt := instance.CreationTimestamp.Time.Add(delayTime)
^
pkg/controller/fileintegrity/fileintegrity_controller.go:624:9: S1005: unnecessary assignment to the blank identifier (staticcheck)
for i, _ := range daemonSetList.Items {
^
tests/e2e/helpers.go:6:2: ST1019: package "context" is being imported more than once (staticcheck)
"context"
^
tests/e2e/helpers.go:7:2: ST1019(related information): other import of "context" (staticcheck)
goctx "context"
^
tests/e2e/helpers.go:310:8: SA1019: wait.Poll is deprecated: This method does not return errors from context, use PollUntilContextTimeout. Note that the new method will no longer return ErrWaitTimeout and instead return errors defined by the context package. Will be removed in a future release. (staticcheck)
err = wait.Poll(pollInterval, pollTimeout, func() (bool, error) {
^
tests/e2e/helpers.go:457:17: QF1004: could use strings.ReplaceAll instead (staticcheck)
newContents := strings.Replace(string(read), nsFrom, nsTo, -1)
^
tests/e2e/helpers.go:621:13: SA1019: wait.PollImmediate is deprecated: This method does not return errors from context, use PollUntilContextTimeout. Note that the new method will no longer return ErrWaitTimeout and instead return errors defined by the context package. Will be removed in a future release. (staticcheck)
pollErr := wait.PollImmediate(time.Second, 5*time.Minute, func() (bool, error) {
^
tests/e2e/helpers.go:734:9: SA1019: wait.PollImmediate is deprecated: This method does not return errors from context, use PollUntilContextTimeout. Note that the new method will no longer return ErrWaitTimeout and instead return errors defined by the context package. Will be removed in a future release. (staticcheck)
return wait.PollImmediate(pollInterval, timeout, daemonSetCallback)
^
tests/e2e/helpers.go:738:9: SA1019: wait.PollImmediate is deprecated: This method does not return errors from context, use PollUntilContextTimeout. Note that the new method will no longer return ErrWaitTimeout and instead return errors defined by the context package. Will be removed in a future release. (staticcheck)
return wait.PollImmediate(pollInterval, timeoutVal, daemonSetCallback)
^
tests/e2e/helpers.go:1261:9: SA1019: wait.Poll is deprecated: This method does not return errors from context, use PollUntilContextTimeout. Note that the new method will no longer return ErrWaitTimeout and instead return errors defined by the context package. Will be removed in a future release. (staticcheck)
err := wait.Poll(interval, timeout, func() (bool, error) {
^
tests/e2e/helpers.go:1289:9: SA1019: wait.Poll is deprecated: This method does not return errors from context, use PollUntilContextTimeout. Note that the new method will no longer return ErrWaitTimeout and instead return errors defined by the context package. Will be removed in a future release. (staticcheck)
err := wait.Poll(interval, timeout, func() (bool, error) {
^
tests/e2e/helpers.go:2057:12: ST1005: error strings should not be capitalized (staticcheck)
return fmt.Errorf("The node '%s' is not ready yet", node.Name)
^
tests/e2e/helpers.go:2066:10: ST1005: error strings should not be capitalized (staticcheck)
return fmt.Errorf("The nodes were never ready: %s", err)
^
tests/framework/resource.go:12:2: SA1019: "golang.org/x/net/context" is deprecated: Use the standard library context package instead. (staticcheck)
"golang.org/x/net/context"
^
tests/e2e/helpers.go:1493:6: func assertNodesUpdatingStarted is unused (unused)
func assertNodesUpdatingStarted(t *testing.T, f *framework.Framework, interval, timeout time.Duration) {
^
52 issues:
* errcheck: 10
* govet: 2
* ineffassign: 1
* staticcheck: 38
* unused: 1
make: *** [Makefile:239: lint] Error 1 |
|
/ok-to-test |
|
/retest |
|
@parametalol: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions 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-sigs/prow repository. I understand the commands that are listed here. |
Summary
golangci-lint.yaml) that runs golangci-lint on pushes and PRs to master, usinggolangci/golangci-lint-action@v9with golangci-lint v2.12make linttarget for running golangci-lint locally.golangci.ymlconfig with vendor mode and the standard linter set (errcheck, govet, staticcheck, unused, ineffassign, gosimple)Test plan
make lintlocally and confirm it invokes golangci-lint correctly