From c33c1b8570f9ccc1d931433d135ffff2e37d274f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Svantesson?= Date: Thu, 10 Oct 2024 17:52:28 +0200 Subject: [PATCH] chore: fix linting related to jenkins-x/jx#8670 --- .golangci.yml | 62 +++++++++++------------------------ pkg/masker/watcher/watcher.go | 29 ++++++++-------- 2 files changed, 34 insertions(+), 57 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index a00b8fc4..e0773eae 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,14 +1,16 @@ linters-settings: depguard: - list-type: blacklist - packages: - - github.com/jenkins-x/jx/v2/pkg/log/ - - github.com/satori/go.uuid - - github.com/pborman/uuid - packages-with-error-message: - - github.com/jenkins-x/jx/v2/pkg/log/: "use jenkins-x/jx-logging instead" - - github.com/satori/go.uuid: "use github.com/google/uuid instead" - - github.com/pborman/uuid: "use github.com/google/uuid instead" + rules: + # Name of a rule. + Main: + list-mode: lax + deny: + - pkg: github.com/jenkins-x/jx/v2/pkg/log/ + desc: "use jenkins-x/jx-logging instead" + - pkg: github.com/satori/go.uuid + desc: "use github.com/google/uuid instead" + - pkg: github.com/pborman/uuid + desc: "use github.com/google/uuid instead" dupl: threshold: 100 exhaustive: @@ -37,17 +39,14 @@ linters-settings: gocyclo: min-complexity: 15 goimports: {} - golint: - min-confidence: 0 + revive: + confidence: 0 gofmt: simplify: true - gomnd: - settings: - mnd: - # don't include the "operation" and "assign" - checks: [argument, case, condition, return] + mnd: + # don't include the "operation" and "assign" + checks: [argument, case, condition, return] govet: - check-shadowing: true settings: printf: funcs: @@ -58,11 +57,8 @@ linters-settings: - (github.com/jenkins-x/jx-logging/v3/pkg/log/Logger()).Fatalf lll: line-length: 140 - maligned: - suggest-new: true misspell: {} nolintlint: - allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space) allow-unused: false # report any unused nolint directives require-explanation: false # don't require an explanation for nolint directives require-specific: false # don't require nolint directives to be specific about which linter is being skipped @@ -73,7 +69,6 @@ linters: enable: - asciicheck - bodyclose - - deadcode - depguard - errcheck - gofmt @@ -86,36 +81,17 @@ linters: - nakedret - rowserrcheck - staticcheck - - structcheck - typecheck - unconvert - unparam - unused - - varcheck - - revive + #- revive - gocritic - govet issues: - # Excluding configuration per-path, per-linter, per-text and per-source - exclude-rules: - # - path: _test\.go - # linters: - # - gomnd - # https://github.com/go-critic/go-critic/issues/926 - - linters: - - gocritic - text: "unnecessaryDefer:" - exclude: - - 'shadow: declaration of "err" shadows declaration at' - max-same-issues: 0 - + exclude-dirs: + - cmd/docs run: timeout: 30m - skip-dirs: - - cmd/docs # golangci.com configuration # https://github.com/golangci/golangci/wiki/Configuration -service: - golangci-lint-version: 1.42.x # use the fixed version to not introduce new linters unexpectedly - prepare: - - echo "here I can run custom commands, but no preparation needed for this repo" diff --git a/pkg/masker/watcher/watcher.go b/pkg/masker/watcher/watcher.go index 7b41e806..5767f061 100644 --- a/pkg/masker/watcher/watcher.go +++ b/pkg/masker/watcher/watcher.go @@ -78,21 +78,22 @@ func (o *Options) RunWithChannel(stop chan struct{}) error { log.Logger().Infof("Watching for Secret resources in namespace %s", ns) listWatch := cache.NewListWatchFromClient(o.KubeClient.CoreV1().RESTClient(), "secrets", ns, fields.Everything()) kube.SortListWatchByName(listWatch) - _, ctrl := cache.NewInformer( - listWatch, - secret, - time.Minute*10, - cache.ResourceEventHandlerFuncs{ - AddFunc: func(obj interface{}) { - o.onSecret(ns, obj) + _, ctrl := cache.NewInformerWithOptions( + cache.InformerOptions{ + ListerWatcher: listWatch, + ObjectType: secret, + Handler: cache.ResourceEventHandlerFuncs{ + AddFunc: func(obj interface{}) { + o.onSecret(ns, obj) + }, + UpdateFunc: func(oldObj, newObj interface{}) { + o.onSecret(ns, newObj) + }, + DeleteFunc: func(obj interface{}) { + }, }, - UpdateFunc: func(oldObj, newObj interface{}) { - o.onSecret(ns, newObj) - }, - DeleteFunc: func(obj interface{}) { - }, - }, - ) + ResyncPeriod: time.Minute * 10, + }) go ctrl.Run(stop) } return nil