Skip to content
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

(ci): add linting + fix existing errors #99

Merged
merged 5 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .bingo/Variables.mk
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ $(GINKGO): $(BINGO_DIR)/ginkgo.mod
@echo "(re)installing $(GOBIN)/ginkgo-v2.9.7"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=ginkgo.mod -o=$(GOBIN)/ginkgo-v2.9.7 "github.com/onsi/ginkgo/v2/ginkgo"

GOLANGCI_LINT := $(GOBIN)/golangci-lint-v1.53.3
$(GOLANGCI_LINT): $(BINGO_DIR)/golangci-lint.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/golangci-lint-v1.53.3"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=golangci-lint.mod -o=$(GOBIN)/golangci-lint-v1.53.3 "github.com/golangci/golangci-lint/cmd/golangci-lint"

GORELEASER := $(GOBIN)/goreleaser-v1.16.2
$(GORELEASER): $(BINGO_DIR)/goreleaser.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
Expand Down
5 changes: 5 additions & 0 deletions .bingo/golangci-lint.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.20

require github.com/golangci/golangci-lint v1.53.3 // cmd/golangci-lint
954 changes: 954 additions & 0 deletions .bingo/golangci-lint.sum

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .bingo/variables.env
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ CONTROLLER_GEN="${GOBIN}/controller-gen-v0.11.4"

GINKGO="${GOBIN}/ginkgo-v2.9.7"

GOLANGCI_LINT="${GOBIN}/golangci-lint-v1.53.3"

GORELEASER="${GOBIN}/goreleaser-v1.16.2"

KIND="${GOBIN}/kind-v0.15.0"
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/sanity.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version-file: "go.mod"
- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run verification checks
run: make verify
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: "go.mod"
- name: Run lint checks
run: make lint GOLANGCI_LINT_ARGS="--out-format github-actions"
51 changes: 51 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
run:
# Default timeout is 1m, up to give more room
timeout: 4m

linters:
enable:
- asciicheck
- bodyclose
- errorlint
- ginkgolinter
- gofmt
- goimports
- gosec
- importas
- misspell
- nestif
- nonamedreturns
- prealloc
- revive
- stylecheck
- tparallel
- unconvert
- unparam
- unused
- whitespace

linters-settings:
errorlint:
errorf: false

importas:
alias:
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
alias: metav1
- pkg: k8s.io/apimachinery/pkg/api/errors
alias: apierrors
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
alias: apiextensionsv1
- pkg: k8s.io/apimachinery/pkg/util/runtime
alias: utilruntime
- pkg: "^k8s\\.io/api/([^/]+)/(v[^/]+)$"
alias: $1$2
- pkg: sigs.k8s.io/controller-runtime
alias: ctrl
- pkg: github.com/operator-framework/rukpak/api/v1alpha1
alias: rukpakv1alpha1
goimports:
local-prefixes: github.com/operator-framework/catalogd

output:
format: tab
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ tidy: ## Update dependencies
verify: tidy fmt vet generate ## Verify the current code generation and lint
git diff --exit-code

.PHONY: lint
lint: $(GOLANGCI_LINT) ## Run golangci linter.
$(GOLANGCI_LINT) run $(GOLANGCI_LINT_ARGS)

##@ Build

BINARIES=manager
Expand Down
15 changes: 12 additions & 3 deletions pkg/controllers/core/catalog_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ func (r *CatalogReconciler) SetupWithManager(mgr ctrl.Manager) error {
Complete(r)
}

// Note: This function always returns ctrl.Result{}. The linter
// fusses about this as we could instead just return error. This was
// discussed in https://github.com/operator-framework/rukpak/pull/635#discussion_r1229859464
// and the consensus was that it is better to keep the ctrl.Result return
// type so that if we do end up needing to return something else we don't forget
// to add the ctrl.Result type back as a return value. Adding a comment to ignore
// linting from the linter that was fussing about this.
// nolint:unparam
everettraven marked this conversation as resolved.
Show resolved Hide resolved
func (r *CatalogReconciler) reconcile(ctx context.Context, catalog *v1alpha1.Catalog) (ctrl.Result, error) {
unpackResult, err := r.Unpacker.Unpack(ctx, catalog)
if err != nil {
Expand Down Expand Up @@ -146,7 +154,6 @@ func (r *CatalogReconciler) reconcile(ctx context.Context, catalog *v1alpha1.Cat
default:
return ctrl.Result{}, updateStatusUnpackFailing(&catalog.Status, fmt.Errorf("unknown unpack state %q: %v", unpackResult.State, err))
}

}

func updateStatusUnpackPending(status *v1alpha1.CatalogStatus, result *source.Result) {
Expand Down Expand Up @@ -254,7 +261,8 @@ func (r *CatalogReconciler) syncBundleMetadata(ctx context.Context, declCfg *dec
if err := r.List(ctx, &existingBundles); err != nil {
return fmt.Errorf("list existing bundle metadatas: %v", err)
}
for _, existingBundle := range existingBundles.Items {
for i := range existingBundles.Items {
existingBundle := existingBundles.Items[i]
if _, ok := newBundles[existingBundle.Name]; !ok {
if err := r.Delete(ctx, &existingBundle); err != nil {
return fmt.Errorf("delete existing bundle metadata %q: %v", existingBundle.Name, err)
Expand Down Expand Up @@ -340,7 +348,8 @@ func (r *CatalogReconciler) syncPackages(ctx context.Context, declCfg *declcfg.D
if err := r.List(ctx, &existingPkgs); err != nil {
return fmt.Errorf("list existing packages: %v", err)
}
for _, existingPkg := range existingPkgs.Items {
for i := range existingPkgs.Items {
existingPkg := existingPkgs.Items[i]
if _, ok := newPkgs[existingPkg.Name]; !ok {
// delete existing package
if err := r.Delete(ctx, &existingPkg); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/core/catalog_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type MockSource struct {
shouldError bool
}

func (ms *MockSource) Unpack(ctx context.Context, catalog *v1alpha1.Catalog) (*source.Result, error) {
func (ms *MockSource) Unpack(_ context.Context, _ *v1alpha1.Catalog) (*source.Result, error) {
if ms.shouldError {
return nil, errors.New("mocksource error")
}
Expand Down Expand Up @@ -314,7 +314,7 @@ var _ = Describe("Catalogd Controller Test", func() {
Expect(pack.Spec.Channels).To(HaveLen(1))
Expect(pack.Spec.Channels[0].Name).To(Equal(testChannelName))
Expect(pack.Spec.Channels[0].Entries).To(HaveLen(1))
Expect(Expect(pack.Spec.Channels[0].Entries[0].Name).To(Equal(testBundleName)))
Expect(pack.Spec.Channels[0].Entries[0].Name).To(Equal(testBundleName))
})
})
})
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/unpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"

Check failure on line 10 in test/e2e/unpack_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed with -local github.com/operator-framework/catalogd (goimports)
v1 "k8s.io/api/core/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -66,7 +66,7 @@
By("Ensuring the expected Package resource is created")
pack := &catalogd.Package{}
expectedPackSpec := catalogd.PackageSpec{
Catalog: v1.LocalObjectReference{
Catalog: corev1.LocalObjectReference{
Name: catalogName,
},
Channels: []catalogd.PackageChannel{
Expand All @@ -89,7 +89,7 @@
By("Ensuring the expected BundleMetadata resource is created")
bm := &catalogd.BundleMetadata{}
expectedBMSpec := catalogd.BundleMetadataSpec{
Catalog: v1.LocalObjectReference{
Catalog: corev1.LocalObjectReference{
Name: catalogName,
},
Package: pkg,
Expand Down
Loading