Skip to content

Commit

Permalink
chore: update golangci-lint to v1.60.2, fix misleading test (opendata…
Browse files Browse the repository at this point in the history
…hub-io#1195)

* chore: update golangci-lint to v1.60.2

Signed-off-by: Luca Burgazzoli <[email protected]>

* chore: rework UpdateComponentReconcile test

---------

Signed-off-by: Luca Burgazzoli <[email protected]>
  • Loading branch information
lburgazzoli authored Aug 21, 2024
1 parent 14fdb89 commit 6acf1db
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 35 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/linter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
66 changes: 35 additions & 31 deletions tests/e2e/dsc_creation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6acf1db

Please sign in to comment.