Skip to content

Commit 4030659

Browse files
grokspawnci-robot
authored andcommitted
enable linting and bingo management of the lint tool (#1524)
* enable linting and bingo management of the lint tool Signed-off-by: Jordan Keister <[email protected]> * automated lint fixes Signed-off-by: Jordan Keister <[email protected]> * manual test fixes Signed-off-by: Jordan <[email protected]> * linter feature code - errcheck - stylecheck - nestif - prealloc - errorlint - nonamedreturns - gosec - gosimple - govet - importas - staticcheck - unused Signed-off-by: Jordan Keister <[email protected]> * update bingo to work with go version stampede Signed-off-by: Jordan Keister <[email protected]> * review revisions Signed-off-by: Jordan Keister <[email protected]> --------- Signed-off-by: Jordan Keister <[email protected]> Signed-off-by: Jordan <[email protected]> Upstream-repository: operator-registry Upstream-commit: 5531412dd246954ef6e52350010793c8b65f4d38
1 parent d86fa57 commit 4030659

File tree

274 files changed

+2906
-1335
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

274 files changed

+2906
-1335
lines changed

staging/operator-registry/.bingo/Variables.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ $(GINKGO): $(BINGO_DIR)/ginkgo.mod
2929
@echo "(re)installing $(GOBIN)/ginkgo-v2.22.2"
3030
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=ginkgo.mod -o=$(GOBIN)/ginkgo-v2.22.2 "github.com/onsi/ginkgo/v2/ginkgo"
3131

32+
GOLANGCI_LINT := $(GOBIN)/golangci-lint-v1.63.4
33+
$(GOLANGCI_LINT): $(BINGO_DIR)/golangci-lint.mod
34+
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
35+
@echo "(re)installing $(GOBIN)/golangci-lint-v1.63.4"
36+
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=golangci-lint.mod -o=$(GOBIN)/golangci-lint-v1.63.4 "github.com/golangci/golangci-lint/cmd/golangci-lint"
37+
3238
GORELEASER := $(GOBIN)/goreleaser-v1.26.2
3339
$(GORELEASER): $(BINGO_DIR)/goreleaser.mod
3440
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT
2+
3+
go 1.22.5
4+
5+
require github.com/golangci/golangci-lint v1.63.4 // cmd/golangci-lint

staging/operator-registry/.bingo/golangci-lint.sum

Lines changed: 1071 additions & 0 deletions
Large diffs are not rendered by default.

staging/operator-registry/.bingo/variables.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ BINGO="${GOBIN}/bingo-v0.9.0"
1212

1313
GINKGO="${GOBIN}/ginkgo-v2.22.2"
1414

15+
GOLANGCI_LINT="${GOBIN}/golangci-lint-v1.63.4"
16+
1517
GORELEASER="${GOBIN}/goreleaser-v1.26.2"
1618

1719
PROTOC_GEN_GO_GRPC="${GOBIN}/protoc-gen-go-grpc-v1.3.0"
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
########
2+
# NOTE
3+
#
4+
# This file is duplicated in the following repos:
5+
# - operator-framework/kubectl-operator
6+
# - operator-framework/catalogd
7+
# - operator-framework/operator-controller
8+
# - operator-framework/operator-registry
9+
#
10+
# If you are making a change, please make it in ALL
11+
# of the above repositories!
12+
#
13+
# TODO: Find a way to have a shared golangci config.
14+
########
15+
16+
run:
17+
# Default timeout is 1m, up to give more room
18+
timeout: 4m
19+
20+
linters:
21+
enable:
22+
- asciicheck
23+
- bodyclose
24+
- errorlint
25+
- gci
26+
- gofmt
27+
- govet
28+
- gosec
29+
- importas
30+
- misspell
31+
- nestif
32+
- nonamedreturns
33+
- prealloc
34+
- stylecheck
35+
- testifylint
36+
- tparallel
37+
- unconvert
38+
- unparam
39+
- unused
40+
- whitespace
41+
42+
linters-settings:
43+
gci:
44+
sections:
45+
- standard
46+
- dot
47+
- default
48+
- prefix(github.com/operator-framework)
49+
- localmodule
50+
custom-order: true
51+
52+
errorlint:
53+
errorf: false
54+
55+
importas:
56+
alias:
57+
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
58+
alias: metav1
59+
- pkg: k8s.io/apimachinery/pkg/api/errors
60+
alias: apierrors
61+
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
62+
alias: apiextensionsv1
63+
- pkg: k8s.io/apimachinery/pkg/util/runtime
64+
alias: utilruntime
65+
- pkg: "^k8s\\.io/api/([^/]+)/(v[^/]+)$"
66+
alias: $1$2
67+
- pkg: sigs.k8s.io/controller-runtime
68+
alias: ctrl
69+
- pkg: github.com/blang/semver/v4
70+
alias: bsemver
71+
72+
issues:
73+
# exclusion rules, mostly to avoid functionally complete areas and reduce unit test noise
74+
exclude-rules:
75+
- path: _test\.go
76+
linters:
77+
- unused
78+
- govet
79+
80+
81+
output:
82+
formats:
83+
- format: tab

staging/operator-registry/Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,14 @@ image-upstream:
102102
docker build -f upstream-example.Dockerfile .
103103

104104
.PHONY: lint
105-
lint:
106-
find . -type f -name '*.go' ! -name '*.pb.go' -print0 | xargs -0 goimports -w
105+
#lint:
106+
# find . -type f -name '*.go' ! -name '*.pb.go' -print0 | xargs -0 goimports -w
107+
lint: $(GOLANGCI_LINT)
108+
$(GOLANGCI_LINT) run $(GOLANGCI_LINT_ARGS)
109+
110+
.PHONY: fix-lint
111+
fix-lint: $(GOLANGCI_LINT)
112+
$(GOLANGCI_LINT) run --fix $(GOLANGCI_LINT_ARGS)
107113

108114
.PHONY: bingo-upgrade
109115
bingo-upgrade: $(BINGO) #EXHELP Upgrade tools

staging/operator-registry/alpha/action/migrate_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func TestMigrate(t *testing.T) {
125125
return
126126
}
127127
actualFS := os.DirFS(s.migrate.OutputDir)
128-
fs.WalkDir(actualFS, ".", func(path string, d fs.DirEntry, err error) error {
128+
require.NoError(t, fs.WalkDir(actualFS, ".", func(path string, d fs.DirEntry, err error) error {
129129
require.NoError(t, err)
130130
if d.IsDir() {
131131
return nil
@@ -136,7 +136,7 @@ func TestMigrate(t *testing.T) {
136136
require.True(t, ok, "output directory contained unexpected file %q", path)
137137
require.Equal(t, expectedData, string(actualData))
138138
return nil
139-
})
139+
}))
140140
})
141141
}
142142
}
@@ -291,7 +291,6 @@ relatedImages:
291291
name: operator
292292
schema: olm.bundle
293293
`
294-
295294
}
296295

297296
func migrateBarCatalogSqlite() string {

staging/operator-registry/alpha/action/migrations/migrations_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import (
88
"testing"
99

1010
"github.com/google/go-cmp/cmp"
11+
"github.com/stretchr/testify/require"
12+
1113
"github.com/operator-framework/api/pkg/operators/v1alpha1"
14+
1215
"github.com/operator-framework/operator-registry/alpha/declcfg"
1316
"github.com/operator-framework/operator-registry/alpha/property"
14-
"github.com/stretchr/testify/require"
1517
)
1618

1719
func TestMigrations(t *testing.T) {
@@ -57,7 +59,7 @@ func TestMigrations(t *testing.T) {
5759

5860
for _, test := range tests {
5961
t.Run(test.name, func(t *testing.T) {
60-
var config declcfg.DeclarativeConfig = unmigratedCatalogFBC()
62+
var config = unmigratedCatalogFBC()
6163

6264
for _, m := range test.migrators.Migrations {
6365
err := m.Migrate(&config)

staging/operator-registry/alpha/action/render.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,13 @@ func (r Render) Run(ctx context.Context) (*declcfg.DeclarativeConfig, error) {
7070
if err != nil {
7171
return nil, fmt.Errorf("create registry: %v", err)
7272
}
73-
defer reg.Destroy()
73+
defer func() {
74+
_ = reg.Destroy()
75+
}()
7476
r.Registry = reg
7577
}
7678

79+
// nolint:prealloc
7780
var cfgs []declcfg.DeclarativeConfig
7881
for _, ref := range r.Refs {
7982
cfg, err := r.renderReference(ctx, ref)
@@ -123,6 +126,7 @@ func (r Render) renderReference(ctx context.Context, ref string) (*declcfg.Decla
123126
if err != nil {
124127
return r.imageToDeclcfg(ctx, ref)
125128
}
129+
// nolint:nestif
126130
if stat.IsDir() {
127131
dirEntries, err := os.ReadDir(ref)
128132
if err != nil {
@@ -178,6 +182,7 @@ func (r Render) imageToDeclcfg(ctx context.Context, imageRef string) (*declcfg.D
178182
}
179183

180184
var cfg *declcfg.DeclarativeConfig
185+
// nolint:nestif
181186
if dbFile, ok := labels[containertools.DbLocationLabel]; ok {
182187
if !r.AllowedRefMask.Allowed(RefSqliteImage) {
183188
return nil, fmt.Errorf("cannot render sqlite image: %w", ErrNotAllowed)
@@ -279,6 +284,7 @@ func populateDBRelatedImages(ctx context.Context, cfg *declcfg.DeclarativeConfig
279284
}
280285
defer rows.Close()
281286

287+
// nolint:staticcheck
282288
images := map[string]sets.String{}
283289
for rows.Next() {
284290
var (
@@ -326,10 +332,10 @@ func bundleToDeclcfg(bundle *registry.Bundle) (*declcfg.Bundle, error) {
326332
return nil, fmt.Errorf("get related images for bundle %q: %v", bundle.Name, err)
327333
}
328334

329-
var csvJson []byte
335+
var csvJSON []byte
330336
for _, obj := range bundle.Objects {
331337
if obj.GetKind() == "ClusterServiceVersion" {
332-
csvJson, err = json.Marshal(obj)
338+
csvJSON, err = json.Marshal(obj)
333339
if err != nil {
334340
return nil, fmt.Errorf("marshal CSV JSON for bundle %q: %v", bundle.Name, err)
335341
}
@@ -344,7 +350,7 @@ func bundleToDeclcfg(bundle *registry.Bundle) (*declcfg.Bundle, error) {
344350
Properties: props,
345351
RelatedImages: relatedImages,
346352
Objects: objs,
347-
CsvJSON: string(csvJson),
353+
CsvJSON: string(csvJSON),
348354
}, nil
349355
}
350356

staging/operator-registry/alpha/action/render_test.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"embed"
66
"encoding/json"
7-
"errors"
87
"fmt"
98
"io/fs"
109
"os"
@@ -13,7 +12,6 @@ import (
1312
"testing/fstest"
1413
"text/template"
1514

16-
"github.com/stretchr/testify/assert"
1715
"github.com/stretchr/testify/require"
1816
"k8s.io/apimachinery/pkg/util/yaml"
1917

@@ -86,11 +84,11 @@ func TestRender(t *testing.T) {
8684
image.SimpleReference("test.registry/foo-operator/foo-bundle:v0.1.0"): "testdata/foo-bundle-v0.1.0",
8785
image.SimpleReference("test.registry/foo-operator/foo-bundle:v0.2.0"): "testdata/foo-bundle-v0.2.0",
8886
}
89-
assert.NoError(t, generateSqliteFile(dbFile, imageMap))
87+
require.NoError(t, generateSqliteFile(dbFile, imageMap))
9088
testMigrations := migrations.Migrations{
9189
Migrations: []migrations.Migration{
9290
fauxMigration{"faux-migration", "my help text", func(d *declcfg.DeclarativeConfig) error {
93-
for i, _ := range d.Bundles {
91+
for i := range d.Bundles {
9492
d.Bundles[i].Name = fmt.Sprintf("%s-MIGRATED", d.Bundles[i].Name)
9593
}
9694
return nil
@@ -1235,7 +1233,7 @@ func TestAllowRefMask(t *testing.T) {
12351233
image.SimpleReference("test.registry/foo-operator/foo-bundle:v0.1.0"): "testdata/foo-bundle-v0.1.0",
12361234
image.SimpleReference("test.registry/foo-operator/foo-bundle:v0.2.0"): "testdata/foo-bundle-v0.2.0",
12371235
}
1238-
assert.NoError(t, generateSqliteFile(dbFile, imageMap))
1236+
require.NoError(t, generateSqliteFile(dbFile, imageMap))
12391237

12401238
specs := []spec{
12411239
{
@@ -1365,18 +1363,17 @@ func TestAllowRefMask(t *testing.T) {
13651363
for _, s := range specs {
13661364
t.Run(s.name, func(t *testing.T) {
13671365
_, err := s.render.Run(context.Background())
1368-
require.True(t, errors.Is(err, s.expectErr), "expected error %#v to be %#v", err, s.expectErr)
1366+
require.ErrorIs(t, err, s.expectErr, "expected error %#v to be %#v", err, s.expectErr)
13691367
})
13701368
}
13711369
}
13721370

13731371
func TestAllowRefMaskAllowed(t *testing.T) {
13741372
type spec struct {
1375-
name string
1376-
mask action.RefType
1377-
pass []action.RefType
1378-
fail []action.RefType
1379-
expect bool
1373+
name string
1374+
mask action.RefType
1375+
pass []action.RefType
1376+
fail []action.RefType
13801377
}
13811378

13821379
specs := []spec{

0 commit comments

Comments
 (0)