From 46ea676fc75e7a8844bbf237cf8e1c4b66b24dd4 Mon Sep 17 00:00:00 2001 From: Camila Macedo Date: Wed, 6 Sep 2023 12:08:10 +0100 Subject: [PATCH] add golangci integration to the default scaffold --- .../testdata/project/.golangci.yml | 40 +++++++++ .../testdata/project/Makefile | 15 ++++ .../testdata/project/.golangci.yml | 40 +++++++++ .../testdata/project/Makefile | 15 ++++ .../project/api/v1/cronjob_webhook.go | 1 + .../project/api/v1/webhook_suite_test.go | 3 +- .../templates/controllers/controller-test.go | 23 +++-- .../templates/controllers/controller.go | 1 - pkg/plugins/golang/v4/scaffolds/init.go | 2 +- .../internal/templates/api/webhook.go | 1 + .../templates/api/webhook_suitetest.go | 3 +- .../scaffolds/internal/templates/golangci.go | 85 +++++++++++++++++++ .../scaffolds/internal/templates/makefile.go | 15 ++++ test/e2e/externalplugin/generate_test.go | 3 - test/testdata/generate.sh | 2 +- testdata/project-v4-multigroup/.golangci.yml | 40 +++++++++ testdata/project-v4-multigroup/Makefile | 15 ++++ .../api/crew/v1/captain_webhook.go | 1 + .../api/crew/v1/webhook_suite_test.go | 3 +- .../example.com/v1alpha1/memcached_webhook.go | 1 + .../v1alpha1/webhook_suite_test.go | 3 +- .../api/ship/v1/destroyer_webhook.go | 1 + .../api/ship/v1/webhook_suite_test.go | 3 +- .../api/ship/v1beta1/frigate_webhook.go | 1 + .../api/ship/v2alpha1/cruiser_webhook.go | 1 + .../api/ship/v2alpha1/webhook_suite_test.go | 3 +- .../api/v1/lakers_webhook.go | 1 + .../api/v1/webhook_suite_test.go | 3 +- .../example.com/busybox_controller.go | 1 - .../example.com/busybox_controller_test.go | 23 +++-- .../example.com/memcached_controller.go | 1 - .../example.com/memcached_controller_test.go | 23 +++-- .../.golangci.yml | 40 +++++++++ .../project-v4-with-deploy-image/Makefile | 15 ++++ .../api/v1alpha1/memcached_webhook.go | 1 + .../api/v1alpha1/webhook_suite_test.go | 3 +- .../internal/controller/busybox_controller.go | 1 - .../controller/busybox_controller_test.go | 23 +++-- .../controller/memcached_controller.go | 1 - .../controller/memcached_controller_test.go | 23 +++-- .../project-v4-with-grafana/.golangci.yml | 40 +++++++++ testdata/project-v4-with-grafana/Makefile | 15 ++++ testdata/project-v4/.golangci.yml | 40 +++++++++ testdata/project-v4/Makefile | 15 ++++ testdata/project-v4/api/v1/admiral_webhook.go | 1 + testdata/project-v4/api/v1/captain_webhook.go | 1 + .../project-v4/api/v1/firstmate_webhook.go | 1 + .../project-v4/api/v1/webhook_suite_test.go | 3 +- 48 files changed, 538 insertions(+), 58 deletions(-) create mode 100644 docs/book/src/component-config-tutorial/testdata/project/.golangci.yml create mode 100644 docs/book/src/cronjob-tutorial/testdata/project/.golangci.yml create mode 100644 pkg/plugins/golang/v4/scaffolds/internal/templates/golangci.go create mode 100644 testdata/project-v4-multigroup/.golangci.yml create mode 100644 testdata/project-v4-with-deploy-image/.golangci.yml create mode 100644 testdata/project-v4-with-grafana/.golangci.yml create mode 100644 testdata/project-v4/.golangci.yml diff --git a/docs/book/src/component-config-tutorial/testdata/project/.golangci.yml b/docs/book/src/component-config-tutorial/testdata/project/.golangci.yml new file mode 100644 index 0000000000..aed8644d11 --- /dev/null +++ b/docs/book/src/component-config-tutorial/testdata/project/.golangci.yml @@ -0,0 +1,40 @@ +run: + deadline: 5m + allow-parallel-runners: true + +issues: + # don't skip warning about doc comments + # don't exclude the default set of lint + exclude-use-default: false + # restore some of the defaults + # (fill in the rest as needed) + exclude-rules: + - path: "api/*" + linters: + - lll + - path: "internal/*" + linters: + - dupl + - lll +linters: + disable-all: true + enable: + - dupl + - errcheck + - exportloopref + - goconst + - gocyclo + - gofmt + - goimports + - gosimple + - govet + - ineffassign + - lll + - misspell + - nakedret + - prealloc + - staticcheck + - typecheck + - unconvert + - unparam + - unused diff --git a/docs/book/src/component-config-tutorial/testdata/project/Makefile b/docs/book/src/component-config-tutorial/testdata/project/Makefile index 751cdd7716..fc949b7f47 100644 --- a/docs/book/src/component-config-tutorial/testdata/project/Makefile +++ b/docs/book/src/component-config-tutorial/testdata/project/Makefile @@ -64,6 +64,21 @@ vet: ## Run go vet against code. test: manifests generate fmt vet envtest ## Run tests. KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out +GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint +golangci-lint: + @[ -f $(GOLANGCI_LINT) ] || { \ + set -e ;\ + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) v1.54.2 ;\ + } + +.PHONY: lint +lint: golangci-lint ## Run golangci-lint linter & yamllint + $(GOLANGCI_LINT) run + +.PHONY: lint-fix +lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes + $(GOLANGCI_LINT) run --fix + ##@ Build .PHONY: build diff --git a/docs/book/src/cronjob-tutorial/testdata/project/.golangci.yml b/docs/book/src/cronjob-tutorial/testdata/project/.golangci.yml new file mode 100644 index 0000000000..aed8644d11 --- /dev/null +++ b/docs/book/src/cronjob-tutorial/testdata/project/.golangci.yml @@ -0,0 +1,40 @@ +run: + deadline: 5m + allow-parallel-runners: true + +issues: + # don't skip warning about doc comments + # don't exclude the default set of lint + exclude-use-default: false + # restore some of the defaults + # (fill in the rest as needed) + exclude-rules: + - path: "api/*" + linters: + - lll + - path: "internal/*" + linters: + - dupl + - lll +linters: + disable-all: true + enable: + - dupl + - errcheck + - exportloopref + - goconst + - gocyclo + - gofmt + - goimports + - gosimple + - govet + - ineffassign + - lll + - misspell + - nakedret + - prealloc + - staticcheck + - typecheck + - unconvert + - unparam + - unused diff --git a/docs/book/src/cronjob-tutorial/testdata/project/Makefile b/docs/book/src/cronjob-tutorial/testdata/project/Makefile index 751cdd7716..fc949b7f47 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/Makefile +++ b/docs/book/src/cronjob-tutorial/testdata/project/Makefile @@ -64,6 +64,21 @@ vet: ## Run go vet against code. test: manifests generate fmt vet envtest ## Run tests. KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out +GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint +golangci-lint: + @[ -f $(GOLANGCI_LINT) ] || { \ + set -e ;\ + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) v1.54.2 ;\ + } + +.PHONY: lint +lint: golangci-lint ## Run golangci-lint linter & yamllint + $(GOLANGCI_LINT) run + +.PHONY: lint-fix +lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes + $(GOLANGCI_LINT) run --fix + ##@ Build .PHONY: build diff --git a/docs/book/src/cronjob-tutorial/testdata/project/api/v1/cronjob_webhook.go b/docs/book/src/cronjob-tutorial/testdata/project/api/v1/cronjob_webhook.go index 909469c09c..e75120e120 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/api/v1/cronjob_webhook.go +++ b/docs/book/src/cronjob-tutorial/testdata/project/api/v1/cronjob_webhook.go @@ -42,6 +42,7 @@ var cronjoblog = logf.Log.WithName("cronjob-resource") Then, we set up the webhook with the manager. */ +// SetupWebhookWithManager will setup the manager to manage the webhooks func (r *CronJob) SetupWebhookWithManager(mgr ctrl.Manager) error { return ctrl.NewWebhookManagedBy(mgr). For(r). diff --git a/docs/book/src/cronjob-tutorial/testdata/project/api/v1/webhook_suite_test.go b/docs/book/src/cronjob-tutorial/testdata/project/api/v1/webhook_suite_test.go index eba3577726..e82b72c260 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/api/v1/webhook_suite_test.go +++ b/docs/book/src/cronjob-tutorial/testdata/project/api/v1/webhook_suite_test.go @@ -132,8 +132,7 @@ var _ = BeforeSuite(func() { if err != nil { return err } - conn.Close() - return nil + return conn.Close() }).Should(Succeed()) }) diff --git a/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller-test.go b/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller-test.go index 8ed8601ffd..4ecfb70803 100644 --- a/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller-test.go +++ b/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller-test.go @@ -81,6 +81,7 @@ import ( "time" "fmt" + //nolint:golint . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" appsv1 "k8s.io/api/apps/v1" @@ -109,7 +110,10 @@ var _ = Describe("{{ .Resource.Kind }} controller", func() { }, } - typeNamespaceName := types.NamespacedName{Name: {{ .Resource.Kind }}Name, Namespace: {{ .Resource.Kind }}Name} + typeNamespaceName := types.NamespacedName{ + Name: {{ .Resource.Kind }}Name, + Namespace: {{ .Resource.Kind }}Name, + } {{ lower .Resource.Kind }} := &{{ .Resource.ImportAlias }}.{{ .Resource.Kind }}{} BeforeEach(func() { @@ -190,13 +194,20 @@ var _ = Describe("{{ .Resource.Kind }} controller", func() { By("Checking the latest Status Condition added to the {{ .Resource.Kind }} instance") Eventually(func() error { - if {{ lower .Resource.Kind }}.Status.Conditions != nil && len({{ lower .Resource.Kind }}.Status.Conditions) != 0 { + if {{ lower .Resource.Kind }}.Status.Conditions != nil && + len({{ lower .Resource.Kind }}.Status.Conditions) != 0 { latestStatusCondition := {{ lower .Resource.Kind }}.Status.Conditions[len({{ lower .Resource.Kind }}.Status.Conditions)-1] - expectedLatestStatusCondition := metav1.Condition{Type: typeAvailable{{ .Resource.Kind }}, - Status: metav1.ConditionTrue, Reason: "Reconciling", - Message: fmt.Sprintf("Deployment for custom resource (%s) with %d replicas created successfully", {{ lower .Resource.Kind }}.Name, {{ lower .Resource.Kind }}.Spec.Size)} + expectedLatestStatusCondition := metav1.Condition{ + Type: typeAvailable{{ .Resource.Kind }}, + Status: metav1.ConditionTrue, + Reason: "Reconciling", + Message: fmt.Sprintf( + "Deployment for custom resource (%s) with %d replicas created successfully", + {{ lower .Resource.Kind }}.Name, + {{ lower .Resource.Kind }}.Spec.Size), + } if latestStatusCondition != expectedLatestStatusCondition { - return fmt.Errorf("The latest status condition added to the {{ lower .Resource.Kind }} instance is not as expected") + return fmt.Errorf("The latest status condition added to the {{ .Resource.Kind }} instance is not as expected") } } return nil diff --git a/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go b/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go index 5284478c2b..d7e6f9262a 100644 --- a/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go +++ b/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go @@ -137,7 +137,6 @@ type {{ .Resource.Kind }}Reconciler struct { // Reconcile is part of the main kubernetes reconciliation loop which aims to // move the current state of the cluster closer to the desired state. - // It is essential for the controller's reconciliation loop to be idempotent. By following the Operator // pattern you will create Controllers which provide a reconcile function // responsible for synchronizing resources until the desired state is reached on the cluster. diff --git a/pkg/plugins/golang/v4/scaffolds/init.go b/pkg/plugins/golang/v4/scaffolds/init.go index fbd8032dff..637d036171 100644 --- a/pkg/plugins/golang/v4/scaffolds/init.go +++ b/pkg/plugins/golang/v4/scaffolds/init.go @@ -19,7 +19,6 @@ package scaffolds import ( log "github.com/sirupsen/logrus" "github.com/spf13/afero" - "sigs.k8s.io/kubebuilder/v3/pkg/config" "sigs.k8s.io/kubebuilder/v3/pkg/machinery" "sigs.k8s.io/kubebuilder/v3/pkg/plugin" @@ -139,5 +138,6 @@ func (s *initScaffolder) Scaffold() error { &templates.Dockerfile{}, &templates.DockerIgnore{}, &templates.Readme{}, + &templates.Golangci{}, ) } diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/api/webhook.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/api/webhook.go index bde82f8f5c..60ff9051a2 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/api/webhook.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/api/webhook.go @@ -98,6 +98,7 @@ import ( // log is for logging in this package. var {{ lower .Resource.Kind }}log = logf.Log.WithName("{{ lower .Resource.Kind }}-resource") +// SetupWebhookWithManager will setup the manager to manage the webhooks func (r *{{ .Resource.Kind }}) SetupWebhookWithManager(mgr ctrl.Manager) error { return ctrl.NewWebhookManagedBy(mgr). For(r). diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/api/webhook_suitetest.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/api/webhook_suitetest.go index ea9af73c68..e8e396deb1 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/api/webhook_suitetest.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/api/webhook_suitetest.go @@ -249,8 +249,7 @@ var _ = BeforeSuite(func() { if err != nil { return err } - conn.Close() - return nil + return conn.Close(); }).Should(Succeed()) }) diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/golangci.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/golangci.go new file mode 100644 index 0000000000..f6b263dc67 --- /dev/null +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/golangci.go @@ -0,0 +1,85 @@ +/* +Copyright 2022 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package templates + +import ( + "sigs.k8s.io/kubebuilder/v3/pkg/machinery" +) + +var _ machinery.Template = &Golangci{} + +// Golangci scaffolds a file which define Golangci rules +type Golangci struct { + machinery.TemplateMixin + machinery.ProjectNameMixin +} + +// SetTemplateDefaults implements file.Template +func (f *Golangci) SetTemplateDefaults() error { + if f.Path == "" { + f.Path = ".golangci.yml" + } + + f.TemplateBody = golangciTemplate + + f.IfExistsAction = machinery.SkipFile + + return nil +} + +//nolint:lll +const golangciTemplate = `run: + deadline: 5m + allow-parallel-runners: true + +issues: + # don't skip warning about doc comments + # don't exclude the default set of lint + exclude-use-default: false + # restore some of the defaults + # (fill in the rest as needed) + exclude-rules: + - path: "api/*" + linters: + - lll + - path: "internal/*" + linters: + - dupl + - lll +linters: + disable-all: true + enable: + - dupl + - errcheck + - exportloopref + - goconst + - gocyclo + - gofmt + - goimports + - gosimple + - govet + - ineffassign + - lll + - misspell + - nakedret + - prealloc + - staticcheck + - typecheck + - unconvert + - unparam + - unused +` diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go index 9ad9268c5e..28ffa442cb 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go @@ -128,6 +128,21 @@ vet: ## Run go vet against code. test: manifests generate fmt vet envtest ## Run tests. KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out +GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint +golangci-lint: + @[ -f $(GOLANGCI_LINT) ] || { \ + set -e ;\ + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) v1.54.2 ;\ + } + +.PHONY: lint +lint: golangci-lint ## Run golangci-lint linter & yamllint + $(GOLANGCI_LINT) run + +.PHONY: lint-fix +lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes + $(GOLANGCI_LINT) run --fix + ##@ Build .PHONY: build diff --git a/test/e2e/externalplugin/generate_test.go b/test/e2e/externalplugin/generate_test.go index fa49548568..cdd3933363 100644 --- a/test/e2e/externalplugin/generate_test.go +++ b/test/e2e/externalplugin/generate_test.go @@ -24,9 +24,6 @@ import ( //nolint:golint //nolint:revive . "github.com/onsi/ginkgo/v2" - - //nolint:golint - //nolint:revive . "github.com/onsi/gomega" //nolint:golint diff --git a/test/testdata/generate.sh b/test/testdata/generate.sh index a6f7a8f2d8..f37c007b63 100755 --- a/test/testdata/generate.sh +++ b/test/testdata/generate.sh @@ -126,7 +126,7 @@ function scaffold_test_project { make generate manifests rm -f go.sum - + go mod tidy popd } diff --git a/testdata/project-v4-multigroup/.golangci.yml b/testdata/project-v4-multigroup/.golangci.yml new file mode 100644 index 0000000000..aed8644d11 --- /dev/null +++ b/testdata/project-v4-multigroup/.golangci.yml @@ -0,0 +1,40 @@ +run: + deadline: 5m + allow-parallel-runners: true + +issues: + # don't skip warning about doc comments + # don't exclude the default set of lint + exclude-use-default: false + # restore some of the defaults + # (fill in the rest as needed) + exclude-rules: + - path: "api/*" + linters: + - lll + - path: "internal/*" + linters: + - dupl + - lll +linters: + disable-all: true + enable: + - dupl + - errcheck + - exportloopref + - goconst + - gocyclo + - gofmt + - goimports + - gosimple + - govet + - ineffassign + - lll + - misspell + - nakedret + - prealloc + - staticcheck + - typecheck + - unconvert + - unparam + - unused diff --git a/testdata/project-v4-multigroup/Makefile b/testdata/project-v4-multigroup/Makefile index 751cdd7716..fc949b7f47 100644 --- a/testdata/project-v4-multigroup/Makefile +++ b/testdata/project-v4-multigroup/Makefile @@ -64,6 +64,21 @@ vet: ## Run go vet against code. test: manifests generate fmt vet envtest ## Run tests. KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out +GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint +golangci-lint: + @[ -f $(GOLANGCI_LINT) ] || { \ + set -e ;\ + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) v1.54.2 ;\ + } + +.PHONY: lint +lint: golangci-lint ## Run golangci-lint linter & yamllint + $(GOLANGCI_LINT) run + +.PHONY: lint-fix +lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes + $(GOLANGCI_LINT) run --fix + ##@ Build .PHONY: build diff --git a/testdata/project-v4-multigroup/api/crew/v1/captain_webhook.go b/testdata/project-v4-multigroup/api/crew/v1/captain_webhook.go index 7948f0387a..ed99f7f0e5 100644 --- a/testdata/project-v4-multigroup/api/crew/v1/captain_webhook.go +++ b/testdata/project-v4-multigroup/api/crew/v1/captain_webhook.go @@ -27,6 +27,7 @@ import ( // log is for logging in this package. var captainlog = logf.Log.WithName("captain-resource") +// SetupWebhookWithManager will setup the manager to manage the webhooks func (r *Captain) SetupWebhookWithManager(mgr ctrl.Manager) error { return ctrl.NewWebhookManagedBy(mgr). For(r). diff --git a/testdata/project-v4-multigroup/api/crew/v1/webhook_suite_test.go b/testdata/project-v4-multigroup/api/crew/v1/webhook_suite_test.go index fb0518a665..d58a13812d 100644 --- a/testdata/project-v4-multigroup/api/crew/v1/webhook_suite_test.go +++ b/testdata/project-v4-multigroup/api/crew/v1/webhook_suite_test.go @@ -132,8 +132,7 @@ var _ = BeforeSuite(func() { if err != nil { return err } - conn.Close() - return nil + return conn.Close() }).Should(Succeed()) }) diff --git a/testdata/project-v4-multigroup/api/example.com/v1alpha1/memcached_webhook.go b/testdata/project-v4-multigroup/api/example.com/v1alpha1/memcached_webhook.go index 9dde8721ab..77993bc8d5 100644 --- a/testdata/project-v4-multigroup/api/example.com/v1alpha1/memcached_webhook.go +++ b/testdata/project-v4-multigroup/api/example.com/v1alpha1/memcached_webhook.go @@ -27,6 +27,7 @@ import ( // log is for logging in this package. var memcachedlog = logf.Log.WithName("memcached-resource") +// SetupWebhookWithManager will setup the manager to manage the webhooks func (r *Memcached) SetupWebhookWithManager(mgr ctrl.Manager) error { return ctrl.NewWebhookManagedBy(mgr). For(r). diff --git a/testdata/project-v4-multigroup/api/example.com/v1alpha1/webhook_suite_test.go b/testdata/project-v4-multigroup/api/example.com/v1alpha1/webhook_suite_test.go index 3fbb781f9f..17d019e74f 100644 --- a/testdata/project-v4-multigroup/api/example.com/v1alpha1/webhook_suite_test.go +++ b/testdata/project-v4-multigroup/api/example.com/v1alpha1/webhook_suite_test.go @@ -132,8 +132,7 @@ var _ = BeforeSuite(func() { if err != nil { return err } - conn.Close() - return nil + return conn.Close() }).Should(Succeed()) }) diff --git a/testdata/project-v4-multigroup/api/ship/v1/destroyer_webhook.go b/testdata/project-v4-multigroup/api/ship/v1/destroyer_webhook.go index 67798c6e1f..4b0fb739d5 100644 --- a/testdata/project-v4-multigroup/api/ship/v1/destroyer_webhook.go +++ b/testdata/project-v4-multigroup/api/ship/v1/destroyer_webhook.go @@ -25,6 +25,7 @@ import ( // log is for logging in this package. var destroyerlog = logf.Log.WithName("destroyer-resource") +// SetupWebhookWithManager will setup the manager to manage the webhooks func (r *Destroyer) SetupWebhookWithManager(mgr ctrl.Manager) error { return ctrl.NewWebhookManagedBy(mgr). For(r). diff --git a/testdata/project-v4-multigroup/api/ship/v1/webhook_suite_test.go b/testdata/project-v4-multigroup/api/ship/v1/webhook_suite_test.go index fd04fa6392..1c6bb164c5 100644 --- a/testdata/project-v4-multigroup/api/ship/v1/webhook_suite_test.go +++ b/testdata/project-v4-multigroup/api/ship/v1/webhook_suite_test.go @@ -132,8 +132,7 @@ var _ = BeforeSuite(func() { if err != nil { return err } - conn.Close() - return nil + return conn.Close() }).Should(Succeed()) }) diff --git a/testdata/project-v4-multigroup/api/ship/v1beta1/frigate_webhook.go b/testdata/project-v4-multigroup/api/ship/v1beta1/frigate_webhook.go index 028189c9ea..e03bafd22b 100644 --- a/testdata/project-v4-multigroup/api/ship/v1beta1/frigate_webhook.go +++ b/testdata/project-v4-multigroup/api/ship/v1beta1/frigate_webhook.go @@ -24,6 +24,7 @@ import ( // log is for logging in this package. var frigatelog = logf.Log.WithName("frigate-resource") +// SetupWebhookWithManager will setup the manager to manage the webhooks func (r *Frigate) SetupWebhookWithManager(mgr ctrl.Manager) error { return ctrl.NewWebhookManagedBy(mgr). For(r). diff --git a/testdata/project-v4-multigroup/api/ship/v2alpha1/cruiser_webhook.go b/testdata/project-v4-multigroup/api/ship/v2alpha1/cruiser_webhook.go index 030b693764..14d5710a83 100644 --- a/testdata/project-v4-multigroup/api/ship/v2alpha1/cruiser_webhook.go +++ b/testdata/project-v4-multigroup/api/ship/v2alpha1/cruiser_webhook.go @@ -27,6 +27,7 @@ import ( // log is for logging in this package. var cruiserlog = logf.Log.WithName("cruiser-resource") +// SetupWebhookWithManager will setup the manager to manage the webhooks func (r *Cruiser) SetupWebhookWithManager(mgr ctrl.Manager) error { return ctrl.NewWebhookManagedBy(mgr). For(r). diff --git a/testdata/project-v4-multigroup/api/ship/v2alpha1/webhook_suite_test.go b/testdata/project-v4-multigroup/api/ship/v2alpha1/webhook_suite_test.go index 8f37bf1ee3..38482d55ee 100644 --- a/testdata/project-v4-multigroup/api/ship/v2alpha1/webhook_suite_test.go +++ b/testdata/project-v4-multigroup/api/ship/v2alpha1/webhook_suite_test.go @@ -132,8 +132,7 @@ var _ = BeforeSuite(func() { if err != nil { return err } - conn.Close() - return nil + return conn.Close() }).Should(Succeed()) }) diff --git a/testdata/project-v4-multigroup/api/v1/lakers_webhook.go b/testdata/project-v4-multigroup/api/v1/lakers_webhook.go index f1b3ac61a9..26041fdfc7 100644 --- a/testdata/project-v4-multigroup/api/v1/lakers_webhook.go +++ b/testdata/project-v4-multigroup/api/v1/lakers_webhook.go @@ -27,6 +27,7 @@ import ( // log is for logging in this package. var lakerslog = logf.Log.WithName("lakers-resource") +// SetupWebhookWithManager will setup the manager to manage the webhooks func (r *Lakers) SetupWebhookWithManager(mgr ctrl.Manager) error { return ctrl.NewWebhookManagedBy(mgr). For(r). diff --git a/testdata/project-v4-multigroup/api/v1/webhook_suite_test.go b/testdata/project-v4-multigroup/api/v1/webhook_suite_test.go index 5a88f849ef..250b42b87b 100644 --- a/testdata/project-v4-multigroup/api/v1/webhook_suite_test.go +++ b/testdata/project-v4-multigroup/api/v1/webhook_suite_test.go @@ -132,8 +132,7 @@ var _ = BeforeSuite(func() { if err != nil { return err } - conn.Close() - return nil + return conn.Close() }).Should(Succeed()) }) diff --git a/testdata/project-v4-multigroup/internal/controller/example.com/busybox_controller.go b/testdata/project-v4-multigroup/internal/controller/example.com/busybox_controller.go index ce28994612..65756ff8f5 100644 --- a/testdata/project-v4-multigroup/internal/controller/example.com/busybox_controller.go +++ b/testdata/project-v4-multigroup/internal/controller/example.com/busybox_controller.go @@ -69,7 +69,6 @@ type BusyboxReconciler struct { // Reconcile is part of the main kubernetes reconciliation loop which aims to // move the current state of the cluster closer to the desired state. - // It is essential for the controller's reconciliation loop to be idempotent. By following the Operator // pattern you will create Controllers which provide a reconcile function // responsible for synchronizing resources until the desired state is reached on the cluster. diff --git a/testdata/project-v4-multigroup/internal/controller/example.com/busybox_controller_test.go b/testdata/project-v4-multigroup/internal/controller/example.com/busybox_controller_test.go index 0a3496134d..1d06b715f8 100644 --- a/testdata/project-v4-multigroup/internal/controller/example.com/busybox_controller_test.go +++ b/testdata/project-v4-multigroup/internal/controller/example.com/busybox_controller_test.go @@ -22,6 +22,7 @@ import ( "os" "time" + //nolint:golint . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" appsv1 "k8s.io/api/apps/v1" @@ -48,7 +49,10 @@ var _ = Describe("Busybox controller", func() { }, } - typeNamespaceName := types.NamespacedName{Name: BusyboxName, Namespace: BusyboxName} + typeNamespaceName := types.NamespacedName{ + Name: BusyboxName, + Namespace: BusyboxName, + } busybox := &examplecomv1alpha1.Busybox{} BeforeEach(func() { @@ -126,13 +130,20 @@ var _ = Describe("Busybox controller", func() { By("Checking the latest Status Condition added to the Busybox instance") Eventually(func() error { - if busybox.Status.Conditions != nil && len(busybox.Status.Conditions) != 0 { + if busybox.Status.Conditions != nil && + len(busybox.Status.Conditions) != 0 { latestStatusCondition := busybox.Status.Conditions[len(busybox.Status.Conditions)-1] - expectedLatestStatusCondition := metav1.Condition{Type: typeAvailableBusybox, - Status: metav1.ConditionTrue, Reason: "Reconciling", - Message: fmt.Sprintf("Deployment for custom resource (%s) with %d replicas created successfully", busybox.Name, busybox.Spec.Size)} + expectedLatestStatusCondition := metav1.Condition{ + Type: typeAvailableBusybox, + Status: metav1.ConditionTrue, + Reason: "Reconciling", + Message: fmt.Sprintf( + "Deployment for custom resource (%s) with %d replicas created successfully", + busybox.Name, + busybox.Spec.Size), + } if latestStatusCondition != expectedLatestStatusCondition { - return fmt.Errorf("The latest status condition added to the busybox instance is not as expected") + return fmt.Errorf("The latest status condition added to the Busybox instance is not as expected") } } return nil diff --git a/testdata/project-v4-multigroup/internal/controller/example.com/memcached_controller.go b/testdata/project-v4-multigroup/internal/controller/example.com/memcached_controller.go index 9dd0faa9c7..b17cbe0147 100644 --- a/testdata/project-v4-multigroup/internal/controller/example.com/memcached_controller.go +++ b/testdata/project-v4-multigroup/internal/controller/example.com/memcached_controller.go @@ -69,7 +69,6 @@ type MemcachedReconciler struct { // Reconcile is part of the main kubernetes reconciliation loop which aims to // move the current state of the cluster closer to the desired state. - // It is essential for the controller's reconciliation loop to be idempotent. By following the Operator // pattern you will create Controllers which provide a reconcile function // responsible for synchronizing resources until the desired state is reached on the cluster. diff --git a/testdata/project-v4-multigroup/internal/controller/example.com/memcached_controller_test.go b/testdata/project-v4-multigroup/internal/controller/example.com/memcached_controller_test.go index f96146c9b7..920db20dd0 100644 --- a/testdata/project-v4-multigroup/internal/controller/example.com/memcached_controller_test.go +++ b/testdata/project-v4-multigroup/internal/controller/example.com/memcached_controller_test.go @@ -22,6 +22,7 @@ import ( "os" "time" + //nolint:golint . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" appsv1 "k8s.io/api/apps/v1" @@ -48,7 +49,10 @@ var _ = Describe("Memcached controller", func() { }, } - typeNamespaceName := types.NamespacedName{Name: MemcachedName, Namespace: MemcachedName} + typeNamespaceName := types.NamespacedName{ + Name: MemcachedName, + Namespace: MemcachedName, + } memcached := &examplecomv1alpha1.Memcached{} BeforeEach(func() { @@ -127,13 +131,20 @@ var _ = Describe("Memcached controller", func() { By("Checking the latest Status Condition added to the Memcached instance") Eventually(func() error { - if memcached.Status.Conditions != nil && len(memcached.Status.Conditions) != 0 { + if memcached.Status.Conditions != nil && + len(memcached.Status.Conditions) != 0 { latestStatusCondition := memcached.Status.Conditions[len(memcached.Status.Conditions)-1] - expectedLatestStatusCondition := metav1.Condition{Type: typeAvailableMemcached, - Status: metav1.ConditionTrue, Reason: "Reconciling", - Message: fmt.Sprintf("Deployment for custom resource (%s) with %d replicas created successfully", memcached.Name, memcached.Spec.Size)} + expectedLatestStatusCondition := metav1.Condition{ + Type: typeAvailableMemcached, + Status: metav1.ConditionTrue, + Reason: "Reconciling", + Message: fmt.Sprintf( + "Deployment for custom resource (%s) with %d replicas created successfully", + memcached.Name, + memcached.Spec.Size), + } if latestStatusCondition != expectedLatestStatusCondition { - return fmt.Errorf("The latest status condition added to the memcached instance is not as expected") + return fmt.Errorf("The latest status condition added to the Memcached instance is not as expected") } } return nil diff --git a/testdata/project-v4-with-deploy-image/.golangci.yml b/testdata/project-v4-with-deploy-image/.golangci.yml new file mode 100644 index 0000000000..aed8644d11 --- /dev/null +++ b/testdata/project-v4-with-deploy-image/.golangci.yml @@ -0,0 +1,40 @@ +run: + deadline: 5m + allow-parallel-runners: true + +issues: + # don't skip warning about doc comments + # don't exclude the default set of lint + exclude-use-default: false + # restore some of the defaults + # (fill in the rest as needed) + exclude-rules: + - path: "api/*" + linters: + - lll + - path: "internal/*" + linters: + - dupl + - lll +linters: + disable-all: true + enable: + - dupl + - errcheck + - exportloopref + - goconst + - gocyclo + - gofmt + - goimports + - gosimple + - govet + - ineffassign + - lll + - misspell + - nakedret + - prealloc + - staticcheck + - typecheck + - unconvert + - unparam + - unused diff --git a/testdata/project-v4-with-deploy-image/Makefile b/testdata/project-v4-with-deploy-image/Makefile index 751cdd7716..fc949b7f47 100644 --- a/testdata/project-v4-with-deploy-image/Makefile +++ b/testdata/project-v4-with-deploy-image/Makefile @@ -64,6 +64,21 @@ vet: ## Run go vet against code. test: manifests generate fmt vet envtest ## Run tests. KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out +GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint +golangci-lint: + @[ -f $(GOLANGCI_LINT) ] || { \ + set -e ;\ + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) v1.54.2 ;\ + } + +.PHONY: lint +lint: golangci-lint ## Run golangci-lint linter & yamllint + $(GOLANGCI_LINT) run + +.PHONY: lint-fix +lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes + $(GOLANGCI_LINT) run --fix + ##@ Build .PHONY: build diff --git a/testdata/project-v4-with-deploy-image/api/v1alpha1/memcached_webhook.go b/testdata/project-v4-with-deploy-image/api/v1alpha1/memcached_webhook.go index 9dde8721ab..77993bc8d5 100644 --- a/testdata/project-v4-with-deploy-image/api/v1alpha1/memcached_webhook.go +++ b/testdata/project-v4-with-deploy-image/api/v1alpha1/memcached_webhook.go @@ -27,6 +27,7 @@ import ( // log is for logging in this package. var memcachedlog = logf.Log.WithName("memcached-resource") +// SetupWebhookWithManager will setup the manager to manage the webhooks func (r *Memcached) SetupWebhookWithManager(mgr ctrl.Manager) error { return ctrl.NewWebhookManagedBy(mgr). For(r). diff --git a/testdata/project-v4-with-deploy-image/api/v1alpha1/webhook_suite_test.go b/testdata/project-v4-with-deploy-image/api/v1alpha1/webhook_suite_test.go index ad362da301..d1abc45a29 100644 --- a/testdata/project-v4-with-deploy-image/api/v1alpha1/webhook_suite_test.go +++ b/testdata/project-v4-with-deploy-image/api/v1alpha1/webhook_suite_test.go @@ -132,8 +132,7 @@ var _ = BeforeSuite(func() { if err != nil { return err } - conn.Close() - return nil + return conn.Close() }).Should(Succeed()) }) diff --git a/testdata/project-v4-with-deploy-image/internal/controller/busybox_controller.go b/testdata/project-v4-with-deploy-image/internal/controller/busybox_controller.go index ca6cce659e..12f6de5afc 100644 --- a/testdata/project-v4-with-deploy-image/internal/controller/busybox_controller.go +++ b/testdata/project-v4-with-deploy-image/internal/controller/busybox_controller.go @@ -69,7 +69,6 @@ type BusyboxReconciler struct { // Reconcile is part of the main kubernetes reconciliation loop which aims to // move the current state of the cluster closer to the desired state. - // It is essential for the controller's reconciliation loop to be idempotent. By following the Operator // pattern you will create Controllers which provide a reconcile function // responsible for synchronizing resources until the desired state is reached on the cluster. diff --git a/testdata/project-v4-with-deploy-image/internal/controller/busybox_controller_test.go b/testdata/project-v4-with-deploy-image/internal/controller/busybox_controller_test.go index 146c380873..e3aeacd719 100644 --- a/testdata/project-v4-with-deploy-image/internal/controller/busybox_controller_test.go +++ b/testdata/project-v4-with-deploy-image/internal/controller/busybox_controller_test.go @@ -22,6 +22,7 @@ import ( "os" "time" + //nolint:golint . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" appsv1 "k8s.io/api/apps/v1" @@ -48,7 +49,10 @@ var _ = Describe("Busybox controller", func() { }, } - typeNamespaceName := types.NamespacedName{Name: BusyboxName, Namespace: BusyboxName} + typeNamespaceName := types.NamespacedName{ + Name: BusyboxName, + Namespace: BusyboxName, + } busybox := &examplecomv1alpha1.Busybox{} BeforeEach(func() { @@ -126,13 +130,20 @@ var _ = Describe("Busybox controller", func() { By("Checking the latest Status Condition added to the Busybox instance") Eventually(func() error { - if busybox.Status.Conditions != nil && len(busybox.Status.Conditions) != 0 { + if busybox.Status.Conditions != nil && + len(busybox.Status.Conditions) != 0 { latestStatusCondition := busybox.Status.Conditions[len(busybox.Status.Conditions)-1] - expectedLatestStatusCondition := metav1.Condition{Type: typeAvailableBusybox, - Status: metav1.ConditionTrue, Reason: "Reconciling", - Message: fmt.Sprintf("Deployment for custom resource (%s) with %d replicas created successfully", busybox.Name, busybox.Spec.Size)} + expectedLatestStatusCondition := metav1.Condition{ + Type: typeAvailableBusybox, + Status: metav1.ConditionTrue, + Reason: "Reconciling", + Message: fmt.Sprintf( + "Deployment for custom resource (%s) with %d replicas created successfully", + busybox.Name, + busybox.Spec.Size), + } if latestStatusCondition != expectedLatestStatusCondition { - return fmt.Errorf("The latest status condition added to the busybox instance is not as expected") + return fmt.Errorf("The latest status condition added to the Busybox instance is not as expected") } } return nil diff --git a/testdata/project-v4-with-deploy-image/internal/controller/memcached_controller.go b/testdata/project-v4-with-deploy-image/internal/controller/memcached_controller.go index d602cc8619..fb09c3095f 100644 --- a/testdata/project-v4-with-deploy-image/internal/controller/memcached_controller.go +++ b/testdata/project-v4-with-deploy-image/internal/controller/memcached_controller.go @@ -69,7 +69,6 @@ type MemcachedReconciler struct { // Reconcile is part of the main kubernetes reconciliation loop which aims to // move the current state of the cluster closer to the desired state. - // It is essential for the controller's reconciliation loop to be idempotent. By following the Operator // pattern you will create Controllers which provide a reconcile function // responsible for synchronizing resources until the desired state is reached on the cluster. diff --git a/testdata/project-v4-with-deploy-image/internal/controller/memcached_controller_test.go b/testdata/project-v4-with-deploy-image/internal/controller/memcached_controller_test.go index 38e270374a..00f8e7828d 100644 --- a/testdata/project-v4-with-deploy-image/internal/controller/memcached_controller_test.go +++ b/testdata/project-v4-with-deploy-image/internal/controller/memcached_controller_test.go @@ -22,6 +22,7 @@ import ( "os" "time" + //nolint:golint . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" appsv1 "k8s.io/api/apps/v1" @@ -48,7 +49,10 @@ var _ = Describe("Memcached controller", func() { }, } - typeNamespaceName := types.NamespacedName{Name: MemcachedName, Namespace: MemcachedName} + typeNamespaceName := types.NamespacedName{ + Name: MemcachedName, + Namespace: MemcachedName, + } memcached := &examplecomv1alpha1.Memcached{} BeforeEach(func() { @@ -127,13 +131,20 @@ var _ = Describe("Memcached controller", func() { By("Checking the latest Status Condition added to the Memcached instance") Eventually(func() error { - if memcached.Status.Conditions != nil && len(memcached.Status.Conditions) != 0 { + if memcached.Status.Conditions != nil && + len(memcached.Status.Conditions) != 0 { latestStatusCondition := memcached.Status.Conditions[len(memcached.Status.Conditions)-1] - expectedLatestStatusCondition := metav1.Condition{Type: typeAvailableMemcached, - Status: metav1.ConditionTrue, Reason: "Reconciling", - Message: fmt.Sprintf("Deployment for custom resource (%s) with %d replicas created successfully", memcached.Name, memcached.Spec.Size)} + expectedLatestStatusCondition := metav1.Condition{ + Type: typeAvailableMemcached, + Status: metav1.ConditionTrue, + Reason: "Reconciling", + Message: fmt.Sprintf( + "Deployment for custom resource (%s) with %d replicas created successfully", + memcached.Name, + memcached.Spec.Size), + } if latestStatusCondition != expectedLatestStatusCondition { - return fmt.Errorf("The latest status condition added to the memcached instance is not as expected") + return fmt.Errorf("The latest status condition added to the Memcached instance is not as expected") } } return nil diff --git a/testdata/project-v4-with-grafana/.golangci.yml b/testdata/project-v4-with-grafana/.golangci.yml new file mode 100644 index 0000000000..aed8644d11 --- /dev/null +++ b/testdata/project-v4-with-grafana/.golangci.yml @@ -0,0 +1,40 @@ +run: + deadline: 5m + allow-parallel-runners: true + +issues: + # don't skip warning about doc comments + # don't exclude the default set of lint + exclude-use-default: false + # restore some of the defaults + # (fill in the rest as needed) + exclude-rules: + - path: "api/*" + linters: + - lll + - path: "internal/*" + linters: + - dupl + - lll +linters: + disable-all: true + enable: + - dupl + - errcheck + - exportloopref + - goconst + - gocyclo + - gofmt + - goimports + - gosimple + - govet + - ineffassign + - lll + - misspell + - nakedret + - prealloc + - staticcheck + - typecheck + - unconvert + - unparam + - unused diff --git a/testdata/project-v4-with-grafana/Makefile b/testdata/project-v4-with-grafana/Makefile index 751cdd7716..fc949b7f47 100644 --- a/testdata/project-v4-with-grafana/Makefile +++ b/testdata/project-v4-with-grafana/Makefile @@ -64,6 +64,21 @@ vet: ## Run go vet against code. test: manifests generate fmt vet envtest ## Run tests. KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out +GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint +golangci-lint: + @[ -f $(GOLANGCI_LINT) ] || { \ + set -e ;\ + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) v1.54.2 ;\ + } + +.PHONY: lint +lint: golangci-lint ## Run golangci-lint linter & yamllint + $(GOLANGCI_LINT) run + +.PHONY: lint-fix +lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes + $(GOLANGCI_LINT) run --fix + ##@ Build .PHONY: build diff --git a/testdata/project-v4/.golangci.yml b/testdata/project-v4/.golangci.yml new file mode 100644 index 0000000000..aed8644d11 --- /dev/null +++ b/testdata/project-v4/.golangci.yml @@ -0,0 +1,40 @@ +run: + deadline: 5m + allow-parallel-runners: true + +issues: + # don't skip warning about doc comments + # don't exclude the default set of lint + exclude-use-default: false + # restore some of the defaults + # (fill in the rest as needed) + exclude-rules: + - path: "api/*" + linters: + - lll + - path: "internal/*" + linters: + - dupl + - lll +linters: + disable-all: true + enable: + - dupl + - errcheck + - exportloopref + - goconst + - gocyclo + - gofmt + - goimports + - gosimple + - govet + - ineffassign + - lll + - misspell + - nakedret + - prealloc + - staticcheck + - typecheck + - unconvert + - unparam + - unused diff --git a/testdata/project-v4/Makefile b/testdata/project-v4/Makefile index 751cdd7716..fc949b7f47 100644 --- a/testdata/project-v4/Makefile +++ b/testdata/project-v4/Makefile @@ -64,6 +64,21 @@ vet: ## Run go vet against code. test: manifests generate fmt vet envtest ## Run tests. KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out +GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint +golangci-lint: + @[ -f $(GOLANGCI_LINT) ] || { \ + set -e ;\ + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) v1.54.2 ;\ + } + +.PHONY: lint +lint: golangci-lint ## Run golangci-lint linter & yamllint + $(GOLANGCI_LINT) run + +.PHONY: lint-fix +lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes + $(GOLANGCI_LINT) run --fix + ##@ Build .PHONY: build diff --git a/testdata/project-v4/api/v1/admiral_webhook.go b/testdata/project-v4/api/v1/admiral_webhook.go index b809f0feb0..26b2c9f44c 100644 --- a/testdata/project-v4/api/v1/admiral_webhook.go +++ b/testdata/project-v4/api/v1/admiral_webhook.go @@ -25,6 +25,7 @@ import ( // log is for logging in this package. var admirallog = logf.Log.WithName("admiral-resource") +// SetupWebhookWithManager will setup the manager to manage the webhooks func (r *Admiral) SetupWebhookWithManager(mgr ctrl.Manager) error { return ctrl.NewWebhookManagedBy(mgr). For(r). diff --git a/testdata/project-v4/api/v1/captain_webhook.go b/testdata/project-v4/api/v1/captain_webhook.go index 7948f0387a..ed99f7f0e5 100644 --- a/testdata/project-v4/api/v1/captain_webhook.go +++ b/testdata/project-v4/api/v1/captain_webhook.go @@ -27,6 +27,7 @@ import ( // log is for logging in this package. var captainlog = logf.Log.WithName("captain-resource") +// SetupWebhookWithManager will setup the manager to manage the webhooks func (r *Captain) SetupWebhookWithManager(mgr ctrl.Manager) error { return ctrl.NewWebhookManagedBy(mgr). For(r). diff --git a/testdata/project-v4/api/v1/firstmate_webhook.go b/testdata/project-v4/api/v1/firstmate_webhook.go index 941a86ed45..fda2900739 100644 --- a/testdata/project-v4/api/v1/firstmate_webhook.go +++ b/testdata/project-v4/api/v1/firstmate_webhook.go @@ -24,6 +24,7 @@ import ( // log is for logging in this package. var firstmatelog = logf.Log.WithName("firstmate-resource") +// SetupWebhookWithManager will setup the manager to manage the webhooks func (r *FirstMate) SetupWebhookWithManager(mgr ctrl.Manager) error { return ctrl.NewWebhookManagedBy(mgr). For(r). diff --git a/testdata/project-v4/api/v1/webhook_suite_test.go b/testdata/project-v4/api/v1/webhook_suite_test.go index bd1f7f7581..f15fd5f894 100644 --- a/testdata/project-v4/api/v1/webhook_suite_test.go +++ b/testdata/project-v4/api/v1/webhook_suite_test.go @@ -135,8 +135,7 @@ var _ = BeforeSuite(func() { if err != nil { return err } - conn.Close() - return nil + return conn.Close() }).Should(Succeed()) })