From 386e15e46f384b43f92c8349c4b66bb52b1ff864 Mon Sep 17 00:00:00 2001 From: Benjamin Lindner <50365642+lindnerby@users.noreply.github.com> Date: Mon, 4 Mar 2024 08:47:34 +0100 Subject: [PATCH] chore: Bump golangci-lint make and action (#1346) * chore: Bump golangci-lint make and action * retrigger jobs * retrigger jobs * try referencing by full semver * adapt one arg sprints fmts * gofumpt with latest version * extract constant negating func * remove default rules --- .github/workflows/lint-golangci.yml | 4 ++-- .golangci.yaml | 1 - Makefile | 2 +- cmd/main.go | 2 +- internal/controller/kyma_controller.go | 2 +- .../mandatory_modules_installation_controller.go | 2 +- internal/declarative/v2/reconciler.go | 2 +- internal/declarative/v2/ssa.go | 7 +------ internal/pkg/metrics/kyma.go | 2 +- pkg/img/parse.go | 2 +- pkg/remote/kyma_synchronization_context.go | 1 - pkg/remote/remote_catalog.go | 1 - pkg/testutils/klm.go | 1 - pkg/testutils/manifest.go | 2 +- pkg/watcher/skr_webhook_resources.go | 2 +- tests/e2e/ca_certificate_rotation_test.go | 3 +-- .../mandatory_modules_deletion_controller_test.go | 2 +- .../withwatcher/watcher_controller_helper_test.go | 5 ++--- tests/integration/declarative/declarative_test.go | 4 ++-- tests/integration/declarative/helper_test.go | 14 +++++++------- 20 files changed, 25 insertions(+), 36 deletions(-) diff --git a/.github/workflows/lint-golangci.yml b/.github/workflows/lint-golangci.yml index 29763e98f0..090d7d063e 100644 --- a/.github/workflows/lint-golangci.yml +++ b/.github/workflows/lint-golangci.yml @@ -15,7 +15,7 @@ jobs: go-version-file: 'go.mod' cache: false - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v4.0.0 with: - version: v1.55.0 + version: v1.56.2 args: --verbose diff --git a/.golangci.yaml b/.golangci.yaml index a45186600c..c501c217ea 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -29,7 +29,6 @@ linters-settings: - github.com/onsi/ginkgo/v2 - github.com/onsi/gomega revive: - enable-all-rules: false severity: error rules: - name: comment-spacings diff --git a/Makefile b/Makefile index d9187d622b..554c567635 100644 --- a/Makefile +++ b/Makefile @@ -154,7 +154,7 @@ GOLANG_CI_LINT = $(LOCALBIN)/golangci-lint ## Tool Versions KUSTOMIZE_VERSION ?= v5.1.1 CONTROLLER_TOOLS_VERSION ?= v0.13.0 -GOLANG_CI_LINT_VERSION ?= v1.55.0 +GOLANG_CI_LINT_VERSION ?= v1.56.2 .PHONY: kustomize kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. diff --git a/cmd/main.go b/cmd/main.go index 41a3df8a6f..1c15cea3a2 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -453,7 +453,7 @@ func dropStoredVersion(mgr manager.Manager, versionToBeRemoved string) { kcpClient, err := clientset.NewForConfig(cfg) if err != nil { setupLog.V(log.DebugLevel).Error(err, - fmt.Sprintf("unable to initialize client to remove %s", versionToBeRemoved)) + "unable to initialize client to remove "+versionToBeRemoved) } ctx := context.TODO() var crdList *apiextensionsv1.CustomResourceDefinitionList diff --git a/internal/controller/kyma_controller.go b/internal/controller/kyma_controller.go index ea0737f20a..e89f26a1df 100644 --- a/internal/controller/kyma_controller.go +++ b/internal/controller/kyma_controller.go @@ -114,7 +114,7 @@ func (r *KymaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl. status.InitConditions(kyma, r.SyncKymaEnabled(kyma), r.WatcherEnabled(kyma)) if kyma.SkipReconciliation() { - logger.V(log.DebugLevel).Info(fmt.Sprintf("skipping reconciliation for Kyma: %s", kyma.Name)) + logger.V(log.DebugLevel).Info("skipping reconciliation for Kyma: " + kyma.Name) return ctrl.Result{RequeueAfter: r.RequeueIntervals.Success}, nil } diff --git a/internal/controller/mandatory_modules_installation_controller.go b/internal/controller/mandatory_modules_installation_controller.go index 75e2f38b11..4769a1fd20 100644 --- a/internal/controller/mandatory_modules_installation_controller.go +++ b/internal/controller/mandatory_modules_installation_controller.go @@ -63,7 +63,7 @@ func (r *MandatoryModuleReconciler) Reconcile(ctx context.Context, req ctrl.Requ } if kyma.SkipReconciliation() { - logger.V(log.DebugLevel).Info(fmt.Sprintf("skipping mandatory modules reconciliation for Kyma: %s", kyma.Name)) + logger.V(log.DebugLevel).Info("skipping mandatory modules reconciliation for Kyma: " + kyma.Name) return ctrl.Result{RequeueAfter: r.RequeueIntervals.Success}, nil } diff --git a/internal/declarative/v2/reconciler.go b/internal/declarative/v2/reconciler.go index 732d92de28..74ba1227e4 100644 --- a/internal/declarative/v2/reconciler.go +++ b/internal/declarative/v2/reconciler.go @@ -376,7 +376,7 @@ func (r *Reconciler) checkTargetReadiness( } if crStateInfo.State == shared.StateProcessing { - waitingMsg := fmt.Sprintf("waiting for resources to become ready: %s", crStateInfo.Info) + waitingMsg := "waiting for resources to become ready: " + crStateInfo.Info r.Event(manifest, "Normal", "ResourceReadyCheck", waitingMsg) manifest.SetStatus(status.WithState(shared.StateProcessing).WithOperation(waitingMsg)) return ErrInstallationConditionRequiresUpdate diff --git a/internal/declarative/v2/ssa.go b/internal/declarative/v2/ssa.go index f354f2c9c8..ece96f3e7d 100644 --- a/internal/declarative/v2/ssa.go +++ b/internal/declarative/v2/ssa.go @@ -99,13 +99,8 @@ func (c *ConcurrentDefaultSSA) serverSideApply( ) { start := time.Now() logger := logf.FromContext(ctx, "owner", c.owner) - - logger.V(internal.TraceLogLevel).Info( - fmt.Sprintf("apply %s", resource.ObjectName()), - ) - + logger.V(internal.TraceLogLevel).Info("apply " + resource.ObjectName()) results <- c.serverSideApplyResourceInfo(ctx, resource) - logger.V(internal.TraceLogLevel).Info( fmt.Sprintf("apply %s finished", resource.ObjectName()), "time", time.Since(start), diff --git a/internal/pkg/metrics/kyma.go b/internal/pkg/metrics/kyma.go index 7391da0e57..58a0c00a9e 100644 --- a/internal/pkg/metrics/kyma.go +++ b/internal/pkg/metrics/kyma.go @@ -171,7 +171,7 @@ func (k *KymaMetrics) CleanupNonExistingKymaCrsMetrics(ctx context.Context, kcpC continue } if _, exists := kymaNames[currentKymaName]; !exists { - logs.FromContext(ctx).Info(fmt.Sprintf("Deleting a metric for non-existing Kyma: %s", currentKymaName)) + logs.FromContext(ctx).Info("Deleting a metric for non-existing Kyma: " + currentKymaName) k.KymaStateGauge.DeletePartialMatch(prometheus.Labels{ KymaNameLabel: currentKymaName, }) diff --git a/pkg/img/parse.go b/pkg/img/parse.go index 63d909a914..b5cbd2e51b 100644 --- a/pkg/img/parse.go +++ b/pkg/img/parse.go @@ -145,7 +145,7 @@ func getOCIRef( layerRef.Repo = fmt.Sprintf("%s/%s", repo.Name(), repoSubpath) layerRef.Name = descriptor.GetName() case genericocireg.OCIRegistryDigestMapping: - layerRef.Repo = fmt.Sprintf("%s/", repo.Name()) + layerRef.Repo = repo.Name() + "/" layerRef.Name = sha256sum(descriptor.GetName()) default: return nil, fmt.Errorf( diff --git a/pkg/remote/kyma_synchronization_context.go b/pkg/remote/kyma_synchronization_context.go index 795ef87f00..95ee9cd48c 100644 --- a/pkg/remote/kyma_synchronization_context.go +++ b/pkg/remote/kyma_synchronization_context.go @@ -157,7 +157,6 @@ func (c *KymaSynchronizationContext) CreateOrUpdateCRD(ctx context.Context, plur Name: fmt.Sprintf("%s.%s", plural, v1beta2.GroupVersion.Group), }, crd, ) - if err != nil { return fmt.Errorf("failed to get kyma CRDs on kcp: %w", err) } diff --git a/pkg/remote/remote_catalog.go b/pkg/remote/remote_catalog.go index 02e995ba99..a9bcf1922f 100644 --- a/pkg/remote/remote_catalog.go +++ b/pkg/remote/remote_catalog.go @@ -258,7 +258,6 @@ func (c *RemoteCatalog) CreateModuleTemplateCRDInRuntime(ctx context.Context, pl // name changes, this also has to be adjusted here. We can think of making this configurable later Name: fmt.Sprintf("%s.%s", plural, v1beta2.GroupVersion.Group), }, crd) - if err != nil { return fmt.Errorf("failed to get module template CRD from kcp: %w", err) } diff --git a/pkg/testutils/klm.go b/pkg/testutils/klm.go index 913972fdc9..3be5bc2343 100644 --- a/pkg/testutils/klm.go +++ b/pkg/testutils/klm.go @@ -48,7 +48,6 @@ func CheckKLMLogs(ctx context.Context, _, err = getPodLogs(ctx, runtimeConfig, runtimeClient, remoteNamespace, watcher.SkrResourceName, watcherPodContainer, logsSince) - if err != nil { return err } diff --git a/pkg/testutils/manifest.go b/pkg/testutils/manifest.go index 5a60fb9838..c6a4a3b4ca 100644 --- a/pkg/testutils/manifest.go +++ b/pkg/testutils/manifest.go @@ -333,7 +333,7 @@ func PushToRemoteOCIRegistry(server *httptest.Server, manifestFilePath, layerNam return err } if gotHash != digest { - return fmt.Errorf("has not equal to digest") + return errors.New("has not equal to digest") } return nil } diff --git a/pkg/watcher/skr_webhook_resources.go b/pkg/watcher/skr_webhook_resources.go index ac1a47c146..3e8cad7a06 100644 --- a/pkg/watcher/skr_webhook_resources.go +++ b/pkg/watcher/skr_webhook_resources.go @@ -84,7 +84,7 @@ func generateValidatingWebhookConfigFromWatchers(webhookObjKey, for _, watcher := range watchers { moduleName := watcher.GetModuleName() webhookName := fmt.Sprintf("%s.%s.%s", watcher.Namespace, watcher.Name, shared.OperatorGroup) - svcPath := fmt.Sprintf("/validate/%s", moduleName) + svcPath := "/validate/" + moduleName watchableResources := ResolveWebhookRuleResources(watcher.Spec.ResourceToWatch.Resource, watcher.Spec.Field) sideEffects := admissionregistrationv1.SideEffectClassNoneOnDryRun failurePolicy := admissionregistrationv1.Ignore diff --git a/tests/e2e/ca_certificate_rotation_test.go b/tests/e2e/ca_certificate_rotation_test.go index 99808fdf2b..cdd10e92f2 100644 --- a/tests/e2e/ca_certificate_rotation_test.go +++ b/tests/e2e/ca_certificate_rotation_test.go @@ -1,7 +1,6 @@ package e2e_test import ( - "fmt" "time" certmanagerv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1" @@ -28,7 +27,7 @@ var _ = Describe("CA Certificate Rotation", Ordered, func() { Context("Given KCP Cluster and rotated CA certificate", func() { kcpNamespacedSecretName := types.NamespacedName{ - Name: fmt.Sprintf("%s-webhook-tls", kyma.Name), + Name: kyma.Name + "-webhook-tls", Namespace: "istio-system", } diff --git a/tests/integration/controller/mandatorymodule/deletion/mandatory_modules_deletion_controller_test.go b/tests/integration/controller/mandatorymodule/deletion/mandatory_modules_deletion_controller_test.go index cdbce9a488..c727ddada1 100644 --- a/tests/integration/controller/mandatorymodule/deletion/mandatory_modules_deletion_controller_test.go +++ b/tests/integration/controller/mandatorymodule/deletion/mandatory_modules_deletion_controller_test.go @@ -153,5 +153,5 @@ func mandatoryModuleTemplateFinalizerExists(ctx context.Context, clnt client.Cli if controllerutil.ContainsFinalizer(&template, "operator.kyma-project.io/mandatory-module") { return nil } - return fmt.Errorf("ModuleTemplate does not contain mandatory finalizer") + return errors.New("ModuleTemplate does not contain mandatory finalizer") } diff --git a/tests/integration/controller/withwatcher/watcher_controller_helper_test.go b/tests/integration/controller/withwatcher/watcher_controller_helper_test.go index a4ba1a90d9..7063ec0487 100644 --- a/tests/integration/controller/withwatcher/watcher_controller_helper_test.go +++ b/tests/integration/controller/withwatcher/watcher_controller_helper_test.go @@ -3,7 +3,6 @@ package withwatcher_test import ( "context" "errors" - "fmt" "io" "os" @@ -173,11 +172,11 @@ func createWatcherCR(managerInstanceName string, statusOnly bool) *v1beta2.Watch Spec: v1beta2.WatcherSpec{ ServiceInfo: v1beta2.Service{ Port: 8082, - Name: fmt.Sprintf("%s-svc", managerInstanceName), + Name: managerInstanceName + "-svc", Namespace: apimetav1.NamespaceDefault, }, LabelsToWatch: map[string]string{ - fmt.Sprintf("%s-watchable", managerInstanceName): "true", + managerInstanceName + "-watchable": "true", }, ResourceToWatch: v1beta2.WatchableGVR{ Group: v1beta2.GroupVersionResource.Group, diff --git a/tests/integration/declarative/declarative_test.go b/tests/integration/declarative/declarative_test.go index e77cb76120..df100a0aca 100644 --- a/tests/integration/declarative/declarative_test.go +++ b/tests/integration/declarative/declarative_test.go @@ -77,7 +77,7 @@ var _ = Describe( var cfg *rest.Config var testClient client.Client BeforeAll(func() { - runID = fmt.Sprintf("run-%s", rand.String(4)) + runID = "run-" + rand.String(4) env, cfg = StartEnv() testClient = GetTestClient(cfg) ctx, cancel = context.WithCancel(context.TODO()) @@ -160,7 +160,7 @@ var _ = Describe("Test Manifest Reconciliation for module deletion", Ordered, fu var testClient client.Client const ocirefSynced = "sha256:synced" - runID := fmt.Sprintf("run-%s", rand.String(4)) + runID := "run-" + rand.String(4) obj := &declarativetest.TestAPI{Spec: declarativetest.TestAPISpec{ManifestName: "deletion-manifest"}} obj.SetLabels(k8slabels.Set{testRunLabel: runID}) obj.SetNamespace(customResourceNamespace.Name) diff --git a/tests/integration/declarative/helper_test.go b/tests/integration/declarative/helper_test.go index 708037b36d..8a1793735a 100644 --- a/tests/integration/declarative/helper_test.go +++ b/tests/integration/declarative/helper_test.go @@ -41,9 +41,7 @@ func (matcher *BeInStateMatcher) FailureMessage(actual interface{}) string { } func (matcher *BeInStateMatcher) NegatedFailureMessage(actual interface{}) string { - return format.Message( - actual, fmt.Sprintf("not %s", matcher.FailureMessage(actual)), - ) + return negateMessage(actual, matcher.FailureMessage(actual)) } func HaveConditionWithStatus( @@ -75,9 +73,7 @@ func (matcher *HaveConditionMatcher) FailureMessage(actual interface{}) string { } func (matcher *HaveConditionMatcher) NegatedFailureMessage(actual interface{}) string { - return format.Message( - actual, fmt.Sprintf("not %s", matcher.FailureMessage(actual)), - ) + return negateMessage(actual, matcher.FailureMessage(actual)) } func EventuallyDeclarativeStatusShould(ctx context.Context, key client.ObjectKey, testClient client.Client, @@ -144,5 +140,9 @@ func (matcher *SyncedResourcesExistingMatcher) FailureMessage(actual interface{} } func (matcher *SyncedResourcesExistingMatcher) NegatedFailureMessage(actual interface{}) string { - return format.Message(actual, fmt.Sprintf("not %s", matcher.FailureMessage(actual))) + return negateMessage(actual, matcher.FailureMessage(actual)) +} + +func negateMessage(actual interface{}, message string) string { + return format.Message(actual, "not "+message) }