From fdb273ef253ecf53de6fb76bb31e22dc5dcad3da Mon Sep 17 00:00:00 2001 From: "Kiss, Tibor" Date: Wed, 28 Feb 2024 10:45:38 +0100 Subject: [PATCH 01/12] Linter: bodyclose --- .golangci.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.golangci.yaml b/.golangci.yaml index 01862e55..d253c2bd 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -38,7 +38,6 @@ linters: - gomoddirectives - funlen - testifylint - - bodyclose - containedctx - thelper - tagliatelle From 738ab2e3eb6408e5e7c2ad80c45e123c68131bea Mon Sep 17 00:00:00 2001 From: "Kiss, Tibor" Date: Wed, 28 Feb 2024 12:00:38 +0100 Subject: [PATCH 02/12] Linter: gci --- .golangci.yaml | 1 - cmd/main.go | 21 +++++++------- e2e/common/fixtures/fixtures.go | 5 ++-- e2e/common/k8s.go | 3 +- internal/controller/cache/cache.go | 3 +- internal/controller/nats/controller.go | 10 +++---- internal/controller/nats/deprovisioner.go | 9 +++--- .../controller/nats/deprovisioner_test.go | 10 +++---- .../controller/integration_test.go | 15 ++++------ .../validation/integration_test.go | 10 +++---- internal/controller/nats/provisioner.go | 7 ++--- internal/controller/nats/provisioner_test.go | 3 +- internal/controller/nats/status_test.go | 9 +++--- internal/controller/nats/unit_test.go | 9 ++---- pkg/k8s/chart/helmrenderer_test.go | 6 ++-- pkg/k8s/chart/releaseinstance.go | 3 +- pkg/k8s/chart/releaseinstance_test.go | 3 +- pkg/k8s/client.go | 5 ++-- pkg/manager/nats.go | 3 +- pkg/manager/overrides_test.go | 5 ++-- testutils/integration/integration.go | 28 ++++++++----------- testutils/matchers/nats/matchers.go | 3 +- testutils/options.go | 6 ++-- testutils/utils.go | 8 ++---- 24 files changed, 74 insertions(+), 111 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index d253c2bd..255d5961 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -32,7 +32,6 @@ linters: - unconvert - varnamelen - wrapcheck - - gci - tagalign - dupword - gomoddirectives diff --git a/cmd/main.go b/cmd/main.go index dc3805dc..c53b86fe 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -20,10 +20,13 @@ import ( "flag" "os" - // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.) - // to ensure that exec-entrypoint and run can make use of them. - _ "k8s.io/client-go/plugin/pkg/client/auth" - + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + nmctrlcache "github.com/kyma-project/nats-manager/internal/controller/cache" + nmctrl "github.com/kyma-project/nats-manager/internal/controller/nats" + "github.com/kyma-project/nats-manager/pkg/env" + "github.com/kyma-project/nats-manager/pkg/k8s" + "github.com/kyma-project/nats-manager/pkg/k8s/chart" + nmmgr "github.com/kyma-project/nats-manager/pkg/manager" "go.uber.org/zap" "go.uber.org/zap/zapcore" kapiextclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" @@ -37,13 +40,9 @@ import ( "sigs.k8s.io/controller-runtime/pkg/metrics/server" "sigs.k8s.io/controller-runtime/pkg/webhook" - nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" - nmctrlcache "github.com/kyma-project/nats-manager/internal/controller/cache" - nmctrl "github.com/kyma-project/nats-manager/internal/controller/nats" - "github.com/kyma-project/nats-manager/pkg/env" - "github.com/kyma-project/nats-manager/pkg/k8s" - "github.com/kyma-project/nats-manager/pkg/k8s/chart" - nmmgr "github.com/kyma-project/nats-manager/pkg/manager" + // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.) + // to ensure that exec-entrypoint and run can make use of them. + _ "k8s.io/client-go/plugin/pkg/client/auth" ) const defaultMetricsPort = 9443 diff --git a/e2e/common/fixtures/fixtures.go b/e2e/common/fixtures/fixtures.go index e455dad6..bcd821da 100644 --- a/e2e/common/fixtures/fixtures.go +++ b/e2e/common/fixtures/fixtures.go @@ -1,12 +1,11 @@ package fixtures import ( + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + "github.com/kyma-project/nats-manager/testutils" kcorev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" - "github.com/kyma-project/nats-manager/testutils" ) const ( diff --git a/e2e/common/k8s.go b/e2e/common/k8s.go index 0dd542ee..fc4ce00e 100644 --- a/e2e/common/k8s.go +++ b/e2e/common/k8s.go @@ -4,13 +4,12 @@ import ( "os" "path/filepath" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" "k8s.io/client-go/kubernetes" kscheme "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" "sigs.k8s.io/controller-runtime/pkg/client" - - nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" ) func GetK8sClients() (*kubernetes.Clientset, client.Client, error) { diff --git a/internal/controller/cache/cache.go b/internal/controller/cache/cache.go index a5188ec6..3680ec18 100644 --- a/internal/controller/cache/cache.go +++ b/internal/controller/cache/cache.go @@ -1,6 +1,7 @@ package cache import ( + nmlabels "github.com/kyma-project/nats-manager/pkg/labels" kappsv1 "k8s.io/api/apps/v1" kautoscalingv1 "k8s.io/api/autoscaling/v1" kcorev1 "k8s.io/api/core/v1" @@ -10,8 +11,6 @@ import ( "k8s.io/client-go/rest" "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/client" - - nmlabels "github.com/kyma-project/nats-manager/pkg/labels" ) // New returns a cache with the cache-options applied, generade form the rest-config. diff --git a/internal/controller/nats/controller.go b/internal/controller/nats/controller.go index a230ce28..10bd4adb 100644 --- a/internal/controller/nats/controller.go +++ b/internal/controller/nats/controller.go @@ -20,9 +20,12 @@ import ( "context" "fmt" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" "github.com/kyma-project/nats-manager/pkg/events" + "github.com/kyma-project/nats-manager/pkg/k8s" + "github.com/kyma-project/nats-manager/pkg/k8s/chart" + nmmgr "github.com/kyma-project/nats-manager/pkg/manager" nmnats "github.com/kyma-project/nats-manager/pkg/nats" - "go.uber.org/zap" kappsv1 "k8s.io/api/apps/v1" kcorev1 "k8s.io/api/core/v1" @@ -34,11 +37,6 @@ import ( kcontrollerruntime "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" - - nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" - "github.com/kyma-project/nats-manager/pkg/k8s" - "github.com/kyma-project/nats-manager/pkg/k8s/chart" - nmmgr "github.com/kyma-project/nats-manager/pkg/manager" ) const ( diff --git a/internal/controller/nats/deprovisioner.go b/internal/controller/nats/deprovisioner.go index 471ffba5..59cd3fd8 100644 --- a/internal/controller/nats/deprovisioner.go +++ b/internal/controller/nats/deprovisioner.go @@ -4,15 +4,14 @@ import ( "context" "fmt" - "go.uber.org/zap" - kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - kcontrollerruntime "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/client" - nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" nmctrlurl "github.com/kyma-project/nats-manager/internal/controller/nats/url" "github.com/kyma-project/nats-manager/pkg/events" nmnats "github.com/kyma-project/nats-manager/pkg/nats" + "go.uber.org/zap" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kcontrollerruntime "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" ) const ( diff --git a/internal/controller/nats/deprovisioner_test.go b/internal/controller/nats/deprovisioner_test.go index 5554f73d..77beef69 100644 --- a/internal/controller/nats/deprovisioner_test.go +++ b/internal/controller/nats/deprovisioner_test.go @@ -6,19 +6,17 @@ import ( "fmt" "testing" - nmnats "github.com/kyma-project/nats-manager/pkg/nats" - "go.uber.org/zap" - - nmmgr "github.com/kyma-project/nats-manager/pkg/manager" - "github.com/kyma-project/nats-manager/pkg/nats/mocks" - nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" "github.com/kyma-project/nats-manager/pkg/k8s/chart" nmkmocks "github.com/kyma-project/nats-manager/pkg/k8s/mocks" + nmmgr "github.com/kyma-project/nats-manager/pkg/manager" + nmnats "github.com/kyma-project/nats-manager/pkg/nats" + "github.com/kyma-project/nats-manager/pkg/nats/mocks" "github.com/kyma-project/nats-manager/testutils" natsgo "github.com/nats-io/nats.go" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + "go.uber.org/zap" kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" kcontrollerruntime "sigs.k8s.io/controller-runtime" diff --git a/internal/controller/nats/integrationtests/controller/integration_test.go b/internal/controller/nats/integrationtests/controller/integration_test.go index 11331c66..7f02f763 100644 --- a/internal/controller/nats/integrationtests/controller/integration_test.go +++ b/internal/controller/nats/integrationtests/controller/integration_test.go @@ -7,20 +7,17 @@ import ( "testing" "time" - keventsv1 "k8s.io/api/events/v1" - - "github.com/onsi/gomega" - - onsigomegatypes "github.com/onsi/gomega/types" - "github.com/stretchr/testify/require" - kcorev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/resource" - nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" nmctrl "github.com/kyma-project/nats-manager/internal/controller/nats" "github.com/kyma-project/nats-manager/testutils" "github.com/kyma-project/nats-manager/testutils/integration" nmtsmatchers "github.com/kyma-project/nats-manager/testutils/matchers/nats" + "github.com/onsi/gomega" + onsigomegatypes "github.com/onsi/gomega/types" + "github.com/stretchr/testify/require" + kcorev1 "k8s.io/api/core/v1" + keventsv1 "k8s.io/api/events/v1" + "k8s.io/apimachinery/pkg/api/resource" ) const projectRootDir = "../../../../../" diff --git a/internal/controller/nats/integrationtests/validation/integration_test.go b/internal/controller/nats/integrationtests/validation/integration_test.go index 27b77162..b3b5aba2 100644 --- a/internal/controller/nats/integrationtests/validation/integration_test.go +++ b/internal/controller/nats/integrationtests/validation/integration_test.go @@ -5,6 +5,10 @@ import ( "os" "testing" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + "github.com/kyma-project/nats-manager/testutils" + "github.com/kyma-project/nats-manager/testutils/integration" + nmtsmatchers "github.com/kyma-project/nats-manager/testutils/matchers/nats" "github.com/onsi/gomega" onsigomegatypes "github.com/onsi/gomega/types" "github.com/stretchr/testify/require" @@ -12,12 +16,6 @@ import ( "k8s.io/apimachinery/pkg/api/resource" kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - - nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" - "github.com/kyma-project/nats-manager/testutils" - nmtsmatchers "github.com/kyma-project/nats-manager/testutils/matchers/nats" - - "github.com/kyma-project/nats-manager/testutils/integration" ) const projectRootDir = "../../../../../" diff --git a/internal/controller/nats/provisioner.go b/internal/controller/nats/provisioner.go index 4b03f04e..ad99392e 100644 --- a/internal/controller/nats/provisioner.go +++ b/internal/controller/nats/provisioner.go @@ -4,14 +4,13 @@ import ( "context" "time" - "go.uber.org/zap" - kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - kcontrollerruntime "sigs.k8s.io/controller-runtime" - nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" nmctrlurl "github.com/kyma-project/nats-manager/internal/controller/nats/url" "github.com/kyma-project/nats-manager/pkg/events" "github.com/kyma-project/nats-manager/pkg/k8s/chart" + "go.uber.org/zap" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kcontrollerruntime "sigs.k8s.io/controller-runtime" ) const RequeueTimeForStatusCheck = 10 diff --git a/internal/controller/nats/provisioner_test.go b/internal/controller/nats/provisioner_test.go index f5e6879c..457ef775 100644 --- a/internal/controller/nats/provisioner_test.go +++ b/internal/controller/nats/provisioner_test.go @@ -4,10 +4,9 @@ import ( "errors" "testing" - nmmgr "github.com/kyma-project/nats-manager/pkg/manager" - nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" "github.com/kyma-project/nats-manager/pkg/k8s/chart" + nmmgr "github.com/kyma-project/nats-manager/pkg/manager" "github.com/kyma-project/nats-manager/testutils" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" diff --git a/internal/controller/nats/status_test.go b/internal/controller/nats/status_test.go index fe8aa8d3..e1a89536 100644 --- a/internal/controller/nats/status_test.go +++ b/internal/controller/nats/status_test.go @@ -4,16 +4,15 @@ import ( "errors" "testing" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" "github.com/kyma-project/nats-manager/pkg/k8s" + "github.com/kyma-project/nats-manager/testutils" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "sigs.k8s.io/controller-runtime/pkg/predicate" "sigs.k8s.io/controller-runtime/pkg/source" - - nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" - "github.com/kyma-project/nats-manager/testutils" - "github.com/stretchr/testify/require" - kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) var ErrTestErrorMsg = errors.New("test error") diff --git a/internal/controller/nats/unit_test.go b/internal/controller/nats/unit_test.go index fa136e55..e547eb22 100644 --- a/internal/controller/nats/unit_test.go +++ b/internal/controller/nats/unit_test.go @@ -4,19 +4,16 @@ import ( "context" "testing" - kcorev1 "k8s.io/api/core/v1" - - nmctrlmocks "github.com/kyma-project/nats-manager/internal/controller/nats/mocks" - - "k8s.io/apimachinery/pkg/runtime" - nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + nmctrlmocks "github.com/kyma-project/nats-manager/internal/controller/nats/mocks" nmkchartmocks "github.com/kyma-project/nats-manager/pkg/k8s/chart/mocks" nmkmocks "github.com/kyma-project/nats-manager/pkg/k8s/mocks" nmmgrmocks "github.com/kyma-project/nats-manager/pkg/manager/mocks" "github.com/kyma-project/nats-manager/testutils" "github.com/stretchr/testify/require" "go.uber.org/zap" + kcorev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/runtime" ktypes "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/tools/record" "sigs.k8s.io/controller-runtime/pkg/client" diff --git a/pkg/k8s/chart/helmrenderer_test.go b/pkg/k8s/chart/helmrenderer_test.go index 85b811b7..3ff6d734 100644 --- a/pkg/k8s/chart/helmrenderer_test.go +++ b/pkg/k8s/chart/helmrenderer_test.go @@ -7,13 +7,11 @@ import ( "testing" "github.com/kyma-project/nats-manager/testutils" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - + "github.com/stretchr/testify/require" "gopkg.in/yaml.v3" "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chart/loader" - - "github.com/stretchr/testify/require" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) const ( diff --git a/pkg/k8s/chart/releaseinstance.go b/pkg/k8s/chart/releaseinstance.go index 3b6cd29e..344389c1 100644 --- a/pkg/k8s/chart/releaseinstance.go +++ b/pkg/k8s/chart/releaseinstance.go @@ -4,9 +4,8 @@ import ( "errors" "strings" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "dario.cat/mergo" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) var ErrFailedToConvertToNestedMap = errors.New("failed to convert to nestedMap to map[string]interface{}") diff --git a/pkg/k8s/chart/releaseinstance_test.go b/pkg/k8s/chart/releaseinstance_test.go index 23c5b031..3de796fd 100644 --- a/pkg/k8s/chart/releaseinstance_test.go +++ b/pkg/k8s/chart/releaseinstance_test.go @@ -4,9 +4,8 @@ import ( "encoding/json" "testing" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "github.com/stretchr/testify/require" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) func Test_GetConfiguration(t *testing.T) { diff --git a/pkg/k8s/client.go b/pkg/k8s/client.go index bab8eaa4..e48e6b93 100644 --- a/pkg/k8s/client.go +++ b/pkg/k8s/client.go @@ -7,11 +7,10 @@ import ( kappsv1 "k8s.io/api/apps/v1" kcorev1 "k8s.io/api/core/v1" kapiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" - kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - kapiextclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/labels" ktypes "k8s.io/apimachinery/pkg/types" "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" diff --git a/pkg/manager/nats.go b/pkg/manager/nats.go index f009a69b..52b94732 100644 --- a/pkg/manager/nats.go +++ b/pkg/manager/nats.go @@ -4,11 +4,10 @@ import ( "context" "fmt" - "go.uber.org/zap" - nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" "github.com/kyma-project/nats-manager/pkg/k8s" "github.com/kyma-project/nats-manager/pkg/k8s/chart" + "go.uber.org/zap" ) var ErrNATSStatefulSetNotFound = fmt.Errorf("NATS StatefulSet not found in manifests") diff --git a/pkg/manager/overrides_test.go b/pkg/manager/overrides_test.go index 31405bfc..dbdc9e27 100644 --- a/pkg/manager/overrides_test.go +++ b/pkg/manager/overrides_test.go @@ -5,13 +5,12 @@ import ( "strings" "testing" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + "github.com/kyma-project/nats-manager/testutils" "github.com/stretchr/testify/require" "helm.sh/helm/v3/pkg/chart/loader" kcorev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" - - nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" - "github.com/kyma-project/nats-manager/testutils" ) func Test_GenerateOverrides(t *testing.T) { diff --git a/testutils/integration/integration.go b/testutils/integration/integration.go index 7e167456..b9a0ffb0 100644 --- a/testutils/integration/integration.go +++ b/testutils/integration/integration.go @@ -10,23 +10,26 @@ import ( "testing" "time" - kapipolicyv1 "k8s.io/api/policy/v1" - - kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/dynamic" - - kcorev1 "k8s.io/api/core/v1" - "github.com/avast/retry-go/v3" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + nmctrl "github.com/kyma-project/nats-manager/internal/controller/nats" + "github.com/kyma-project/nats-manager/pkg/k8s" + "github.com/kyma-project/nats-manager/pkg/k8s/chart" + nmmgr "github.com/kyma-project/nats-manager/pkg/manager" + "github.com/kyma-project/nats-manager/testutils" "github.com/onsi/gomega" "github.com/stretchr/testify/require" "go.uber.org/zap" kappsv1 "k8s.io/api/apps/v1" + kcorev1 "k8s.io/api/core/v1" + kapipolicyv1 "k8s.io/api/policy/v1" kapiextclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" kapierrors "k8s.io/apimachinery/pkg/api/errors" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/labels" ktypes "k8s.io/apimachinery/pkg/types" + "k8s.io/client-go/dynamic" kscheme "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" "k8s.io/client-go/tools/record" @@ -35,13 +38,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/envtest" "sigs.k8s.io/controller-runtime/pkg/metrics/server" "sigs.k8s.io/controller-runtime/pkg/webhook" - - nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" - nmctrl "github.com/kyma-project/nats-manager/internal/controller/nats" - "github.com/kyma-project/nats-manager/pkg/k8s" - "github.com/kyma-project/nats-manager/pkg/k8s/chart" - nmmgr "github.com/kyma-project/nats-manager/pkg/manager" - "github.com/kyma-project/nats-manager/testutils" ) const ( diff --git a/testutils/matchers/nats/matchers.go b/testutils/matchers/nats/matchers.go index 5c74d99c..fa173752 100644 --- a/testutils/matchers/nats/matchers.go +++ b/testutils/matchers/nats/matchers.go @@ -3,13 +3,12 @@ package nats import ( "reflect" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" "github.com/onsi/gomega" "github.com/onsi/gomega/gstruct" onsigomegatypes "github.com/onsi/gomega/types" kcorev1 "k8s.io/api/core/v1" kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" ) func HaveSpecJetsStreamMemStorage(ms nmapiv1alpha1.MemStorage) onsigomegatypes.GomegaMatcher { diff --git a/testutils/options.go b/testutils/options.go index fddcf4e4..7406dc03 100644 --- a/testutils/options.go +++ b/testutils/options.go @@ -3,13 +3,11 @@ package testutils import ( "errors" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" kcorev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - - nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" ) var ( diff --git a/testutils/utils.go b/testutils/utils.go index f6e432d2..9814fc54 100644 --- a/testutils/utils.go +++ b/testutils/utils.go @@ -6,19 +6,17 @@ import ( "math/rand" "time" - "k8s.io/apimachinery/pkg/api/resource" - "k8s.io/apimachinery/pkg/runtime/schema" - + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" "go.uber.org/zap" "go.uber.org/zap/zapcore" kappsv1 "k8s.io/api/apps/v1" kcorev1 "k8s.io/api/core/v1" kapiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" + "k8s.io/apimachinery/pkg/api/resource" kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" - - nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + "k8s.io/apimachinery/pkg/runtime/schema" ) const ( From cf64b48d40c840194b7da6b9b673055f6c7e453c Mon Sep 17 00:00:00 2001 From: "Kiss, Tibor" Date: Wed, 28 Feb 2024 12:04:52 +0100 Subject: [PATCH 03/12] Linter: funlen --- .golangci.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.golangci.yaml b/.golangci.yaml index 255d5961..ec647760 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -35,7 +35,6 @@ linters: - tagalign - dupword - gomoddirectives - - funlen - testifylint - containedctx - thelper From 1acbc133005a6beacd53ff7b17e60cdc4aee74ff Mon Sep 17 00:00:00 2001 From: "Kiss, Tibor" Date: Wed, 28 Feb 2024 12:06:47 +0100 Subject: [PATCH 04/12] Remove TODO: delete the following logic after migrating to modular Kyma --- internal/controller/nats/deprovisioner.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/controller/nats/deprovisioner.go b/internal/controller/nats/deprovisioner.go index 59cd3fd8..ccbbbb74 100644 --- a/internal/controller/nats/deprovisioner.go +++ b/internal/controller/nats/deprovisioner.go @@ -119,8 +119,6 @@ func (r *Reconciler) deletePVCsAndRemoveFinalizer(ctx context.Context, nats *nmapiv1alpha1.NATS, log *zap.SugaredLogger, ) (kcontrollerruntime.Result, error) { labelValue := nats.Name - //nolint: godox - // TODO: delete the following logic after migrating to modular Kyma if nats.Name == "eventing-nats" { labelValue = "eventing" } From 91f8dff92633d5f8c2f0303ead7d09041800aae3 Mon Sep 17 00:00:00 2001 From: "Kiss, Tibor" Date: Wed, 28 Feb 2024 12:16:38 +0100 Subject: [PATCH 05/12] Linter: dupword --- .golangci.yaml | 1 - internal/controller/nats/deprovisioner_test.go | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index ec647760..6575bfc3 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -33,7 +33,6 @@ linters: - varnamelen - wrapcheck - tagalign - - dupword - gomoddirectives - testifylint - containedctx diff --git a/internal/controller/nats/deprovisioner_test.go b/internal/controller/nats/deprovisioner_test.go index 77beef69..40f72700 100644 --- a/internal/controller/nats/deprovisioner_test.go +++ b/internal/controller/nats/deprovisioner_test.go @@ -64,7 +64,7 @@ func Test_handleNATSDeletion(t *testing.T) { return natsClient }, wantNATSStatusState: nmapiv1alpha1.StateDeleting, - wantK8sEvents: []string{"Normal Deleting Deleting the NATS cluster."}, + wantK8sEvents: []string{"Normal Deleting the NATS cluster."}, wantResult: kcontrollerruntime.Result{}, }, { @@ -78,7 +78,7 @@ func Test_handleNATSDeletion(t *testing.T) { natsClient.On("Close").Return() return natsClient }, - wantK8sEvents: []string{"Normal Deleting Deleting the NATS cluster."}, + wantK8sEvents: []string{"Normal Deleting the NATS cluster."}, wantResult: kcontrollerruntime.Result{}, }, { @@ -99,7 +99,7 @@ func Test_handleNATSDeletion(t *testing.T) { natsClient.On("Close").Return() return natsClient }, - wantK8sEvents: []string{"Normal Deleting Deleting the NATS cluster."}, + wantK8sEvents: []string{"Normal Deleting the NATS cluster."}, wantResult: kcontrollerruntime.Result{}, }, { @@ -128,7 +128,7 @@ func Test_handleNATSDeletion(t *testing.T) { }, wantFinalizerExists: true, wantK8sEvents: []string{ - "Normal Deleting Deleting the NATS cluster.", + "Normal Deleting the NATS cluster.", "Warning DeletionError " + StreamExistsErrorMsg, }, wantResult: kcontrollerruntime.Result{Requeue: true}, @@ -160,7 +160,7 @@ func Test_handleNATSDeletion(t *testing.T) { }, wantFinalizerExists: true, wantK8sEvents: []string{ - "Normal Deleting Deleting the NATS cluster.", + "Normal Deleting the NATS cluster.", "Warning DeletionError " + ConsumerExistsErrorMsg, }, wantResult: kcontrollerruntime.Result{Requeue: true}, @@ -184,7 +184,7 @@ func Test_handleNATSDeletion(t *testing.T) { return natsClient }, wantK8sEvents: []string{ - "Normal Deleting Deleting the NATS cluster.", + "Normal Deleting the NATS cluster.", }, wantResult: kcontrollerruntime.Result{}, }, From 2147683a57b59730846ac76ea8c39861c262217b Mon Sep 17 00:00:00 2001 From: "Kiss, Tibor" Date: Wed, 28 Feb 2024 13:55:09 +0100 Subject: [PATCH 06/12] Linter: thelper --- .golangci.yaml | 1 - .../controller/integration_test.go | 2 ++ internal/controller/nats/unit_test.go | 1 + pkg/k8s/chart/helmrenderer_test.go | 1 + pkg/manager/overrides_test.go | 1 + testutils/integration/integration.go | 27 +++++++++++++++++++ 6 files changed, 32 insertions(+), 1 deletion(-) diff --git a/.golangci.yaml b/.golangci.yaml index 6575bfc3..b05da5a6 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -36,7 +36,6 @@ linters: - gomoddirectives - testifylint - containedctx - - thelper - tagliatelle - errchkjson - perfsprint diff --git a/internal/controller/nats/integrationtests/controller/integration_test.go b/internal/controller/nats/integrationtests/controller/integration_test.go index 7f02f763..aa8dc7c2 100644 --- a/internal/controller/nats/integrationtests/controller/integration_test.go +++ b/internal/controller/nats/integrationtests/controller/integration_test.go @@ -602,6 +602,7 @@ func Test_DoubleReconcileNATSCR(t *testing.T) { } func makeStatefulSetReady(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { sts, err := testEnvironment.GetStatefulSetFromK8s(name, namespace) if err != nil { @@ -629,6 +630,7 @@ type deletionFunc func(env integration.TestEnvironment, natsName, namespace stri func ensureK8sResourceDeletion( t *testing.T, env integration.TestEnvironment, natsName, namespace string, fs ...deletionFunc, ) { + t.Helper() for _, f := range fs { require.NoError(t, f(env, natsName, namespace)) } diff --git a/internal/controller/nats/unit_test.go b/internal/controller/nats/unit_test.go index e547eb22..a53b21e2 100644 --- a/internal/controller/nats/unit_test.go +++ b/internal/controller/nats/unit_test.go @@ -35,6 +35,7 @@ type MockedUnitTestEnvironment struct { } func NewMockedUnitTestEnvironment(t *testing.T, objs ...client.Object) *MockedUnitTestEnvironment { + t.Helper() // setup context ctx := context.Background() diff --git a/pkg/k8s/chart/helmrenderer_test.go b/pkg/k8s/chart/helmrenderer_test.go index 3ff6d734..35a7aa0b 100644 --- a/pkg/k8s/chart/helmrenderer_test.go +++ b/pkg/k8s/chart/helmrenderer_test.go @@ -204,6 +204,7 @@ func Test_RenderManifestAsUnstructured(t *testing.T) { } func loadHelmChart(t *testing.T) *chart.Chart { + t.Helper() helmChart, err := loader.Load(testChartDir) require.NoError(t, err) return helmChart diff --git a/pkg/manager/overrides_test.go b/pkg/manager/overrides_test.go index dbdc9e27..c753ef2d 100644 --- a/pkg/manager/overrides_test.go +++ b/pkg/manager/overrides_test.go @@ -169,6 +169,7 @@ func Test_Overrides_Keys(t *testing.T) { } func getValueFromNestedMap(t *testing.T, key string, data map[string]interface{}) interface{} { + t.Helper() tokens := strings.Split(key, ".") lastNestedData := data for depth, token := range tokens { diff --git a/testutils/integration/integration.go b/testutils/integration/integration.go index b9a0ffb0..432b30ca 100644 --- a/testutils/integration/integration.go +++ b/testutils/integration/integration.go @@ -207,6 +207,7 @@ func (env TestEnvironment) CreateK8sResource(obj client.Object) error { } func (env TestEnvironment) EnsureNamespaceCreation(t *testing.T, namespace string) { + t.Helper() if namespace == "default" { return } @@ -216,10 +217,12 @@ func (env TestEnvironment) EnsureNamespaceCreation(t *testing.T, namespace strin } func (env TestEnvironment) EnsureK8sResourceCreated(t *testing.T, obj client.Object) { + t.Helper() require.NoError(t, env.k8sClient.Create(env.Context, obj)) } func (env TestEnvironment) EnsureK8sUnStructResourceCreated(t *testing.T, obj *unstructured.Unstructured) { + t.Helper() require.NoError(t, env.k8sClient.Create(env.Context, obj)) } @@ -228,6 +231,7 @@ func (env TestEnvironment) CreateUnstructuredK8sResource(obj *unstructured.Unstr } func (env TestEnvironment) EnsureK8sResourceUpdated(t *testing.T, obj client.Object) { + t.Helper() require.NoError(t, env.k8sClient.Update(env.Context, obj)) } @@ -247,10 +251,12 @@ func (env TestEnvironment) UpdatedNATSInK8s(nats *nmapiv1alpha1.NATS, options .. } func (env TestEnvironment) EnsureK8sResourceDeleted(t *testing.T, obj client.Object) { + t.Helper() require.NoError(t, env.k8sClient.Delete(env.Context, obj)) } func (env TestEnvironment) EnsureK8sConfigMapExists(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { result, err := env.GetConfigMapFromK8s(name, namespace) return err == nil && result != nil @@ -258,6 +264,7 @@ func (env TestEnvironment) EnsureK8sConfigMapExists(t *testing.T, name, namespac } func (env TestEnvironment) EnsureK8sSecretExists(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { result, err := env.GetSecretFromK8s(name, namespace) return err == nil && result != nil @@ -265,6 +272,7 @@ func (env TestEnvironment) EnsureK8sSecretExists(t *testing.T, name, namespace s } func (env TestEnvironment) EnsureK8sPodDisruptionBudgetExists(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { result, err := env.GetPodDisruptionBudgetFromK8s(name, namespace) return err == nil && result != nil @@ -272,6 +280,7 @@ func (env TestEnvironment) EnsureK8sPodDisruptionBudgetExists(t *testing.T, name } func (env TestEnvironment) EnsureK8sServiceExists(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { result, err := env.GetServiceFromK8s(name, namespace) return err == nil && result != nil @@ -279,6 +288,7 @@ func (env TestEnvironment) EnsureK8sServiceExists(t *testing.T, name, namespace } func (env TestEnvironment) EnsureK8sDestinationRuleExists(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { result, err := env.GetDestinationRuleFromK8s(name, namespace) return err == nil && result != nil @@ -286,6 +296,7 @@ func (env TestEnvironment) EnsureK8sDestinationRuleExists(t *testing.T, name, na } func (env TestEnvironment) EnsureK8sStatefulSetExists(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { result, err := env.GetStatefulSetFromK8s(name, namespace) if err != nil { @@ -297,6 +308,7 @@ func (env TestEnvironment) EnsureK8sStatefulSetExists(t *testing.T, name, namesp } func (env TestEnvironment) EnsureK8sPVCExists(t *testing.T, label, namespace string) { + t.Helper() require.Eventually(t, func() bool { result, err := env.GetPVCFromK8s(label, namespace) if err != nil { @@ -308,6 +320,7 @@ func (env TestEnvironment) EnsureK8sPVCExists(t *testing.T, label, namespace str } func (env TestEnvironment) EnsureK8sConfigMapNotFound(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { _, err := env.GetConfigMapFromK8s(name, namespace) return err != nil && kapierrors.IsNotFound(err) @@ -315,6 +328,7 @@ func (env TestEnvironment) EnsureK8sConfigMapNotFound(t *testing.T, name, namesp } func (env TestEnvironment) EnsureK8sSecretNotFound(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { _, err := env.GetSecretFromK8s(name, namespace) return err != nil && kapierrors.IsNotFound(err) @@ -322,6 +336,7 @@ func (env TestEnvironment) EnsureK8sSecretNotFound(t *testing.T, name, namespace } func (env TestEnvironment) EnsureK8sServiceNotFound(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { _, err := env.GetServiceFromK8s(name, namespace) return err != nil && kapierrors.IsNotFound(err) @@ -329,6 +344,7 @@ func (env TestEnvironment) EnsureK8sServiceNotFound(t *testing.T, name, namespac } func (env TestEnvironment) EnsureK8sDestinationRuleNotFound(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { _, err := env.GetDestinationRuleFromK8s(name, namespace) return err != nil && kapierrors.IsNotFound(err) @@ -336,6 +352,7 @@ func (env TestEnvironment) EnsureK8sDestinationRuleNotFound(t *testing.T, name, } func (env TestEnvironment) EnsureK8sNATSNotFound(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { _, err := env.GetNATSFromK8s(name, namespace) return err != nil && kapierrors.IsNotFound(err) @@ -343,6 +360,7 @@ func (env TestEnvironment) EnsureK8sNATSNotFound(t *testing.T, name, namespace s } func (env TestEnvironment) EnsureK8sStatefulSetNotFound(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { _, err := env.GetStatefulSetFromK8s(name, namespace) if err != nil { @@ -354,6 +372,7 @@ func (env TestEnvironment) EnsureK8sStatefulSetNotFound(t *testing.T, name, name } func (env TestEnvironment) EnsureK8sPVCNotFound(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { pvc, err := env.GetPVCFromK8s(name, namespace) if err != nil { @@ -368,6 +387,7 @@ func (env TestEnvironment) EnsureK8sPVCNotFound(t *testing.T, name, namespace st func (env TestEnvironment) EnsureK8sStatefulSetHasLabels(t *testing.T, name, namespace string, labels map[string]string, ) { + t.Helper() require.Eventually(t, func() bool { result, err := env.GetStatefulSetFromK8s(name, namespace) if err != nil { @@ -389,6 +409,7 @@ func (env TestEnvironment) EnsureK8sStatefulSetHasLabels(t *testing.T, name, nam func (env TestEnvironment) EnsureK8sStatefulSetHasAnnotations(t *testing.T, name, namespace string, annotations map[string]string, ) { + t.Helper() require.Eventually(t, func() bool { result, err := env.GetStatefulSetFromK8s(name, namespace) if err != nil { @@ -410,6 +431,7 @@ func (env TestEnvironment) EnsureK8sStatefulSetHasAnnotations(t *testing.T, name // EnsureNATSSpecClusterSizeReflected ensures that NATS CR Spec.cluster.size is reflected // in relevant k8s objects. func (env TestEnvironment) EnsureNATSSpecClusterSizeReflected(t *testing.T, nats nmapiv1alpha1.NATS) { + t.Helper() require.Eventually(t, func() bool { stsName := testutils.GetStatefulSetName(nats) result, err := env.GetStatefulSetFromK8s(stsName, nats.Namespace) @@ -425,6 +447,7 @@ func (env TestEnvironment) EnsureNATSSpecClusterSizeReflected(t *testing.T, nats // EnsureNATSSpecResourcesReflected ensures that NATS CR Spec.resources is reflected // in relevant k8s objects. func (env TestEnvironment) EnsureNATSSpecResourcesReflected(t *testing.T, nats nmapiv1alpha1.NATS) { + t.Helper() require.Eventually(t, func() bool { stsName := testutils.GetStatefulSetName(nats) result, err := env.GetStatefulSetFromK8s(stsName, nats.Namespace) @@ -444,6 +467,7 @@ func (env TestEnvironment) EnsureNATSSpecResourcesReflected(t *testing.T, nats n // EnsureNATSSpecDebugTraceReflected ensures that NATS CR Spec.trace and Spec.debug is reflected // in relevant k8s objects. func (env TestEnvironment) EnsureNATSSpecDebugTraceReflected(t *testing.T, nats nmapiv1alpha1.NATS) { + t.Helper() require.Eventually(t, func() bool { // get NATS configMap. result, err := env.GetConfigMapFromK8s(testutils.GetConfigMapName(nats), nats.Namespace) @@ -468,6 +492,7 @@ func (env TestEnvironment) EnsureNATSSpecDebugTraceReflected(t *testing.T, nats // EnsureNATSSpecFileStorageReflected ensures that NATS CR Spec.jetStream.fileStorage is reflected // in relevant k8s objects. func (env TestEnvironment) EnsureNATSSpecFileStorageReflected(t *testing.T, nats nmapiv1alpha1.NATS) { + t.Helper() require.Eventually(t, func() bool { // get NATS configMap. result, err := env.GetConfigMapFromK8s(testutils.GetConfigMapName(nats), nats.Namespace) @@ -512,6 +537,7 @@ func (env TestEnvironment) EnsureNATSSpecFileStorageReflected(t *testing.T, nats // EnsureNATSSpecMemStorageReflected ensures that NATS CR Spec.jetStream.memStorage is reflected // in relevant k8s objects. func (env TestEnvironment) EnsureNATSSpecMemStorageReflected(t *testing.T, nats nmapiv1alpha1.NATS) { + t.Helper() require.Eventually(t, func() bool { // get NATS configMap. result, err := env.GetConfigMapFromK8s(testutils.GetConfigMapName(nats), nats.Namespace) @@ -533,6 +559,7 @@ func (env TestEnvironment) EnsureNATSSpecMemStorageReflected(t *testing.T, nats } func (env TestEnvironment) EnsureURLInNATSStatus(t *testing.T, name, namespace string) { + t.Helper() natsCR, err := env.GetNATSFromK8s(name, namespace) require.NoError(t, err) require.NotNil(t, natsCR) From 1fbe8f224c6d0418e5327c01f550bad99764719c Mon Sep 17 00:00:00 2001 From: "Kiss, Tibor" Date: Wed, 28 Feb 2024 14:06:54 +0100 Subject: [PATCH 07/12] Linter: tagalign --- .golangci.yaml | 1 - pkg/env/config.go | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index b05da5a6..fcfb97b2 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -32,7 +32,6 @@ linters: - unconvert - varnamelen - wrapcheck - - tagalign - gomoddirectives - testifylint - containedctx diff --git a/pkg/env/config.go b/pkg/env/config.go index 80b0ccde..42c65f0f 100644 --- a/pkg/env/config.go +++ b/pkg/env/config.go @@ -6,9 +6,9 @@ import ( // Config represents the environment config for the NATS Manager. type Config struct { - LogLevel string `envconfig:"LOG_LEVEL" required:"true"` - NATSChartDir string `envconfig:"NATS_CHART_DIR" required:"true"` - NATSCRName string `envconfig:"NATS_CR_NAME" required:"true"` + LogLevel string `envconfig:"LOG_LEVEL" required:"true"` + NATSChartDir string `envconfig:"NATS_CHART_DIR" required:"true"` + NATSCRName string `envconfig:"NATS_CR_NAME" required:"true"` NATSCRNamespace string `envconfig:"NATS_CR_NAMESPACE" required:"true"` } From bf8201150e687efebdb9231b2568c61f59e1dfb5 Mon Sep 17 00:00:00 2001 From: "Kiss, Tibor" Date: Wed, 28 Feb 2024 15:02:30 +0100 Subject: [PATCH 08/12] Linter: perfsprint --- .golangci.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.golangci.yaml b/.golangci.yaml index fcfb97b2..0a2775e9 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -37,7 +37,6 @@ linters: - containedctx - tagliatelle - errchkjson - - perfsprint - noctx linters-settings: From 9148f001e6899aa4284c2d6a35519c13f4799b97 Mon Sep 17 00:00:00 2001 From: "Kiss, Tibor" Date: Wed, 28 Feb 2024 15:32:49 +0100 Subject: [PATCH 09/12] Linter: gomoddirectives --- .golangci.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.golangci.yaml b/.golangci.yaml index 0a2775e9..8fb13d9d 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -32,7 +32,6 @@ linters: - unconvert - varnamelen - wrapcheck - - gomoddirectives - testifylint - containedctx - tagliatelle From 0a417bf667c00ae063beb20425fbc357c25225af Mon Sep 17 00:00:00 2001 From: "Kiss, Tibor" Date: Wed, 28 Feb 2024 17:07:18 +0100 Subject: [PATCH 10/12] Central Linter Config --- .github/workflows/codequality.yml | 21 +-- .golangci.yaml | 234 ------------------------------ 2 files changed, 6 insertions(+), 249 deletions(-) delete mode 100644 .golangci.yaml diff --git a/.github/workflows/codequality.yml b/.github/workflows/codequality.yml index 0af0d28b..b6c7c659 100644 --- a/.github/workflows/codequality.yml +++ b/.github/workflows/codequality.yml @@ -21,18 +21,9 @@ permissions: pull-requests: read jobs: - lint: - name: lint - runs-on: ubuntu-latest - steps: - - uses: actions/setup-go@v5 - with: - go-version: "1.21" - cache: false - - uses: actions/checkout@v4 - - name: golangci-lint - uses: golangci/golangci-lint-action@v3 - with: - # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: v1.55 - args: --timeout=5m + code-linter: + name: "Run golangci-lint" + uses: kyma-project/eventing-tools/.github/workflows/lint-go-reusable.yml@main + with: + go-version: "1.21" + lint-config-uri: https://raw.githubusercontent.com/kyma-project/eventing-tools/abb93fa301d4b1aa07b46e5b01ffb0463f06e1bb/config/lint/.golangci.yaml diff --git a/.golangci.yaml b/.golangci.yaml deleted file mode 100644 index 8fb13d9d..00000000 --- a/.golangci.yaml +++ /dev/null @@ -1,234 +0,0 @@ -linters: - enable-all: true - disable: - - contextcheck # too many false positives - - deadcode # deprecated (since v1.49.0) and replaced by 'unused' - - depguard # checks if package imports are whitelisted - - exhaustivestruct # deprecated (since v1.46.0) and replaced by 'exhaustruct' - - exhaustruct # TODO enable and fix, use regex to exclude certain cases - - golint # deprecated (since v1.41.0) and replaced by 'revive' - - ifshort # deprecated (since v1.48.0) - - interfacer # deprecated (since v1.38.0) - - lll - - maligned # deprecated (since v1.38.0) - - nlreturn # too strict and mostly code is not more readable - - nosnakecase # deprecated (since v1.48.1) and replaced by 'revive' - - scopelint # deprecated (since v1.39.0) and replaced by 'exportloopref' - - structcheck # deprecated (since v1.49.0) and replaced by 'unused' - - sqlclosecheck # not needed for this project - - varcheck # deprecated (since v1.49.0) and replaced by 'unused' - - wsl # too strict and mostly code is not more readable - - dupl - - forcetypeassert - - gosec - - inamedparam - - ireturn - - maintidx - - nolintlint - - paralleltest - - prealloc - - testpackage - - tparallel - - unconvert - - varnamelen - - wrapcheck - - testifylint - - containedctx - - tagliatelle - - errchkjson - - noctx - -linters-settings: - gomoddirectives: - replace-allow-list: - - github.com/prometheus/client_golang - stylecheck: - dot-import-whitelist: - - github.com/onsi/ginkgo/v2 - - github.com/onsi/gomega - revive: - enable-all-rules: false - severity: error - rules: - - name: comment-spacings - disabled: true - - name: dot-imports - severity: warning - disabled: true - - name: line-length-limit - severity: warning - disabled: true - arguments: [120] - funlen: - lines: 100 - cyclop: - max-complexity: 20 - nestif: - min-complexity: 6 - gci: - sections: - - standard # Standard packages. - - default # Imports that could not be matched to another section type. - - prefix(github.com/kyma-project/eventing-manager) # Imports with the specified prefix. - - blank # Blank imports. - - dot # Dot imports. - custom-order: true - skip-generated: true - importas: - no-unaliased: false - no-extra-aliases: true - ## Version number must be added as suffix to the package name. As an example check `k8s.io/api/core/v1` - ## kubernetes APIs get the prefix `k`. As an example check `kcorev1` - ## Eventing Manager APIs get the prefix `em`. As an example check `emeventingv1alpha1` - ## Eventing Publisher Proxy APIs get the prefix `epp`. As an example check `eppapi` - ## Cloud Events APIs get the prefix `ce`. As an example check `ce` - ## Eventing Auth Manager APIs get the prefix `eam`. - ## Kyma Metrics Collector APIs get the prefix `kmc`. - ## NATS Manager APIs get the prefix `nm`. - - alias: - - pkg: "log" - alias: log - - pkg: k8s.io/api/core/v1 - alias: kcorev1 - - pkg: k8s.io/apimachinery/pkg/apis/meta/v1 - alias: kmetav1 - - pkg: k8s.io/client-go/dynamic/fake - alias: kdynamicfake - - pkg: github.com/nats-io/nats.go - alias: natsgo - - pkg: go.opencensus.io/trace/propagation - alias: ocpropagation - - pkg: github.com/kyma-project/eventing-publisher-proxy/testing - alias: epptestingutils - - pkg: github.com/kyma-project/eventing-publisher-proxy/pkg/legacy/api - alias: eppapi - - pkg: github.com/kyma-project/eventing-publisher-proxy/pkg/nats - alias: eppnats - - pkg: github.com/kyma-project/eventing-manager/pkg/logger - alias: emlogger - - pkg: github.com/kyma-project/eventing-manager/api/eventing/v1alpha1 - alias: emeventingv1alpha1 - - pkg: github.com/kyma-project/eventing-manager/api/eventing/v1alpha2 - alias: emeventingv2alpha1 - - pkg: github.com/cloudevents/sdk-go/v2 - alias: ce - - pkg: github.com/cloudevents/sdk-go/v2/protocol/http - alias: cehttp - - pkg: github.com/cloudevents/sdk-go/v2/event - alias: ceevent - - pkg: github.com/cloudevents/sdk-go/v2/client - alias: ceclient - - pkg: github.com/kyma-project/kyma/components/central-application-gateway/pkg/apis/applicationconnector/v1alpha1 - alias: kymaappconnv1alpha1 - - ###### - ### The following imports are used by github.com/kyma-project/eventing-auth-manager repository. - ###### - - pkg: github.com/kyma-project/eventing-auth-manager/internal/ias - alias: eamias - - pkg: github.com/kyma-project/eventing-auth-manager/controllers - alias: eamcontrollers - - pkg: github.com/kyma-project/eventing-auth-manager/api/v1alpha1 - alias: eamapiv1alpha1 - - pkg: github.com/kyma-project/eventing-auth-manager/internal/ias/internal/oidc/mocks - alias: eamoidcmocks - - pkg: github.com/kyma-project/lifecycle-manager/api/v1beta1 - alias: klmapiv1beta1 - - pkg: github.com/kyma-project/lifecycle-manager/api/v1beta2 - alias: klmapiv1beta2 - - pkg: k8s.io/apimachinery/pkg/api/errors - alias: kapierrors - - pkg: sigs.k8s.io/controller-runtime/pkg/client - alias: kpkgclient - - pkg: k8s.io/apimachinery/pkg/util/runtime - alias: kutilruntime - - pkg: k8s.io/client-go/kubernetes/scheme - alias: kscheme - - pkg: sigs.k8s.io/controller-runtime - alias: kcontrollerruntime - - pkg: github.com/onsi/gomega/types - alias: onsigomegatypes - - pkg: sigs.k8s.io/controller-runtime/pkg/log - alias: kpkglog - - ###### - ### The following imports are used by github.com/kyma-project/nats-manager repository. - ###### - - pkg: k8s.io/api/apps/v1 - alias: kappsv1 - - pkg: k8s.io/apimachinery/pkg/types - alias: ktypes - - pkg: sigs.k8s.io/controller-runtime/pkg/log/zap - alias: klogzap - - pkg: github.com/kyma-project/nats-manager/pkg/k8s/mocks - alias: nmkmocks - - pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1 - alias: kapiextv1 - - pkg: k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset - alias: kapiextclientset - - pkg: github.com/kyma-project/nats-manager/internal/controller/nats - alias: nmctrl - - pkg: github.com/kyma-project/nats-manager/api/v1alpha1 - alias: nmapiv1alpha1 - - pkg: k8s.io/api/policy/v1 - alias: kapipolicyv1 - - pkg: github.com/kyma-project/nats-manager/pkg/k8s/chart/mocks - alias: nmkchartmocks - - pkg: k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/fake - alias: kapiextclientsetfake - - pkg: k8s.io/apimachinery/pkg/util/yaml - alias: kutilyaml - - pkg: github.com/kyma-project/nats-manager/pkg/manager/mocks - alias: nmmgrmocks - - pkg: github.com/kyma-project/nats-manager/internal/controller/nats/mocks - alias: nmctrlmocks - - pkg: github.com/kyma-project/nats-manager/pkg/manager - alias: nmmgr - - pkg: github.com/kyma-project/nats-manager/internal/controller/nats/url - alias: nmctrlurl - - pkg: github.com/kyma-project/nats-manager/testutils/matchers/nats - alias: nmtsmatchers - - pkg: k8s.io/api/events/v1 - alias: keventsv1 - - pkg: github.com/kyma-project/nats-manager/pkg/nats - alias: nmnats - - pkg: k8s.io/api/rbac/v1 - alias: krbacv1 - - pkg: k8s.io/api/autoscaling/v1 - alias: kautoscalingv1 - - pkg: github.com/kyma-project/nats-manager/internal/controller/cache - alias: nmctrlcache - - pkg: github.com/kyma-project/nats-manager/pkg/labels - alias: nmlabels - - ireturn: - allow: - - anon - - error - - empty - - stdlib - - Client - - client.Object - - (or|er)$ - wrapcheck: - ignorePackageGlobs: -issues: - exclude-rules: - - path: "_test\\.go" - linters: - - wrapcheck - - gochecknoglobals - - funlen # Table driven unit and integration tests exceed function length by design - - maintidx # Table driven unit and integration tests exceed maintainability index by design - - linters: - - importas - text: has alias "" which is not part of config # Ignore false positives that emerged due to https://github.com/julz/importas/issues/15. - max-issues-per-linter: 0 - max-same-issues: 0 -output: - sort-results: true -run: - timeout: 15m - skip-files: - - zz_generated.deepcopy.go From c2282b1f6b9ee2779e4ddfffcf09fb13d6c54d79 Mon Sep 17 00:00:00 2001 From: "Kiss, Tibor" Date: Wed, 28 Feb 2024 18:07:20 +0100 Subject: [PATCH 11/12] No lint for dupword --- internal/controller/nats/deprovisioner_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/controller/nats/deprovisioner_test.go b/internal/controller/nats/deprovisioner_test.go index 40f72700..343d8945 100644 --- a/internal/controller/nats/deprovisioner_test.go +++ b/internal/controller/nats/deprovisioner_test.go @@ -64,7 +64,7 @@ func Test_handleNATSDeletion(t *testing.T) { return natsClient }, wantNATSStatusState: nmapiv1alpha1.StateDeleting, - wantK8sEvents: []string{"Normal Deleting the NATS cluster."}, + wantK8sEvents: []string{"Normal Deleting Deleting the NATS cluster."}, //nolint: dupword // reason: This is the required result wantResult: kcontrollerruntime.Result{}, }, { @@ -78,7 +78,7 @@ func Test_handleNATSDeletion(t *testing.T) { natsClient.On("Close").Return() return natsClient }, - wantK8sEvents: []string{"Normal Deleting the NATS cluster."}, + wantK8sEvents: []string{"Normal Deleting Deleting the NATS cluster."}, //nolint: dupword // reason: This is the required result wantResult: kcontrollerruntime.Result{}, }, { @@ -99,7 +99,7 @@ func Test_handleNATSDeletion(t *testing.T) { natsClient.On("Close").Return() return natsClient }, - wantK8sEvents: []string{"Normal Deleting the NATS cluster."}, + wantK8sEvents: []string{"Normal Deleting Deleting the NATS cluster."}, //nolint: dupword // reason: This is the required result wantResult: kcontrollerruntime.Result{}, }, { @@ -128,7 +128,7 @@ func Test_handleNATSDeletion(t *testing.T) { }, wantFinalizerExists: true, wantK8sEvents: []string{ - "Normal Deleting the NATS cluster.", + "Normal Deleting Deleting the NATS cluster.", //nolint: dupword // reason: This is the required result "Warning DeletionError " + StreamExistsErrorMsg, }, wantResult: kcontrollerruntime.Result{Requeue: true}, @@ -160,7 +160,7 @@ func Test_handleNATSDeletion(t *testing.T) { }, wantFinalizerExists: true, wantK8sEvents: []string{ - "Normal Deleting the NATS cluster.", + "Normal Deleting Deleting the NATS cluster.", //nolint: dupword // reason: This is the required result "Warning DeletionError " + ConsumerExistsErrorMsg, }, wantResult: kcontrollerruntime.Result{Requeue: true}, @@ -184,7 +184,7 @@ func Test_handleNATSDeletion(t *testing.T) { return natsClient }, wantK8sEvents: []string{ - "Normal Deleting the NATS cluster.", + "Normal Deleting Deleting the NATS cluster.", //nolint: dupword // reason: This is the required result }, wantResult: kcontrollerruntime.Result{}, }, From 436f2ddc5078e50288286b5701a0eae307d51c0c Mon Sep 17 00:00:00 2001 From: "Kiss, Tibor" Date: Fri, 1 Mar 2024 12:03:59 +0100 Subject: [PATCH 12/12] go-version: "1.22" --- .github/workflows/codequality.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codequality.yml b/.github/workflows/codequality.yml index b6c7c659..7787e251 100644 --- a/.github/workflows/codequality.yml +++ b/.github/workflows/codequality.yml @@ -25,5 +25,5 @@ jobs: name: "Run golangci-lint" uses: kyma-project/eventing-tools/.github/workflows/lint-go-reusable.yml@main with: - go-version: "1.21" + go-version: "1.22" lint-config-uri: https://raw.githubusercontent.com/kyma-project/eventing-tools/abb93fa301d4b1aa07b46e5b01ffb0463f06e1bb/config/lint/.golangci.yaml