From 7cebd98686981c3fca702a09f6fd2c73b6517fca Mon Sep 17 00:00:00 2001 From: marcobebway Date: Thu, 11 Apr 2024 18:09:57 +0200 Subject: [PATCH] Fix lint issues --- .github/workflows/lint-go.yml | 2 +- .golangci.yaml | 2 + Makefile | 2 +- api/eventing/v1alpha2/condition.go | 8 ++-- api/eventing/v1alpha2/subscription_types.go | 5 ++- api/operator/v1alpha1/status_test.go | 2 +- cmd/main.go | 2 +- hack/e2e/common/eventing/publisher.go | 3 +- internal/controller/errors/skip.go | 2 +- .../subscription/eventmesh/reconciler.go | 31 ++++++++------- .../reconciler_internal_integration_test.go | 4 +- .../test/reconciler_integration_test.go | 2 +- .../subscription/eventmesh/test/utils.go | 10 +---- .../eventmesh/testwebhookauth/utils.go | 29 +++++++------- .../subscription/jetstream/reconciler.go | 39 +++++++++---------- .../reconciler_internal_unit_test.go | 2 +- .../subscription/jetstream/test_utils_test.go | 3 +- .../operator/eventing/eventmesh_test.go | 2 +- .../controller/integration_test.go | 6 +-- .../controller/operator/eventing/nats_test.go | 2 +- pkg/backend/cleaner/eventmesh.go | 2 +- .../jetstream/config_internal_unit_test.go | 2 +- .../jetstream/jetstream_integration_test.go | 4 +- pkg/backend/sink/validator.go | 4 +- pkg/k8s/client.go | 2 +- pkg/utils/utils_unit_test.go | 2 +- pkg/watcher/watcher.go | 1 - test/utils/integration/integration.go | 6 +-- testing/eventmeshmock.go | 2 +- 29 files changed, 91 insertions(+), 92 deletions(-) diff --git a/.github/workflows/lint-go.yml b/.github/workflows/lint-go.yml index 0d703e5ee..0d2cebd0f 100644 --- a/.github/workflows/lint-go.yml +++ b/.github/workflows/lint-go.yml @@ -40,4 +40,4 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v4.0.0 with: - version: v1.55 + version: v1.57 diff --git a/.golangci.yaml b/.golangci.yaml index e7353ed81..30626d4f5 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -26,6 +26,8 @@ linters: - testpackage - wrapcheck - paralleltest + - copyloopvar + - perfsprint linters-settings: stylecheck: diff --git a/Makefile b/Makefile index 283016341..88d056ea8 100644 --- a/Makefile +++ b/Makefile @@ -204,7 +204,7 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest ## Tool Versions KUSTOMIZE_VERSION ?= v5.0.0 CONTROLLER_TOOLS_VERSION ?= v0.14.0 -GOLANG_CI_LINT_VERSION ?= v1.55.2 +GOLANG_CI_LINT_VERSION ?= v1.57 KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" .PHONY: kustomize diff --git a/api/eventing/v1alpha2/condition.go b/api/eventing/v1alpha2/condition.go index 0ad5949e8..e7ceafb5f 100644 --- a/api/eventing/v1alpha2/condition.go +++ b/api/eventing/v1alpha2/condition.go @@ -322,13 +322,13 @@ func makeSubscriptionSpecValidCondition(err error) Condition { func (s *SubscriptionStatus) setCondition(condition Condition) { isFound, isSet := false, false conditions := make([]Condition, 0, len(s.Conditions)) - for _, c := range s.Conditions { - if c.Type != condition.Type { - conditions = append(conditions, c) + for _, cond := range s.Conditions { + if cond.Type != condition.Type { + conditions = append(conditions, cond) continue } isFound = true - if !ConditionEquals(c, condition) { + if !ConditionEquals(cond, condition) { isSet = true conditions = append(conditions, condition) } diff --git a/api/eventing/v1alpha2/subscription_types.go b/api/eventing/v1alpha2/subscription_types.go index 59e414f9a..560001c7c 100644 --- a/api/eventing/v1alpha2/subscription_types.go +++ b/api/eventing/v1alpha2/subscription_types.go @@ -117,15 +117,16 @@ func (s *Subscription) GetUniqueTypes() []string { return result } -// GetDuplicateTypes returns the duplicate types from subscription spec. +// GetDuplicateTypes returns the duplicate types from the Subscription spec. func (s *Subscription) GetDuplicateTypes() []string { if len(s.Spec.Types) == 0 { return s.Spec.Types } + const duplicatesCount = 2 types := make(map[string]int, len(s.Spec.Types)) duplicates := make([]string, 0, len(s.Spec.Types)) for _, t := range s.Spec.Types { - if types[t]++; types[t] == 2 { + if types[t]++; types[t] == duplicatesCount { duplicates = append(duplicates, t) } } diff --git a/api/operator/v1alpha1/status_test.go b/api/operator/v1alpha1/status_test.go index a0a5b0359..9177cc034 100644 --- a/api/operator/v1alpha1/status_test.go +++ b/api/operator/v1alpha1/status_test.go @@ -426,7 +426,7 @@ func assertConditionsEqual(t *testing.T, expected, actual []kmetav1.Condition) { t.Helper() assert.Equal(t, len(expected), len(actual)) - for i := 0; i < len(expected); i++ { + for i := range len(expected) { assertConditionEqual(t, expected[i], actual[i]) } } diff --git a/cmd/main.go b/cmd/main.go index 72e883410..95ab7d61a 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -25,6 +25,7 @@ import ( "time" "github.com/go-logr/zapr" + apigatewayv1beta1 "github.com/kyma-project/api-gateway/apis/gateway/v1beta1" natsio "github.com/nats-io/nats.go" kapiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" kapixclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" @@ -38,7 +39,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/healthz" "sigs.k8s.io/controller-runtime/pkg/metrics/server" - apigatewayv1beta1 "github.com/kyma-project/api-gateway/apis/gateway/v1beta1" eventingv1alpha2 "github.com/kyma-project/eventing-manager/api/eventing/v1alpha2" operatorv1alpha1 "github.com/kyma-project/eventing-manager/api/operator/v1alpha1" natsconnection "github.com/kyma-project/eventing-manager/internal/connection/nats" diff --git a/hack/e2e/common/eventing/publisher.go b/hack/e2e/common/eventing/publisher.go index c363fd55e..40f907cd0 100644 --- a/hack/e2e/common/eventing/publisher.go +++ b/hack/e2e/common/eventing/publisher.go @@ -116,7 +116,8 @@ func (p *Publisher) SendLegacyEvent(source, eventType, payload string) error { func (p *Publisher) SendCloudEvent(event *cloudevents.Event, encoding binding.Encoding) error { newCtx := context.Background() ctx := cloudevents.ContextWithTarget(newCtx, p.PublishEndpoint()) - //nolint:exhaustive // we only support the two checked encodings. Every other encoding will result in an error. + + //nolint:exhaustive // we only support binary and structured encoding. switch encoding { case binding.EncodingBinary: { diff --git a/internal/controller/errors/skip.go b/internal/controller/errors/skip.go index ff14b0a1e..f24bba40a 100644 --- a/internal/controller/errors/skip.go +++ b/internal/controller/errors/skip.go @@ -12,7 +12,7 @@ func IsSkippable(err error) bool { if err == nil { return true } - _, ok := err.(skippable) //nolint:errorlint // here we do not want to check the chain + _, ok := err.(skippable) return ok } diff --git a/internal/controller/eventing/subscription/eventmesh/reconciler.go b/internal/controller/eventing/subscription/eventmesh/reconciler.go index 512aee393..4ff806b57 100644 --- a/internal/controller/eventing/subscription/eventmesh/reconciler.go +++ b/internal/controller/eventing/subscription/eventmesh/reconciler.go @@ -9,6 +9,7 @@ import ( "reflect" "time" + apigatewayv1beta1 "github.com/kyma-project/api-gateway/apis/gateway/v1beta1" pkgerrors "github.com/pkg/errors" "go.uber.org/zap" "golang.org/x/xerrors" @@ -25,7 +26,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" - apigatewayv1beta1 "github.com/kyma-project/api-gateway/apis/gateway/v1beta1" eventingv1alpha2 "github.com/kyma-project/eventing-manager/api/eventing/v1alpha2" controllererrors "github.com/kyma-project/eventing-manager/internal/controller/errors" "github.com/kyma-project/eventing-manager/internal/controller/events" @@ -144,21 +144,11 @@ func (r *Reconciler) Reconcile(ctx context.Context, req kctrl.Request) (kctrl.Re } // Validate subscription. - if validationErr := r.validate(ctx, sub); validationErr != nil { - // Update subscription status accordingly. - sub.Status.SetNotReady() - sub.Status.ClearTypes() - sub.Status.ClearBackend() - sub.Status.ClearConditions() - sub.Status.SetSubscriptionSpecValidCondition(validationErr) + if validationErr := r.handleSubscriptionValidation(ctx, sub); validationErr != nil { if updateErr := r.updateStatus(ctx, currentSubscription, sub, log); updateErr != nil { return kctrl.Result{}, errors.Join(validationErr, updateErr) } - return kctrl.Result{}, reconcile.TerminalError(validationErr) - } else { - var noError error = nil - sub.Status.SetSubscriptionSpecValidCondition(noError) } // sync APIRule for the desired subscription @@ -194,7 +184,22 @@ func (r *Reconciler) Reconcile(ctx context.Context, req kctrl.Request) (kctrl.Re return result, nil } -func (r *Reconciler) validate(ctx context.Context, subscription *eventingv1alpha2.Subscription) error { +func (r *Reconciler) handleSubscriptionValidation(ctx context.Context, desiredSubscription *eventingv1alpha2.Subscription) error { + if validationErr := r.validateSubscriptionSpec(ctx, desiredSubscription); validationErr != nil { + desiredSubscription.Status.SetNotReady() + desiredSubscription.Status.ClearTypes() + desiredSubscription.Status.ClearBackend() + desiredSubscription.Status.ClearConditions() + desiredSubscription.Status.SetSubscriptionSpecValidCondition(validationErr) + return reconcile.TerminalError(validationErr) + } + + var noError error = nil + desiredSubscription.Status.SetSubscriptionSpecValidCondition(noError) + return noError +} + +func (r *Reconciler) validateSubscriptionSpec(ctx context.Context, subscription *eventingv1alpha2.Subscription) error { if errList := subscription.ValidateSpec(); len(errList) > 0 { return errors.Join(errList.ToAggregate()) } diff --git a/internal/controller/eventing/subscription/eventmesh/reconciler_internal_integration_test.go b/internal/controller/eventing/subscription/eventmesh/reconciler_internal_integration_test.go index fb99d1b6c..0171d0d6a 100644 --- a/internal/controller/eventing/subscription/eventmesh/reconciler_internal_integration_test.go +++ b/internal/controller/eventing/subscription/eventmesh/reconciler_internal_integration_test.go @@ -6,6 +6,8 @@ import ( "testing" "time" + apigatewayv1beta1 "github.com/kyma-project/api-gateway/apis/gateway/v1beta1" + kymalogger "github.com/kyma-project/kyma/common/logging/logger" "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -21,7 +23,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client/fake" "sigs.k8s.io/controller-runtime/pkg/reconcile" - apigatewayv1beta1 "github.com/kyma-project/api-gateway/apis/gateway/v1beta1" eventingv1alpha2 "github.com/kyma-project/eventing-manager/api/eventing/v1alpha2" "github.com/kyma-project/eventing-manager/pkg/backend/cleaner" "github.com/kyma-project/eventing-manager/pkg/backend/eventmesh" @@ -36,7 +37,6 @@ import ( "github.com/kyma-project/eventing-manager/pkg/object" "github.com/kyma-project/eventing-manager/test/utils" eventingtesting "github.com/kyma-project/eventing-manager/testing" - kymalogger "github.com/kyma-project/kyma/common/logging/logger" ) // TestReconciler_Reconcile tests the return values of the Reconcile() method of the reconciler. diff --git a/internal/controller/eventing/subscription/eventmesh/test/reconciler_integration_test.go b/internal/controller/eventing/subscription/eventmesh/test/reconciler_integration_test.go index 97af2c608..4f65d09de 100644 --- a/internal/controller/eventing/subscription/eventmesh/test/reconciler_integration_test.go +++ b/internal/controller/eventing/subscription/eventmesh/test/reconciler_integration_test.go @@ -9,6 +9,7 @@ import ( "testing" "time" + apigatewayv1beta1 "github.com/kyma-project/api-gateway/apis/gateway/v1beta1" "github.com/onsi/gomega" gomegatypes "github.com/onsi/gomega/types" "github.com/stretchr/testify/assert" @@ -16,7 +17,6 @@ import ( kcorev1 "k8s.io/api/core/v1" kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - apigatewayv1beta1 "github.com/kyma-project/api-gateway/apis/gateway/v1beta1" eventingv1alpha2 "github.com/kyma-project/eventing-manager/api/eventing/v1alpha2" emstypes "github.com/kyma-project/eventing-manager/pkg/ems/api/events/types" "github.com/kyma-project/eventing-manager/pkg/object" diff --git a/internal/controller/eventing/subscription/eventmesh/test/utils.go b/internal/controller/eventing/subscription/eventmesh/test/utils.go index e7ef6414a..0b0837324 100644 --- a/internal/controller/eventing/subscription/eventmesh/test/utils.go +++ b/internal/controller/eventing/subscription/eventmesh/test/utils.go @@ -1,4 +1,3 @@ -//nolint:gosec //this is just a test, and security issues found here will not result in code used in a prod environment package test import ( @@ -13,6 +12,8 @@ import ( "github.com/avast/retry-go/v3" "github.com/go-logr/zapr" + apigatewayv1beta1 "github.com/kyma-project/api-gateway/apis/gateway/v1beta1" + kymalogger "github.com/kyma-project/kyma/common/logging/logger" "github.com/stretchr/testify/require" kcorev1 "k8s.io/api/core/v1" kerrors "k8s.io/apimachinery/pkg/api/errors" @@ -29,7 +30,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/metrics/server" - apigatewayv1beta1 "github.com/kyma-project/api-gateway/apis/gateway/v1beta1" eventingv1alpha2 "github.com/kyma-project/eventing-manager/api/eventing/v1alpha2" subscriptioncontrollereventmesh "github.com/kyma-project/eventing-manager/internal/controller/eventing/subscription/eventmesh" "github.com/kyma-project/eventing-manager/pkg/backend/cleaner" @@ -45,7 +45,6 @@ import ( "github.com/kyma-project/eventing-manager/pkg/utils" testutils "github.com/kyma-project/eventing-manager/test/utils" eventingtesting "github.com/kyma-project/eventing-manager/testing" - kymalogger "github.com/kyma-project/kyma/common/logging/logger" ) type eventMeshTestEnsemble struct { @@ -287,11 +286,6 @@ func ensureK8sResourceCreated(ctx context.Context, t *testing.T, obj client.Obje require.NoError(t, emTestEnsemble.k8sClient.Create(ctx, obj)) } -func ensureK8sResourceNotCreated(ctx context.Context, t *testing.T, obj client.Object, err error) { - t.Helper() - require.Equal(t, emTestEnsemble.k8sClient.Create(ctx, obj), err) -} - func ensureK8sResourceDeleted(ctx context.Context, t *testing.T, obj client.Object) { t.Helper() require.NoError(t, emTestEnsemble.k8sClient.Delete(ctx, obj)) diff --git a/internal/controller/eventing/subscription/eventmesh/testwebhookauth/utils.go b/internal/controller/eventing/subscription/eventmesh/testwebhookauth/utils.go index 45d6d0263..30bb7adb6 100644 --- a/internal/controller/eventing/subscription/eventmesh/testwebhookauth/utils.go +++ b/internal/controller/eventing/subscription/eventmesh/testwebhookauth/utils.go @@ -12,20 +12,6 @@ import ( "github.com/avast/retry-go/v3" "github.com/go-logr/zapr" apigatewayv1beta1 "github.com/kyma-project/api-gateway/apis/gateway/v1beta1" - eventingv1alpha2 "github.com/kyma-project/eventing-manager/api/eventing/v1alpha2" - subscriptioncontrollereventmesh "github.com/kyma-project/eventing-manager/internal/controller/eventing/subscription/eventmesh" - "github.com/kyma-project/eventing-manager/pkg/backend/cleaner" - backendeventmesh "github.com/kyma-project/eventing-manager/pkg/backend/eventmesh" - "github.com/kyma-project/eventing-manager/pkg/backend/metrics" - "github.com/kyma-project/eventing-manager/pkg/backend/sink" - backendutils "github.com/kyma-project/eventing-manager/pkg/backend/utils" - emstypes "github.com/kyma-project/eventing-manager/pkg/ems/api/events/types" - "github.com/kyma-project/eventing-manager/pkg/env" - "github.com/kyma-project/eventing-manager/pkg/featureflags" - "github.com/kyma-project/eventing-manager/pkg/logger" - "github.com/kyma-project/eventing-manager/pkg/utils" - testutils "github.com/kyma-project/eventing-manager/test/utils" - eventingtesting "github.com/kyma-project/eventing-manager/testing" kymalogger "github.com/kyma-project/kyma/common/logging/logger" "github.com/stretchr/testify/require" kcorev1 "k8s.io/api/core/v1" @@ -41,6 +27,21 @@ import ( kctrllog "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/metrics/server" + + eventingv1alpha2 "github.com/kyma-project/eventing-manager/api/eventing/v1alpha2" + subscriptioncontrollereventmesh "github.com/kyma-project/eventing-manager/internal/controller/eventing/subscription/eventmesh" + "github.com/kyma-project/eventing-manager/pkg/backend/cleaner" + backendeventmesh "github.com/kyma-project/eventing-manager/pkg/backend/eventmesh" + "github.com/kyma-project/eventing-manager/pkg/backend/metrics" + "github.com/kyma-project/eventing-manager/pkg/backend/sink" + backendutils "github.com/kyma-project/eventing-manager/pkg/backend/utils" + emstypes "github.com/kyma-project/eventing-manager/pkg/ems/api/events/types" + "github.com/kyma-project/eventing-manager/pkg/env" + "github.com/kyma-project/eventing-manager/pkg/featureflags" + "github.com/kyma-project/eventing-manager/pkg/logger" + "github.com/kyma-project/eventing-manager/pkg/utils" + testutils "github.com/kyma-project/eventing-manager/test/utils" + eventingtesting "github.com/kyma-project/eventing-manager/testing" ) type eventMeshTestEnsemble struct { diff --git a/internal/controller/eventing/subscription/jetstream/reconciler.go b/internal/controller/eventing/subscription/jetstream/reconciler.go index 58b7a1b2c..60578080a 100644 --- a/internal/controller/eventing/subscription/jetstream/reconciler.go +++ b/internal/controller/eventing/subscription/jetstream/reconciler.go @@ -131,33 +131,17 @@ func (r *Reconciler) Reconcile(ctx context.Context, req kctrl.Request) (kctrl.Re } // Validate subscription. - if validationErr := r.validate(ctx, desiredSubscription); validationErr != nil { + if validationErr := r.handleSubscriptionValidation(ctx, desiredSubscription); validationErr != nil { if errors.Is(validationErr, sink.ErrSinkValidationFailed) { if deleteErr := r.Backend.DeleteSubscriptionsOnly(desiredSubscription); deleteErr != nil { - r.namedLogger().Errorw( - "Failed to delete JetStream subscriptions", - "namespace", desiredSubscription.Namespace, - "name", desiredSubscription.Name, - "error", deleteErr, - ) + log.Errorw("Failed to delete JetStream subscriptions", "error", deleteErr) return kctrl.Result{}, deleteErr } } - - // Update subscription status accordingly. - desiredSubscription.Status.SetNotReady() - desiredSubscription.Status.ClearTypes() - desiredSubscription.Status.ClearBackend() - desiredSubscription.Status.ClearConditions() - desiredSubscription.Status.SetSubscriptionSpecValidCondition(validationErr) if updateErr := r.updateSubscriptionStatus(ctx, desiredSubscription, log); updateErr != nil { return kctrl.Result{}, errors.Join(validationErr, updateErr) } - - return kctrl.Result{}, reconcile.TerminalError(validationErr) - } else { - var noError error = nil - desiredSubscription.Status.SetSubscriptionSpecValidCondition(noError) + return kctrl.Result{}, validationErr } // update the cleanEventTypes and config values in the subscription status, if changed @@ -187,7 +171,22 @@ func (r *Reconciler) Reconcile(ctx context.Context, req kctrl.Request) (kctrl.Re return kctrl.Result{}, r.syncSubscriptionStatus(ctx, desiredSubscription, nil, log) } -func (r *Reconciler) validate(ctx context.Context, subscription *eventingv1alpha2.Subscription) error { +func (r *Reconciler) handleSubscriptionValidation(ctx context.Context, desiredSubscription *eventingv1alpha2.Subscription) error { + if validationErr := r.validateSubscriptionSpec(ctx, desiredSubscription); validationErr != nil { + desiredSubscription.Status.SetNotReady() + desiredSubscription.Status.ClearTypes() + desiredSubscription.Status.ClearBackend() + desiredSubscription.Status.ClearConditions() + desiredSubscription.Status.SetSubscriptionSpecValidCondition(validationErr) + return reconcile.TerminalError(validationErr) + } + + var noError error = nil + desiredSubscription.Status.SetSubscriptionSpecValidCondition(noError) + return noError +} + +func (r *Reconciler) validateSubscriptionSpec(ctx context.Context, subscription *eventingv1alpha2.Subscription) error { if errList := subscription.ValidateSpec(); len(errList) > 0 { return errors.Join(errList.ToAggregate()) } diff --git a/internal/controller/eventing/subscription/jetstream/reconciler_internal_unit_test.go b/internal/controller/eventing/subscription/jetstream/reconciler_internal_unit_test.go index 5e9b2df07..b713db957 100644 --- a/internal/controller/eventing/subscription/jetstream/reconciler_internal_unit_test.go +++ b/internal/controller/eventing/subscription/jetstream/reconciler_internal_unit_test.go @@ -4,6 +4,7 @@ import ( "context" "testing" + kymalogger "github.com/kyma-project/kyma/common/logging/logger" "github.com/pkg/errors" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" @@ -27,7 +28,6 @@ import ( "github.com/kyma-project/eventing-manager/pkg/env" "github.com/kyma-project/eventing-manager/pkg/logger" eventingtesting "github.com/kyma-project/eventing-manager/testing" - kymalogger "github.com/kyma-project/kyma/common/logging/logger" ) const ( diff --git a/internal/controller/eventing/subscription/jetstream/test_utils_test.go b/internal/controller/eventing/subscription/jetstream/test_utils_test.go index e1bf154f4..ffba32e1c 100644 --- a/internal/controller/eventing/subscription/jetstream/test_utils_test.go +++ b/internal/controller/eventing/subscription/jetstream/test_utils_test.go @@ -9,6 +9,7 @@ import ( "time" "github.com/avast/retry-go/v3" + kymalogger "github.com/kyma-project/kyma/common/logging/logger" natsioserver "github.com/nats-io/nats-server/v2/server" "github.com/onsi/gomega" gomegatypes "github.com/onsi/gomega/types" @@ -36,7 +37,6 @@ import ( "github.com/kyma-project/eventing-manager/pkg/env" "github.com/kyma-project/eventing-manager/pkg/logger" eventingtesting "github.com/kyma-project/eventing-manager/testing" - kymalogger "github.com/kyma-project/kyma/common/logging/logger" ) const ( @@ -395,7 +395,6 @@ func StartTestEnv(ens *Ensemble) error { } }), ) - if err != nil { return err } diff --git a/internal/controller/operator/eventing/eventmesh_test.go b/internal/controller/operator/eventing/eventmesh_test.go index cf0e07f21..92caffcc2 100644 --- a/internal/controller/operator/eventing/eventmesh_test.go +++ b/internal/controller/operator/eventing/eventmesh_test.go @@ -309,7 +309,7 @@ func Test_reconcileEventMeshSubManager(t *testing.T) { // then if testcase.wantError != nil { require.Error(t, err) - require.ErrorAs(t, err, &testcase.wantError) + require.EqualError(t, err, testcase.wantError.Error()) } else { require.NoError(t, err) require.NotNil(t, testEnv.Reconciler.eventMeshSubManager) diff --git a/internal/controller/operator/eventing/integrationtests/controller/integration_test.go b/internal/controller/operator/eventing/integrationtests/controller/integration_test.go index 2e822a32d..9042aae6b 100644 --- a/internal/controller/operator/eventing/integrationtests/controller/integration_test.go +++ b/internal/controller/operator/eventing/integrationtests/controller/integration_test.go @@ -8,6 +8,8 @@ import ( "strings" "testing" + natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + natstestutils "github.com/kyma-project/nats-manager/testutils" "github.com/onsi/gomega" gomegatypes "github.com/onsi/gomega/types" "github.com/pkg/errors" @@ -27,8 +29,6 @@ import ( "github.com/kyma-project/eventing-manager/test/matchers" "github.com/kyma-project/eventing-manager/test/utils" testutilsintegration "github.com/kyma-project/eventing-manager/test/utils/integration" - natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" - natstestutils "github.com/kyma-project/nats-manager/testutils" ) const ( @@ -343,7 +343,7 @@ func Test_ReconcileSameEventingCR(t *testing.T) { // Ensure reconciling the same Eventing CR multiple times does not update the EPP deployment. const runs = 3 resourceVersionBefore := eppDeployment.ObjectMeta.ResourceVersion - for r := 0; r < runs; r++ { + for r := range runs { // when runID := fmt.Sprintf("run-%d", r) diff --git a/internal/controller/operator/eventing/nats_test.go b/internal/controller/operator/eventing/nats_test.go index cf600615d..4fda2e43a 100644 --- a/internal/controller/operator/eventing/nats_test.go +++ b/internal/controller/operator/eventing/nats_test.go @@ -580,7 +580,7 @@ func Test_UpdateNatsConfig(t *testing.T) { // then require.Equal(t, testcase.expectedError, err) - require.Equal(t, testcase.expectedConfig, testcase.expectedConfig) + require.Equal(t, testcase.expectedConfig, natsConfig) }) } } diff --git a/pkg/backend/cleaner/eventmesh.go b/pkg/backend/cleaner/eventmesh.go index 078d31e42..9d15940e1 100644 --- a/pkg/backend/cleaner/eventmesh.go +++ b/pkg/backend/cleaner/eventmesh.go @@ -44,7 +44,7 @@ func (c *EventMeshCleaner) getMergedSegments(eventType string) string { if totalSegments > maxEventMeshSegmentsLimit { combinedSegment := "" // combine the first n-2 segments without dots "." - for i := 0; i < totalSegments-2; i++ { + for i := range totalSegments - 2 { combinedSegment += segments[i] } // append the last two segment with preceding dots "." diff --git a/pkg/backend/jetstream/config_internal_unit_test.go b/pkg/backend/jetstream/config_internal_unit_test.go index 23ab296d5..7f3a48985 100644 --- a/pkg/backend/jetstream/config_internal_unit_test.go +++ b/pkg/backend/jetstream/config_internal_unit_test.go @@ -64,7 +64,7 @@ func TestUnitValidate_For_Errors(t *testing.T) { func fixtureStreamNameTooLong() string { b := strings.Builder{} - for i := 0; i < (jsMaxStreamNameLength + 1); i++ { + for range jsMaxStreamNameLength + 1 { b.WriteString("a") } streamName := b.String() diff --git a/pkg/backend/jetstream/jetstream_integration_test.go b/pkg/backend/jetstream/jetstream_integration_test.go index d6ab7eca1..e09c02190 100644 --- a/pkg/backend/jetstream/jetstream_integration_test.go +++ b/pkg/backend/jetstream/jetstream_integration_test.go @@ -158,11 +158,11 @@ func TestMultipleJSSubscriptionsToSameEvent(t *testing.T) { types.ContentModeBinary), ) // Check for the 3 events that should be received by the subscriber - for i := 0; i < len(subs); i++ { + for range len(subs) { require.NoError(t, subscriber.CheckEvent(eventingtesting.CloudEventData)) } // Delete all 3 subscription - for i := 0; i < len(subs); i++ { + for i := range len(subs) { require.NoError(t, jsBackend.DeleteSubscription(subs[i])) } // Check if all subscriptions are deleted in NATS diff --git a/pkg/backend/sink/validator.go b/pkg/backend/sink/validator.go index fcc5e6439..1682abebd 100644 --- a/pkg/backend/sink/validator.go +++ b/pkg/backend/sink/validator.go @@ -41,9 +41,7 @@ func NewValidator(client client.Client, recorder record.EventRecorder) Validator } func (s defaultSinkValidator) Validate(ctx context.Context, subscription *v1alpha2.Subscription) error { - var ( - svcNs, svcName string - ) + var svcNs, svcName string if _, subDomains, err := utils.GetSinkData(subscription.Spec.Sink); err != nil { return err diff --git a/pkg/k8s/client.go b/pkg/k8s/client.go index 81d4cae23..a8c63720f 100644 --- a/pkg/k8s/client.go +++ b/pkg/k8s/client.go @@ -5,6 +5,7 @@ import ( "errors" "strings" + natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" istiopkgsecurityv1beta1 "istio.io/client-go/pkg/apis/security/v1beta1" kappsv1 "k8s.io/api/apps/v1" kcorev1 "k8s.io/api/core/v1" @@ -20,7 +21,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" eventingv1alpha2 "github.com/kyma-project/eventing-manager/api/eventing/v1alpha2" - natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" ) func NatsGVK() schema.GroupVersionResource { diff --git a/pkg/utils/utils_unit_test.go b/pkg/utils/utils_unit_test.go index b3c4edf95..336c7d140 100644 --- a/pkg/utils/utils_unit_test.go +++ b/pkg/utils/utils_unit_test.go @@ -138,7 +138,7 @@ func TestGetRandSuffix(t *testing.T) { totalExecutions := 10 lengthOfRandomSuffix := 6 results := make(map[string]bool) - for i := 0; i < totalExecutions; i++ { + for range totalExecutions { result := GetRandString(lengthOfRandomSuffix) if _, ok := results[result]; ok { t.Fatalf("generated string already exists: %s", result) diff --git a/pkg/watcher/watcher.go b/pkg/watcher/watcher.go index 7e7feed5a..ad8cfc35e 100644 --- a/pkg/watcher/watcher.go +++ b/pkg/watcher/watcher.go @@ -60,7 +60,6 @@ func (w *ResourceWatcher) Start() { UpdateFunc: w.updateFunc, DeleteFunc: w.deleteFunc, }) - if err != nil { runtime.HandleError(err) } diff --git a/test/utils/integration/integration.go b/test/utils/integration/integration.go index ba0876324..23ad01200 100644 --- a/test/utils/integration/integration.go +++ b/test/utils/integration/integration.go @@ -12,6 +12,8 @@ import ( "github.com/avast/retry-go/v3" "github.com/go-logr/zapr" + natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + natstestutils "github.com/kyma-project/nats-manager/testutils" "github.com/onsi/gomega" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" @@ -49,8 +51,6 @@ import ( submgrmocks "github.com/kyma-project/eventing-manager/pkg/subscriptionmanager/mocks" "github.com/kyma-project/eventing-manager/test" testutils "github.com/kyma-project/eventing-manager/test/utils" - natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" - natstestutils "github.com/kyma-project/nats-manager/testutils" ) const ( @@ -310,7 +310,7 @@ func (env TestEnvironment) TearDown() error { var err error sleepTime := 1 * time.Second const retries = 20 - for i := 0; i < retries; i++ { + for range retries { if err = env.EnvTestInstance.Stop(); err == nil { break } diff --git a/testing/eventmeshmock.go b/testing/eventmeshmock.go index b5d7a15c9..06a2599c7 100644 --- a/testing/eventmeshmock.go +++ b/testing/eventmeshmock.go @@ -208,7 +208,7 @@ func (m *EventMeshMock) handleMessaging() func(w http.ResponseWriter, r *http.Re // extract get request key from /messaging/events/subscriptions/%s/state key := strings.TrimSuffix(r.URL.Path, "/state") - for i := 0; i < 3; i++ { + for i := range 3 { err := m.UpdateStateResponse(w, key, state) if err == nil { break