Skip to content

build: replace go vet with golangci-lint#53

Merged
diranged merged 4 commits intodiranged:mainfrom
stlava:linter
Dec 5, 2022
Merged

build: replace go vet with golangci-lint#53
diranged merged 4 commits intodiranged:mainfrom
stlava:linter

Conversation

@stlava
Copy link
Copy Markdown
Collaborator

@stlava stlava commented Dec 4, 2022

This PR replaces go vet in favor of golangci-lint which includes vet as well as a host of other lint checks. I've also removed fmt and vet as a required make targets for the build, test, and run targets as code formatting is orthogonal to building the binary.

I've left a few TODOs to handle err responses for areas I wasn't sure about the desired functionality.

@github-actions github-actions bot added build github_actions Pull requests that update GitHub Actions code repo labels Dec 4, 2022
@diranged
Copy link
Copy Markdown
Owner

diranged commented Dec 4, 2022

@stlava thanks for the PR! The failure in the unit test has been opened as a bug (#54) and obviously needs to be fixed... I must have been in a hurry when i merged that PR. I'll get a fix up this afternoon for it.

Comment thread webhook/contextual_defaulter.go Outdated
//
// orig: https://github.com/kubernetes-sigs/controller-runtime/blob/v0.13.1/pkg/webhook/admission/defaulter.go#L78-L83
obj.Default(req)
if err := obj.Default(req); err != nil {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I'm curious - is it common in Go to test the "if err ..." code paths?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It depends on if you care about the result or not. Typically any handled errors should be tested since it introduces a new branch.

@coveralls
Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 3616861999

  • 12 of 19 (63.16%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.03%) to 44.775%

Changes Missing Coverage Covered Lines Changed/Added Lines %
controllers/builders/exec_access_builder.go 0 2 0.0%
controllers/builders/pod_access_builder.go 0 2 0.0%
controllers/base_controller.go 1 4 25.0%
Totals Coverage Status
Change from base Build 3616835478: 0.03%
Covered Lines: 857
Relevant Lines: 1914

💛 - Coveralls

@diranged diranged merged commit 227eb29 into diranged:main Dec 5, 2022
diranged added a commit that referenced this pull request Dec 5, 2022
The latest release attempt
(https://github.com/diranged/oz/actions/runs/3621310569/jobs/6105202279)
failed. In digging in, it looks like in
#53 we made a change to the
auto-generated file that was likely done via a IDE or auto-linter.. but
that causes the `make build` to mutate the files before the final
release, which causes `make release` to fail.

```
diranged@Matts-Air-UW oz % make build
Custom.mk:38: warning: overriding commands for target `lint'
Makefile:104: warning: ignoring old commands for target `lint'
Custom.mk:65: warning: overriding commands for target `fmt'
Makefile:100: warning: ignoring old commands for target `fmt'
Custom.mk:79: warning: overriding commands for target `build'
Makefile:114: warning: ignoring old commands for target `build'
test -s /Users/diranged/go/src/github.com/diranged/oz/bin/controller-gen || GOBIN=/Users/diranged/go/src/github.com/diranged/oz/bin go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.10.0
/Users/diranged/go/src/github.com/diranged/oz/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
PUBLISH=false /Library/Developer/CommandLineTools/usr/bin/make release
Custom.mk:38: warning: overriding commands for target `lint'
Makefile:104: warning: ignoring old commands for target `lint'
Custom.mk:65: warning: overriding commands for target `fmt'
Makefile:100: warning: ignoring old commands for target `fmt'
Custom.mk:79: warning: overriding commands for target `build'
Makefile:114: warning: ignoring old commands for target `build'
IMG=ghcr.io/diranged/oz:0.0.1 /Users/diranged/go/src/github.com/diranged/oz/bin/goreleaser release --skip-publish --snapshot --rm-dist
  • starting release...
  • loading config file                              file=.goreleaser.yml
  • loading environment variables
  • getting and validating git state
    • building...                                    commit=227eb29e4c6b40278a6eea5fdb86b4287fb8af98 latest tag=0.0.0-rc9
    • pipe skipped                                   reason=disabled during snapshot mode
  • parsing tag
  • setting defaults
  • running before hooks
    • running                                        hook=go mod tidy
  • snapshotting
    • building snapshot...                           version=0.0.0-rc9-SNAPSHOT-227eb29
  • checking distribution directory
    • --rm-dist is set, cleaning it up
  • loading go mod information
  • build prerequisites
  • writing effective config file
    • writing                                        config=dist/config.yaml
  • building binaries
    • building                                       binary=dist/cli_darwin_amd64_v1/ozctl
    • building                                       binary=dist/manager_linux_arm64/manager
    • building                                       binary=dist/cli_darwin_arm64/ozctl
    • building                                       binary=dist/manager_linux_amd64_v1/manager
    • took: 3s
  • universal binaries
    • creating from 2 binaries                       binary=dist/cli_darwin_all/ozctl id=cli
  • archives
    • creating                                       archive=dist/oz_0.0.0-rc9-SNAPSHOT-227eb29_darwin_all.tar.gz
    • creating                                       archive=dist/oz_0.0.0-rc9-SNAPSHOT-227eb29_linux_amd64.tar.gz
    • creating                                       archive=dist/oz_0.0.0-rc9-SNAPSHOT-227eb29_linux_arm64.tar.gz
    • took: 8s
  • calculating checksums
  • docker images
    • building docker image                          image=ghcr.io/diranged/oz:0.0.1
    • building docker image                          image=ghcr.io/diranged/oz:0.0.0-rc9-SNAPSHOT-227eb29-amd64
    • building docker image                          image=ghcr.io/diranged/oz:0.0.0-rc9-SNAPSHOT-227eb29-arm64v8
    • took: 3s
  • storing release metadata
    • writing                                        file=dist/artifacts.json
    • writing                                        file=dist/metadata.json
  • release succeeded after 13s
diranged@Matts-Air-UW oz % git status
On branch fix_build
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   api/v1alpha1/zz_generated.deepcopy.go

no changes added to commit (use "git add" and/or "git commit -a")
diranged@Matts-Air-UW oz % git diff
diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go
index b9e85b7..aa3a51c 100644
--- a/api/v1alpha1/zz_generated.deepcopy.go
+++ b/api/v1alpha1/zz_generated.deepcopy.go
@@ -22,7 +22,7 @@ limitations under the License.
 package v1alpha1

 import (
-       v1 "k8s.io/api/core/v1"
+       "k8s.io/api/core/v1"
        "k8s.io/apimachinery/pkg/runtime"
 )

diranged@Matts-Air-UW oz %
```
diranged added a commit that referenced this pull request Dec 5, 2022
The latest release attempt
(https://github.com/diranged/oz/actions/runs/3621310569/jobs/6105202279)
failed. In digging in, it looks like in
#53 we made a change to the
auto-generated file that was likely done via a IDE or auto-linter.. but
that causes the `make build` to mutate the files before the final
release, which causes `make release` to fail.

```
diranged@Matts-Air-UW oz % make build
Custom.mk:38: warning: overriding commands for target `lint'
Makefile:104: warning: ignoring old commands for target `lint'
Custom.mk:65: warning: overriding commands for target `fmt'
Makefile:100: warning: ignoring old commands for target `fmt'
Custom.mk:79: warning: overriding commands for target `build'
Makefile:114: warning: ignoring old commands for target `build'
test -s /Users/diranged/go/src/github.com/diranged/oz/bin/controller-gen || GOBIN=/Users/diranged/go/src/github.com/diranged/oz/bin go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.10.0
/Users/diranged/go/src/github.com/diranged/oz/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
PUBLISH=false /Library/Developer/CommandLineTools/usr/bin/make release
Custom.mk:38: warning: overriding commands for target `lint'
Makefile:104: warning: ignoring old commands for target `lint'
Custom.mk:65: warning: overriding commands for target `fmt'
Makefile:100: warning: ignoring old commands for target `fmt'
Custom.mk:79: warning: overriding commands for target `build'
Makefile:114: warning: ignoring old commands for target `build'
IMG=ghcr.io/diranged/oz:0.0.1 /Users/diranged/go/src/github.com/diranged/oz/bin/goreleaser release --skip-publish --snapshot --rm-dist
  • starting release...
  • loading config file                              file=.goreleaser.yml
  • loading environment variables
  • getting and validating git state
    • building...                                    commit=227eb29e4c6b40278a6eea5fdb86b4287fb8af98 latest tag=0.0.0-rc9
    • pipe skipped                                   reason=disabled during snapshot mode
  • parsing tag
  • setting defaults
  • running before hooks
    • running                                        hook=go mod tidy
  • snapshotting
    • building snapshot...                           version=0.0.0-rc9-SNAPSHOT-227eb29
  • checking distribution directory
    • --rm-dist is set, cleaning it up
  • loading go mod information
  • build prerequisites
  • writing effective config file
    • writing                                        config=dist/config.yaml
  • building binaries
    • building                                       binary=dist/cli_darwin_amd64_v1/ozctl
    • building                                       binary=dist/manager_linux_arm64/manager
    • building                                       binary=dist/cli_darwin_arm64/ozctl
    • building                                       binary=dist/manager_linux_amd64_v1/manager
    • took: 3s
  • universal binaries
    • creating from 2 binaries                       binary=dist/cli_darwin_all/ozctl id=cli
  • archives
    • creating                                       archive=dist/oz_0.0.0-rc9-SNAPSHOT-227eb29_darwin_all.tar.gz
    • creating                                       archive=dist/oz_0.0.0-rc9-SNAPSHOT-227eb29_linux_amd64.tar.gz
    • creating                                       archive=dist/oz_0.0.0-rc9-SNAPSHOT-227eb29_linux_arm64.tar.gz
    • took: 8s
  • calculating checksums
  • docker images
    • building docker image                          image=ghcr.io/diranged/oz:0.0.1
    • building docker image                          image=ghcr.io/diranged/oz:0.0.0-rc9-SNAPSHOT-227eb29-amd64
    • building docker image                          image=ghcr.io/diranged/oz:0.0.0-rc9-SNAPSHOT-227eb29-arm64v8
    • took: 3s
  • storing release metadata
    • writing                                        file=dist/artifacts.json
    • writing                                        file=dist/metadata.json
  • release succeeded after 13s
diranged@Matts-Air-UW oz % git status
On branch fix_build
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   api/v1alpha1/zz_generated.deepcopy.go

no changes added to commit (use "git add" and/or "git commit -a")
diranged@Matts-Air-UW oz % git diff
diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go
index b9e85b7..aa3a51c 100644
--- a/api/v1alpha1/zz_generated.deepcopy.go
+++ b/api/v1alpha1/zz_generated.deepcopy.go
@@ -22,7 +22,7 @@ limitations under the License.
 package v1alpha1

 import (
-       v1 "k8s.io/api/core/v1"
+       "k8s.io/api/core/v1"
        "k8s.io/apimachinery/pkg/runtime"
 )

diranged@Matts-Air-UW oz %
```
diranged added a commit that referenced this pull request Dec 5, 2022
The latest release attempt

(https://github.com/diranged/oz/actions/runs/3621310569/jobs/6105202279)
failed. In digging in, it looks like in
#53 we made a change to the
auto-generated file that was likely done via a IDE or auto-linter.. but
that causes the `make build` to mutate the files before the final
release, which causes `make release` to fail.

```
diranged@Matts-Air-UW oz % make build
Custom.mk:38: warning: overriding commands for target `lint'
Makefile:104: warning: ignoring old commands for target `lint'
Custom.mk:65: warning: overriding commands for target `fmt'
Makefile:100: warning: ignoring old commands for target `fmt'
Custom.mk:79: warning: overriding commands for target `build'
Makefile:114: warning: ignoring old commands for target `build'
test -s /Users/diranged/go/src/github.com/diranged/oz/bin/controller-gen || GOBIN=/Users/diranged/go/src/github.com/diranged/oz/bin go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.10.0
/Users/diranged/go/src/github.com/diranged/oz/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
PUBLISH=false /Library/Developer/CommandLineTools/usr/bin/make release
Custom.mk:38: warning: overriding commands for target `lint'
Makefile:104: warning: ignoring old commands for target `lint'
Custom.mk:65: warning: overriding commands for target `fmt'
Makefile:100: warning: ignoring old commands for target `fmt'
Custom.mk:79: warning: overriding commands for target `build'
Makefile:114: warning: ignoring old commands for target `build'
IMG=ghcr.io/diranged/oz:0.0.1 /Users/diranged/go/src/github.com/diranged/oz/bin/goreleaser release --skip-publish --snapshot --rm-dist
  • starting release...
  • loading config file                              file=.goreleaser.yml
  • loading environment variables
  • getting and validating git state
    • building...                                    commit=227eb29e4c6b40278a6eea5fdb86b4287fb8af98 latest tag=0.0.0-rc9
    • pipe skipped                                   reason=disabled during snapshot mode
  • parsing tag
  • setting defaults
  • running before hooks
    • running                                        hook=go mod tidy
  • snapshotting
    • building snapshot...                           version=0.0.0-rc9-SNAPSHOT-227eb29
  • checking distribution directory
    • --rm-dist is set, cleaning it up
  • loading go mod information
  • build prerequisites
  • writing effective config file
    • writing                                        config=dist/config.yaml
  • building binaries
    • building                                       binary=dist/cli_darwin_amd64_v1/ozctl
    • building                                       binary=dist/manager_linux_arm64/manager
    • building                                       binary=dist/cli_darwin_arm64/ozctl
    • building                                       binary=dist/manager_linux_amd64_v1/manager
    • took: 3s
  • universal binaries
    • creating from 2 binaries                       binary=dist/cli_darwin_all/ozctl id=cli
  • archives
    • creating                                       archive=dist/oz_0.0.0-rc9-SNAPSHOT-227eb29_darwin_all.tar.gz
    • creating                                       archive=dist/oz_0.0.0-rc9-SNAPSHOT-227eb29_linux_amd64.tar.gz
    • creating                                       archive=dist/oz_0.0.0-rc9-SNAPSHOT-227eb29_linux_arm64.tar.gz
    • took: 8s
  • calculating checksums
  • docker images
    • building docker image                          image=ghcr.io/diranged/oz:0.0.1
    • building docker image                          image=ghcr.io/diranged/oz:0.0.0-rc9-SNAPSHOT-227eb29-amd64
    • building docker image                          image=ghcr.io/diranged/oz:0.0.0-rc9-SNAPSHOT-227eb29-arm64v8
    • took: 3s
  • storing release metadata
    • writing                                        file=dist/artifacts.json
    • writing                                        file=dist/metadata.json
  • release succeeded after 13s
diranged@Matts-Air-UW oz % git status
On branch fix_build
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   api/v1alpha1/zz_generated.deepcopy.go

no changes added to commit (use "git add" and/or "git commit -a")
diranged@Matts-Air-UW oz % git diff
diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go
index b9e85b7..aa3a51c 100644
--- a/api/v1alpha1/zz_generated.deepcopy.go
+++ b/api/v1alpha1/zz_generated.deepcopy.go
@@ -22,7 +22,7 @@ limitations under the License.
 package v1alpha1

 import (
-       v1 "k8s.io/api/core/v1"
+       "k8s.io/api/core/v1"
        "k8s.io/apimachinery/pkg/runtime"
 )

diranged@Matts-Air-UW oz %
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build github_actions Pull requests that update GitHub Actions code repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants