From 6acf1db148d1539c28c42a3337de69863061e4c4 Mon Sep 17 00:00:00 2001 From: Luca Burgazzoli Date: Wed, 21 Aug 2024 18:06:07 +0200 Subject: [PATCH] chore: update golangci-lint to v1.60.2, fix misleading test (#1195) * chore: update golangci-lint to v1.60.2 Signed-off-by: Luca Burgazzoli * chore: rework UpdateComponentReconcile test --------- Signed-off-by: Luca Burgazzoli --- .github/workflows/linter.yaml | 5 ++- Makefile | 2 +- tests/e2e/dsc_creation_test.go | 66 ++++++++++++++++++---------------- 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/.github/workflows/linter.yaml b/.github/workflows/linter.yaml index 3d40b46d66c..4df641cb6b1 100644 --- a/.github/workflows/linter.yaml +++ b/.github/workflows/linter.yaml @@ -20,8 +20,7 @@ jobs: with: go-version-file: go.mod - name: golangci-lint - uses: golangci/golangci-lint-action@v4 + uses: golangci/golangci-lint-action@v6 with: - version: v1.59.1 - skip-cache: true + version: v1.60.2 args: --timeout 5m0s diff --git a/Makefile b/Makefile index 3c86a2d5539..f85e0f29806 100644 --- a/Makefile +++ b/Makefile @@ -68,7 +68,7 @@ YQ ?= $(LOCALBIN)/yq KUSTOMIZE_VERSION ?= v5.0.2 CONTROLLER_GEN_VERSION ?= v0.9.2 OPERATOR_SDK_VERSION ?= v1.31.0 -GOLANGCI_LINT_VERSION ?= v1.59.1 +GOLANGCI_LINT_VERSION ?= v1.60.2 YQ_VERSION ?= v4.12.2 # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. ENVTEST_K8S_VERSION = 1.24.2 diff --git a/tests/e2e/dsc_creation_test.go b/tests/e2e/dsc_creation_test.go index 47c97881e4b..b2fbe7966dc 100644 --- a/tests/e2e/dsc_creation_test.go +++ b/tests/e2e/dsc_creation_test.go @@ -194,7 +194,7 @@ func (tc *testContext) requireInstalled(t *testing.T, gvk schema.GroupVersionKin err := tc.customClient.List(tc.ctx, list) require.NoErrorf(t, err, "Could not get %s list", gvk.Kind) - require.NotEmptyf(t, len(list.Items), "%s has not been installed", gvk.Kind) + require.NotEmptyf(t, list.Items, "%s has not been installed", gvk.Kind) } func (tc *testContext) testDuplication(t *testing.T, gvk schema.GroupVersionKind, o any) { @@ -433,37 +433,41 @@ func (tc *testContext) testUpdateComponentReconcile() error { if err != nil { return err } - if len(appDeployments.Items) != 0 { - testDeployment := appDeployments.Items[0] - expectedReplica := 3 - patchedReplica := &autoscalingv1.Scale{ - ObjectMeta: metav1.ObjectMeta{ - Name: testDeployment.Name, - Namespace: testDeployment.Namespace, - }, - Spec: autoscalingv1.ScaleSpec{ - Replicas: 3, - }, - Status: autoscalingv1.ScaleStatus{}, - } - updatedDep, err := tc.kubeClient.AppsV1().Deployments(tc.applicationsNamespace).UpdateScale(tc.ctx, testDeployment.Name, patchedReplica, metav1.UpdateOptions{}) - if err != nil { - return fmt.Errorf("error patching component resources : %w", err) - } - if updatedDep.Spec.Replicas != patchedReplica.Spec.Replicas { - return fmt.Errorf("failed to patch replicas : expect to be %v but got %v", patchedReplica.Spec.Replicas, updatedDep.Spec.Replicas) - } - // Sleep for 40 seconds to allow the operator to reconcile - // we expect it should not revert back to original value because of AllowList - time.Sleep(4 * tc.resourceRetryInterval) - reconciledDep, err := tc.kubeClient.AppsV1().Deployments(tc.applicationsNamespace).Get(tc.ctx, testDeployment.Name, metav1.GetOptions{}) - if err != nil { - return fmt.Errorf("error getting component resource after reconcile: %w", err) - } - if *reconciledDep.Spec.Replicas != int32(expectedReplica) { - return fmt.Errorf("failed to revert back replicas : expect to be %v but got %v", expectedReplica, *reconciledDep.Spec.Replicas) - } + if len(appDeployments.Items) != 1 { + return fmt.Errorf("error getting deployment for component %s", tc.testDsc.Spec.Components.Dashboard.GetComponentName()) + } + + const expectedReplica int32 = 3 + + testDeployment := appDeployments.Items[0] + patchedReplica := &autoscalingv1.Scale{ + ObjectMeta: metav1.ObjectMeta{ + Name: testDeployment.Name, + Namespace: testDeployment.Namespace, + }, + Spec: autoscalingv1.ScaleSpec{ + Replicas: expectedReplica, + }, + Status: autoscalingv1.ScaleStatus{}, + } + updatedDep, err := tc.kubeClient.AppsV1().Deployments(tc.applicationsNamespace).UpdateScale(tc.ctx, testDeployment.Name, patchedReplica, metav1.UpdateOptions{}) + if err != nil { + return fmt.Errorf("error patching component resources : %w", err) + } + if updatedDep.Spec.Replicas != patchedReplica.Spec.Replicas { + return fmt.Errorf("failed to patch replicas : expect to be %v but got %v", patchedReplica.Spec.Replicas, updatedDep.Spec.Replicas) + } + + // Sleep for 40 seconds to allow the operator to reconcile + // we expect it should not revert back to original value because of AllowList + time.Sleep(4 * tc.resourceRetryInterval) + reconciledDep, err := tc.kubeClient.AppsV1().Deployments(tc.applicationsNamespace).Get(tc.ctx, testDeployment.Name, metav1.GetOptions{}) + if err != nil { + return fmt.Errorf("error getting component resource after reconcile: %w", err) + } + if *reconciledDep.Spec.Replicas != expectedReplica { + return fmt.Errorf("failed to revert back replicas : expect to be %v but got %v", expectedReplica, *reconciledDep.Spec.Replicas) } return nil