From e405f2b4a14350d264a2c164c80cbd198b2972ce Mon Sep 17 00:00:00 2001 From: Jonathan West Date: Wed, 23 Jul 2025 10:48:03 -0400 Subject: [PATCH] Enable gosec/golangci-lint, then fix reported errors Signed-off-by: Jonathan West --- .github/workflows/codegen.yaml | 19 +++ .golangci.yml | 23 +++ Makefile | 35 ++++- cmd/main.go | 8 +- controllers/argocd/argocd_test.go | 4 +- .../argocd/openshift/clusterconfig_test.go | 17 +-- controllers/argocd/openshift/openshift.go | 18 ++- .../argocd/openshift/openshift_test.go | 10 +- controllers/argocd_controller_test.go | 3 +- controllers/argocd_metrics_controller_test.go | 14 +- controllers/consoleplugin.go | 16 +- controllers/consoleplugin_test.go | 140 +++++++++++------- controllers/gitopsservice_controller.go | 7 +- controllers/gitopsservice_controller_test.go | 24 +-- hack/upgrade-rollouts-manager/go.sum | 3 - hack/upgrade-rollouts-manager/main.go | 5 + test/e2e/argocd_route_test.go | 2 +- test/e2e/gitopsservice_test.go | 87 ++--------- test/e2e/suite_test.go | 15 -- test/helper/application_status.go | 22 +-- .../gitops_service_nondefault_test.go | 2 +- test/nondefaulte2e/suite_test.go | 27 ---- .../e2e/ginkgo/fixture/application/fixture.go | 6 +- .../e2e/ginkgo/fixture/argocd/fixture.go | 10 +- .../e2e/ginkgo/fixture/clusterrole/fixture.go | 8 +- .../fixture/clusterrolebinding/fixture.go | 8 +- .../fixture/clusterserviceversion/fixture.go | 3 +- .../e2e/ginkgo/fixture/configmap/fixture.go | 6 +- .../e2e/ginkgo/fixture/deployment/fixture.go | 20 +-- .../fixture/deploymentconfig/fixture.go | 11 +- test/openshift/e2e/ginkgo/fixture/fixture.go | 44 +++--- .../ginkgo/fixture/gitopsservice/fixture.go | 3 +- .../e2e/ginkgo/fixture/k8s/fixture.go | 6 +- .../e2e/ginkgo/fixture/namespace/fixture.go | 10 +- .../e2e/ginkgo/fixture/node/fixture.go | 6 +- .../notificationsconfiguration/fixture.go | 8 +- .../e2e/ginkgo/fixture/os/fixture.go | 4 +- .../fixture/persistentvolume/fixture.go | 6 +- .../e2e/ginkgo/fixture/pod/fixture.go | 6 +- .../e2e/ginkgo/fixture/role/fixture.go | 6 +- .../e2e/ginkgo/fixture/rolebinding/fixture.go | 6 +- .../e2e/ginkgo/fixture/route/fixture.go | 6 +- .../e2e/ginkgo/fixture/secret/fixture.go | 6 +- .../e2e/ginkgo/fixture/statefulset/fixture.go | 10 +- .../ginkgo/fixture/subscription/fixture.go | 3 +- .../e2e/ginkgo/fixture/utils/fixtureUtils.go | 3 +- ...1-001_alpha_to_beta_dex_conversion_test.go | 4 +- ..._alpha_to_beta_keycloak_conversion_test.go | 2 +- ...ha_to_beta_sso_conflict_conversion_test.go | 4 +- .../1-004_beta_to_alpha_conversion_test.go | 4 +- ...09_validate-manage-other-namespace_test.go | 4 +- .../1-012_validate-managed-by-chain_test.go | 2 +- .../1-057_validate_notifications_test.go | 2 +- .../1-064_validate_security_contexts_test.go | 15 +- ...redis_secure_comm_no_autotls_no_ha_test.go | 8 +- ...te_redis_secure_comm_no_autotls_ha_test.go | 8 +- ...ate_resource_customization_subkeys_test.go | 2 +- .../1-090_validate_permissions_test.go | 4 +- ...idate_appcontroller_initcontainers_test.go | 4 +- ...112_validate_server_initcontainers_test.go | 4 +- ...113_validate_appcontroller_sidecar_test.go | 2 +- .../1-114_validate_server_sidecar_test.go | 2 +- ...lidate-ootb-manage-other-namespace_test.go | 2 +- ..._validate_disable_default_instance_test.go | 2 +- .../1-028-validate_run_on_infra_test.go | 4 +- .../1-034_validate_custom_roles_test.go | 2 +- ...e_rolebinding_for_source_namespace_test.go | 6 +- .../sequential/1-071_validate_SCC_HA_test.go | 2 +- ...lidate_terminating_namespace_block_test.go | 2 +- ...alidate_default_argocd_consoleLink_test.go | 2 +- ...083_validate_apps_in_any_namespace_test.go | 2 +- ...date_handle_terminating_namespaces_test.go | 2 +- .../1-105_validate_label_selector_test.go | 2 +- ...-111_validate_default_argocd_route_test.go | 2 +- 74 files changed, 429 insertions(+), 378 deletions(-) create mode 100644 .golangci.yml diff --git a/.github/workflows/codegen.yaml b/.github/workflows/codegen.yaml index e4524d0e5..b763f6180 100644 --- a/.github/workflows/codegen.yaml +++ b/.github/workflows/codegen.yaml @@ -58,3 +58,22 @@ jobs: - name: Ensure there is no diff in manifests run: | git diff --ignore-matching-lines='.*createdAt:.*' --exit-code -- . + + gosec: + name: Ensure that code passes gosec and golint + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Setup Golang + uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + + - name: "Ensure code passes 'go-sec' - run 'make gosec' to identify issues" + run: | + make gosec + + - name: "Ensure code passes 'golangci-lint' - run 'make lint' to identify issues" + run: | + make lint diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 000000000..6b08446bb --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,23 @@ +version: "2" +linters: + enable: + - ginkgolinter # https://github.com/nunnatsa/ginkgolinter + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - third_party$ + - builtin$ + - examples$ + +formatters: + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/Makefile b/Makefile index 34cb9a662..0fbef505d 100644 --- a/Makefile +++ b/Makefile @@ -329,7 +329,6 @@ endif endif - # A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0). # These images MUST exist in a registry and be pull-able. BUNDLE_IMGS ?= $(BUNDLE_IMG) @@ -353,3 +352,37 @@ catalog-build: opm ## Build a catalog image. .PHONY: catalog-push catalog-push: ## Push a catalog image. $(MAKE) docker-push IMG=$(CATALOG_IMG) + + +.PHONY: gosec +gosec: go_sec + $(GO_SEC) --exclude-dir "hack/upgrade-rollouts-manager" ./... + +.PHONY: lint +lint: golangci_lint + $(GOLANGCI_LINT) --version + GOMAXPROCS=2 $(GOLANGCI_LINT) run --fix --verbose --timeout 300s + + +GO_SEC = $(shell pwd)/bin/gosec +go_sec: ## Download gosec locally if necessary. + $(call go-get-tool,$(GO_SEC),github.com/securego/gosec/v2/cmd/gosec@latest) + +GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint +golangci_lint: ## Download golangci-lint locally if necessary. + $(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest) + + +# go-get-tool will 'go install' any package $2 and install it to $1. +PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) +define go-get-tool +@[ -f $(1) ] || { \ +set -e ;\ +TMP_DIR=$$(mktemp -d) ;\ +cd $$TMP_DIR ;\ +go mod init tmp ;\ +echo "Downloading $(2)" ;\ +GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\ +rm -rf $$TMP_DIR ;\ +} +endef diff --git a/cmd/main.go b/cmd/main.go index 3e758ac00..97569ef35 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -47,7 +47,7 @@ import ( monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" crdv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" clientgoscheme "k8s.io/client-go/kubernetes/scheme" ctrl "sigs.k8s.io/controller-runtime" @@ -56,8 +56,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/webhook" - "github.com/argoproj-labs/argocd-operator/controllers/argocd" - pipelinesv1alpha1 "github.com/redhat-developer/gitops-operator/api/v1alpha1" "github.com/redhat-developer/gitops-operator/common" "github.com/redhat-developer/gitops-operator/controllers" @@ -69,7 +67,7 @@ import ( ) var ( - scheme = runtime.NewScheme() + scheme = k8sruntime.NewScheme() setupLog = ctrl.Log.WithName("setup") ) @@ -257,7 +255,7 @@ func main() { os.Exit(1) } - argocd.Register(openshift.ReconcilerHook) + argocdprovisioner.Register(openshift.ReconcilerHook) setupLog.Info("starting manager") if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil { diff --git a/controllers/argocd/argocd_test.go b/controllers/argocd/argocd_test.go index adca9f2a3..ef3c7a09b 100644 --- a/controllers/argocd/argocd_test.go +++ b/controllers/argocd/argocd_test.go @@ -74,7 +74,9 @@ func TestArgoCD(t *testing.T) { v1.ResourceCPU: resourcev1.MustParse("500m"), }, } - assert.DeepEqual(t, testArgoCD.Spec.Grafana.Resources, testGrafanaResources) + + //lint:ignore SA1019 known to be deprecated + assert.DeepEqual(t, testArgoCD.Spec.Grafana.Resources, testGrafanaResources) //nolint:staticcheck // SA1019: We must test deprecated fields. testHAResources := &v1.ResourceRequirements{ Requests: v1.ResourceList{ diff --git a/controllers/argocd/openshift/clusterconfig_test.go b/controllers/argocd/openshift/clusterconfig_test.go index 5bf0cde64..62f7c69c2 100644 --- a/controllers/argocd/openshift/clusterconfig_test.go +++ b/controllers/argocd/openshift/clusterconfig_test.go @@ -97,29 +97,18 @@ func makeTestDeployment() *appsv1.Deployment { } } -func makeTestRoleBinding() *rbacv1.RoleBinding { - return &rbacv1.RoleBinding{ - ObjectMeta: metav1.ObjectMeta{ - Name: testArgoCDName, - Namespace: testNamespace, - }, - Subjects: []rbacv1.Subject{}, - RoleRef: rbacv1.RoleRef{}, - } -} - func newStatefulSetWithSuffix(suffix string, component string, cr *argoapp.ArgoCD) *appsv1.StatefulSet { return newStatefulSetWithName(fmt.Sprintf("%s-%s", cr.Name, suffix), component, cr) } func newStatefulSetWithName(name string, component string, cr *argoapp.ArgoCD) *appsv1.StatefulSet { ss := newStatefulSet(cr) - ss.ObjectMeta.Name = name + ss.Name = name - lbls := ss.ObjectMeta.Labels + lbls := ss.Labels lbls[common.ArgoCDKeyName] = name lbls[common.ArgoCDKeyComponent] = component - ss.ObjectMeta.Labels = lbls + ss.Labels = lbls return ss } diff --git a/controllers/argocd/openshift/openshift.go b/controllers/argocd/openshift/openshift.go index 64b0f79f1..c946af110 100644 --- a/controllers/argocd/openshift/openshift.go +++ b/controllers/argocd/openshift/openshift.go @@ -31,15 +31,16 @@ func ReconcilerHook(cr *argoapp.ArgoCD, v interface{}, hint string) error { logv := log.WithValues("ArgoCD Namespace", cr.Namespace, "ArgoCD Name", cr.Name) switch o := v.(type) { case *rbacv1.ClusterRole: - if o.ObjectMeta.Name == argocd.GenerateUniqueResourceName("argocd-application-controller", cr) { + if o.Name == argocd.GenerateUniqueResourceName("argocd-application-controller", cr) { logv.Info("configuring openshift cluster config policy rules") o.Rules = policyRulesForClusterConfig() } case *appsv1.Deployment: - if o.ObjectMeta.Name == cr.ObjectMeta.Name+"-redis" { + switch o.Name { + case cr.Name + "-redis": logv.Info("configuring openshift redis") o.Spec.Template.Spec.Containers[0].Args = append(getArgsForRedhatRedis(), o.Spec.Template.Spec.Containers[0].Args...) - } else if o.ObjectMeta.Name == cr.ObjectMeta.Name+"-redis-ha-haproxy" { + case cr.Name + "-redis-ha-haproxy": logv.Info("configuring openshift redis haproxy") o.Spec.Template.Spec.Containers[0].Command = append(getCommandForRedhatRedisHaProxy(), o.Spec.Template.Spec.Containers[0].Command...) version := hint @@ -55,13 +56,14 @@ func ReconcilerHook(cr *argoapp.ArgoCD, v interface{}, hint string) error { } } case *appsv1.StatefulSet: - if o.ObjectMeta.Name == cr.ObjectMeta.Name+"-redis-ha-server" { + if o.Name == cr.Name+"-redis-ha-server" { logv.Info("configuring openshift redis-ha-server stateful set") for index := range o.Spec.Template.Spec.Containers { - if o.Spec.Template.Spec.Containers[index].Name == "redis" { + switch o.Spec.Template.Spec.Containers[index].Name { + case "redis": o.Spec.Template.Spec.Containers[index].Args = getArgsForRedhatHaRedisServer() o.Spec.Template.Spec.Containers[index].Command = []string{} - } else if o.Spec.Template.Spec.Containers[index].Name == "sentinel" { + case "sentinel": o.Spec.Template.Spec.Containers[index].Args = getArgsForRedhatHaRedisSentinel() o.Spec.Template.Spec.Containers[index].Command = []string{} } @@ -70,12 +72,12 @@ func ReconcilerHook(cr *argoapp.ArgoCD, v interface{}, hint string) error { o.Spec.Template.Spec.InitContainers[0].Command = []string{} } case *corev1.Secret: - if allowedNamespace(cr.ObjectMeta.Namespace, os.Getenv("ARGOCD_CLUSTER_CONFIG_NAMESPACES")) { + if allowedNamespace(cr.Namespace, os.Getenv("ARGOCD_CLUSTER_CONFIG_NAMESPACES")) { logv.Info("configuring cluster secret with empty namespaces to allow cluster resources") delete(o.Data, "namespaces") } case *rbacv1.Role: - if o.ObjectMeta.Name == cr.Name+"-"+"argocd-application-controller" { + if o.Name == cr.Name+"-"+"argocd-application-controller" { logv.Info("configuring policy rule for Application Controller") // can move this to somewhere common eventually, maybe init() diff --git a/controllers/argocd/openshift/openshift_test.go b/controllers/argocd/openshift/openshift_test.go index a0b2f6c0a..1a5031e74 100644 --- a/controllers/argocd/openshift/openshift_test.go +++ b/controllers/argocd/openshift/openshift_test.go @@ -107,13 +107,13 @@ func TestReconcileArgoCD_reconcileRedisDeployment(t *testing.T) { a := makeTestArgoCD() testDeployment := makeTestDeployment() - testDeployment.ObjectMeta.Name = a.Name + "-" + "redis" + testDeployment.Name = a.Name + "-" + "redis" want := append(getArgsForRedhatRedis(), testDeployment.Spec.Template.Spec.Containers[0].Args...) assert.NoError(t, ReconcilerHook(a, testDeployment, "")) assert.Equal(t, testDeployment.Spec.Template.Spec.Containers[0].Args, want) - testDeployment.ObjectMeta.Name = a.Name + "-" + "not-redis" + testDeployment.Name = a.Name + "-" + "not-redis" want = testDeployment.Spec.Template.Spec.Containers[0].Args assert.NoError(t, ReconcilerHook(a, testDeployment, "")) @@ -124,7 +124,7 @@ func TestReconcileArgoCD_reconcileRedisHaProxyDeployment(t *testing.T) { a := makeTestArgoCD() testDeployment := makeTestDeployment() - testDeployment.ObjectMeta.Name = a.Name + "-redis-ha-haproxy" + testDeployment.Name = a.Name + "-redis-ha-haproxy" testDeployment.Spec.Template.Spec.Containers[0].SecurityContext = &corev1.SecurityContext{ Capabilities: &corev1.Capabilities{}, } @@ -141,7 +141,7 @@ func TestReconcileArgoCD_reconcileRedisHaProxyDeployment(t *testing.T) { assert.Equal(t, wantc, *testDeployment.Spec.Template.Spec.Containers[0].SecurityContext.Capabilities) testDeployment = makeTestDeployment() - testDeployment.ObjectMeta.Name = a.Name + "-redis-ha-haproxy" + testDeployment.Name = a.Name + "-redis-ha-haproxy" testDeployment.Spec.Template.Spec.Containers[0].SecurityContext = &corev1.SecurityContext{ Capabilities: &corev1.Capabilities{}, } @@ -150,7 +150,7 @@ func TestReconcileArgoCD_reconcileRedisHaProxyDeployment(t *testing.T) { assert.Nil(t, testDeployment.Spec.Template.Spec.Containers[0].SecurityContext.Capabilities) testDeployment = makeTestDeployment() - testDeployment.ObjectMeta.Name = a.Name + "-" + "not-redis-ha-haproxy" + testDeployment.Name = a.Name + "-" + "not-redis-ha-haproxy" want = testDeployment.Spec.Template.Spec.Containers[0].Command assert.NoError(t, ReconcilerHook(a, testDeployment, "")) diff --git a/controllers/argocd_controller_test.go b/controllers/argocd_controller_test.go index 72124176a..6f7f178b6 100644 --- a/controllers/argocd_controller_test.go +++ b/controllers/argocd_controller_test.go @@ -118,7 +118,8 @@ func TestReconcile_delete_consolelink(t *testing.T) { t.Run(test.name, func(t *testing.T) { reconcileArgoCD, fakeClient := newFakeReconcileArgoCD(argoCDRoute, consoleLink) consoleLink := newConsoleLink("https://test.com", "Cluster Argo CD") - fakeClient.Create(context.TODO(), consoleLink) + err := fakeClient.Create(context.TODO(), consoleLink) + assert.NilError(t, err) if test.setEnvVarFunc != nil { test.setEnvVarFunc(t, test.envVar) diff --git a/controllers/argocd_metrics_controller_test.go b/controllers/argocd_metrics_controller_test.go index 2a262621f..6961ad876 100644 --- a/controllers/argocd_metrics_controller_test.go +++ b/controllers/argocd_metrics_controller_test.go @@ -223,8 +223,8 @@ func TestReconcile_add_service_monitors(t *testing.T) { assert.Assert(t, is.Len(serviceMonitor.OwnerReferences, 1)) assert.Equal(t, serviceMonitor.OwnerReferences[0].Kind, argocdKind) assert.Equal(t, serviceMonitor.OwnerReferences[0].Name, tc.instanceName) - assert.Equal(t, len(serviceMonitor.ObjectMeta.Labels), 1) - assert.Equal(t, serviceMonitor.ObjectMeta.Labels["release"], "prometheus-operator") + assert.Equal(t, len(serviceMonitor.Labels), 1) + assert.Equal(t, serviceMonitor.Labels["release"], "prometheus-operator") assert.Equal(t, len(serviceMonitor.Spec.Selector.MatchLabels), 1) assert.Equal(t, serviceMonitor.Spec.Selector.MatchLabels["app.kubernetes.io/name"], matchLabel) assert.Equal(t, len(serviceMonitor.Spec.Endpoints), 1) @@ -238,8 +238,8 @@ func TestReconcile_add_service_monitors(t *testing.T) { assert.Assert(t, is.Len(serviceMonitor.OwnerReferences, 1)) assert.Equal(t, serviceMonitor.OwnerReferences[0].Kind, argocdKind) assert.Equal(t, serviceMonitor.OwnerReferences[0].Name, tc.instanceName) - assert.Equal(t, len(serviceMonitor.ObjectMeta.Labels), 1) - assert.Equal(t, serviceMonitor.ObjectMeta.Labels["release"], "prometheus-operator") + assert.Equal(t, len(serviceMonitor.Labels), 1) + assert.Equal(t, serviceMonitor.Labels["release"], "prometheus-operator") assert.Equal(t, len(serviceMonitor.Spec.Selector.MatchLabels), 1) assert.Equal(t, serviceMonitor.Spec.Selector.MatchLabels["app.kubernetes.io/name"], matchLabel) assert.Equal(t, len(serviceMonitor.Spec.Endpoints), 1) @@ -253,8 +253,8 @@ func TestReconcile_add_service_monitors(t *testing.T) { assert.Assert(t, is.Len(serviceMonitor.OwnerReferences, 1)) assert.Equal(t, serviceMonitor.OwnerReferences[0].Kind, argocdKind) assert.Equal(t, serviceMonitor.OwnerReferences[0].Name, tc.instanceName) - assert.Equal(t, len(serviceMonitor.ObjectMeta.Labels), 1) - assert.Equal(t, serviceMonitor.ObjectMeta.Labels["release"], "prometheus-operator") + assert.Equal(t, len(serviceMonitor.Labels), 1) + assert.Equal(t, serviceMonitor.Labels["release"], "prometheus-operator") assert.Equal(t, len(serviceMonitor.Spec.Selector.MatchLabels), 1) assert.Equal(t, serviceMonitor.Spec.Selector.MatchLabels["app.kubernetes.io/name"], matchLabel) assert.Equal(t, len(serviceMonitor.Spec.Endpoints), 1) @@ -390,7 +390,7 @@ func TestReconciler_add_dashboard(t *testing.T) { err = r.Client.Get(context.TODO(), types.NamespacedName{Name: name, Namespace: dashboardNamespace}, dashboard) assert.NilError(t, err) - assert.Assert(t, dashboard.ObjectMeta.Labels["console.openshift.io/dashboard"] == "true") + assert.Assert(t, dashboard.Labels["console.openshift.io/dashboard"] == "true") assert.Assert(t, dashboard.Data[entry.Name()] == string(content)) } } diff --git a/controllers/consoleplugin.go b/controllers/consoleplugin.go index 08fe7784f..9add4e5cb 100644 --- a/controllers/consoleplugin.go +++ b/controllers/consoleplugin.go @@ -303,7 +303,7 @@ func (r *ReconcileGitopsService) reconcileDeployment(cr *pipelinesv1alpha1.Gitop } else { existingSpecTemplate := &existingPluginDeployment.Spec.Template newSpecTemplate := newPluginDeployment.Spec.Template - changed := !reflect.DeepEqual(existingPluginDeployment.ObjectMeta.Labels, newPluginDeployment.ObjectMeta.Labels) || + changed := !reflect.DeepEqual(existingPluginDeployment.Labels, newPluginDeployment.Labels) || !reflect.DeepEqual(existingPluginDeployment.Spec.Replicas, newPluginDeployment.Spec.Replicas) || !reflect.DeepEqual(existingPluginDeployment.Spec.Selector, newPluginDeployment.Spec.Selector) || !reflect.DeepEqual(existingSpecTemplate.Labels, newSpecTemplate.Labels) || @@ -317,7 +317,7 @@ func (r *ReconcileGitopsService) reconcileDeployment(cr *pipelinesv1alpha1.Gitop if changed { reqLogger.Info("Reconciling plugin deployment", "Namespace", existingPluginDeployment.Namespace, "Name", existingPluginDeployment.Name) - existingPluginDeployment.ObjectMeta.Labels = newPluginDeployment.ObjectMeta.Labels + existingPluginDeployment.Labels = newPluginDeployment.Labels existingPluginDeployment.Spec.Replicas = newPluginDeployment.Spec.Replicas existingPluginDeployment.Spec.Selector = newPluginDeployment.Spec.Selector existingSpecTemplate.Labels = newSpecTemplate.Labels @@ -357,15 +357,15 @@ func (r *ReconcileGitopsService) reconcileService(instance *pipelinesv1alpha1.Gi return reconcile.Result{}, err } } else { - changed := !reflect.DeepEqual(existingServiceRef.ObjectMeta.Annotations, pluginServiceRef.ObjectMeta.Annotations) || - !reflect.DeepEqual(existingServiceRef.ObjectMeta.Labels, pluginServiceRef.ObjectMeta.Labels) || + changed := !reflect.DeepEqual(existingServiceRef.Annotations, pluginServiceRef.Annotations) || + !reflect.DeepEqual(existingServiceRef.Labels, pluginServiceRef.Labels) || !reflect.DeepEqual(existingServiceRef.Spec.Selector, pluginServiceRef.Spec.Selector) || !reflect.DeepEqual(existingServiceRef.Spec.Ports, pluginServiceRef.Spec.Ports) if changed { reqLogger.Info("Reconciling plugin service", "Namespace", existingServiceRef.Namespace, "Name", existingServiceRef.Name) - existingServiceRef.ObjectMeta.Annotations = pluginServiceRef.ObjectMeta.Annotations - existingServiceRef.ObjectMeta.Labels = pluginServiceRef.ObjectMeta.Labels + existingServiceRef.Annotations = pluginServiceRef.Annotations + existingServiceRef.Labels = pluginServiceRef.Labels existingServiceRef.Spec.Selector = pluginServiceRef.Spec.Selector existingServiceRef.Spec.Ports = pluginServiceRef.Spec.Ports return reconcile.Result{}, r.Client.Update(context.TODO(), pluginServiceRef) @@ -434,11 +434,11 @@ func (r *ReconcileGitopsService) reconcileConfigMap(instance *pipelinesv1alpha1. } } else { changed := !reflect.DeepEqual(existingPluginConfigMap.Data, newPluginConfigMap.Data) || - !reflect.DeepEqual(existingPluginConfigMap.ObjectMeta.Labels, newPluginConfigMap.ObjectMeta.Labels) + !reflect.DeepEqual(existingPluginConfigMap.Labels, newPluginConfigMap.Labels) if changed { reqLogger.Info("Reconciling plugin configMap", "Namespace", existingPluginConfigMap.Namespace, "Name", existingPluginConfigMap.Name) existingPluginConfigMap.Data = newPluginConfigMap.Data - existingPluginConfigMap.ObjectMeta.Labels = newPluginConfigMap.ObjectMeta.Labels + existingPluginConfigMap.Labels = newPluginConfigMap.Labels return reconcile.Result{}, r.Client.Update(context.TODO(), newPluginConfigMap) } } diff --git a/controllers/consoleplugin_test.go b/controllers/consoleplugin_test.go index 728324b31..e990850f4 100644 --- a/controllers/consoleplugin_test.go +++ b/controllers/consoleplugin_test.go @@ -17,7 +17,6 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/client-go/kubernetes/scheme" - "k8s.io/utils/pointer" "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client/fake" @@ -75,7 +74,7 @@ func TestPlugin_reconcileDeployment_changedLabels(t *testing.T) { instance := &pipelinesv1alpha1.GitopsService{} var replicas int32 = 1 - for _, test := range tests { + for x, test := range tests { t.Run(test.name, func(t *testing.T) { d := &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ @@ -147,7 +146,7 @@ func TestPlugin_reconcileDeployment_changedLabels(t *testing.T) { VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ SecretName: pluginServingCertName, - DefaultMode: pointer.Int32Ptr(420), + DefaultMode: ptr.To(int32(420)), }, }, }, @@ -158,7 +157,7 @@ func TestPlugin_reconcileDeployment_changedLabels(t *testing.T) { LocalObjectReference: corev1.LocalObjectReference{ Name: httpdConfigMapName, }, - DefaultMode: pointer.Int32Ptr(420), + DefaultMode: ptr.To(int32(420)), }, }, }, @@ -169,7 +168,11 @@ func TestPlugin_reconcileDeployment_changedLabels(t *testing.T) { }, }, } - reconciler.Client.Create(context.TODO(), d) + + if x == 0 { + err := reconciler.Client.Create(context.TODO(), d) + assert.NilError(t, err) + } _, err := reconciler.reconcileConsolePlugin(instance, newRequest(serviceNamespace, gitopsPluginName)) assertNoError(t, err) @@ -178,11 +181,11 @@ func TestPlugin_reconcileDeployment_changedLabels(t *testing.T) { err = fakeClient.Get(context.TODO(), types.NamespacedName{Name: gitopsPluginName, Namespace: serviceNamespace}, deployment) assertNoError(t, err) - assert.Equal(t, deployment.ObjectMeta.Labels[kubeAppLabelApp], "gitops-plugin") - assert.Equal(t, deployment.ObjectMeta.Labels[kubeAppLabelComponent], "gitops-plugin") - assert.Equal(t, deployment.ObjectMeta.Labels[kubeAppLabelInstance], "gitops-plugin") - assert.Equal(t, deployment.ObjectMeta.Labels[kubeAppLabelPartOf], "gitops-plugin") - assert.Equal(t, deployment.ObjectMeta.Labels[kubeAppLabelRuntimeNamespace], "openshift-gitops") + assert.Equal(t, deployment.Labels[kubeAppLabelApp], "gitops-plugin") + assert.Equal(t, deployment.Labels[kubeAppLabelComponent], "gitops-plugin") + assert.Equal(t, deployment.Labels[kubeAppLabelInstance], "gitops-plugin") + assert.Equal(t, deployment.Labels[kubeAppLabelPartOf], "gitops-plugin") + assert.Equal(t, deployment.Labels[kubeAppLabelRuntimeNamespace], "openshift-gitops") }) } } @@ -211,7 +214,7 @@ func TestPlugin_reconcileDeployment_changedReplicas(t *testing.T) { reconciler := newReconcileGitOpsService(fakeClient, s) instance := &pipelinesv1alpha1.GitopsService{} - for _, test := range tests { + for x, test := range tests { t.Run(test.name, func(t *testing.T) { d := &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ @@ -289,7 +292,7 @@ func TestPlugin_reconcileDeployment_changedReplicas(t *testing.T) { VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ SecretName: pluginServingCertName, - DefaultMode: pointer.Int32Ptr(420), + DefaultMode: ptr.To(int32(420)), }, }, }, @@ -300,7 +303,7 @@ func TestPlugin_reconcileDeployment_changedReplicas(t *testing.T) { LocalObjectReference: corev1.LocalObjectReference{ Name: httpdConfigMapName, }, - DefaultMode: pointer.Int32Ptr(420), + DefaultMode: ptr.To(int32(420)), }, }, }, @@ -311,7 +314,10 @@ func TestPlugin_reconcileDeployment_changedReplicas(t *testing.T) { }, }, } - reconciler.Client.Create(context.TODO(), d) + if x == 0 { + err := reconciler.Client.Create(context.TODO(), d) + assertNoError(t, err) + } _, err := reconciler.reconcileConsolePlugin(instance, newRequest(serviceNamespace, gitopsPluginName)) assertNoError(t, err) @@ -351,7 +357,7 @@ func TestPlugin_reconcileDeployment_changedSelector(t *testing.T) { reconciler := newReconcileGitOpsService(fakeClient, s) instance := &pipelinesv1alpha1.GitopsService{} - for _, test := range tests { + for x, test := range tests { t.Run(test.name, func(t *testing.T) { d := &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ @@ -427,7 +433,7 @@ func TestPlugin_reconcileDeployment_changedSelector(t *testing.T) { VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ SecretName: pluginServingCertName, - DefaultMode: pointer.Int32Ptr(420), + DefaultMode: ptr.To(int32(420)), }, }, }, @@ -438,7 +444,7 @@ func TestPlugin_reconcileDeployment_changedSelector(t *testing.T) { LocalObjectReference: corev1.LocalObjectReference{ Name: httpdConfigMapName, }, - DefaultMode: pointer.Int32Ptr(420), + DefaultMode: ptr.To(int32(420)), }, }, }, @@ -449,7 +455,11 @@ func TestPlugin_reconcileDeployment_changedSelector(t *testing.T) { }, }, } - reconciler.Client.Create(context.TODO(), d) + + if x == 0 { + err := reconciler.Client.Create(context.TODO(), d) + assertNoError(t, err) + } _, err := reconciler.reconcileConsolePlugin(instance, newRequest(serviceNamespace, gitopsPluginName)) assertNoError(t, err) @@ -563,7 +573,7 @@ func TestPlugin_reconcileDeployment_changedTemplateLabels(t *testing.T) { VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ SecretName: pluginServingCertName, - DefaultMode: pointer.Int32Ptr(420), + DefaultMode: ptr.To(int32(420)), }, }, }, @@ -574,7 +584,7 @@ func TestPlugin_reconcileDeployment_changedTemplateLabels(t *testing.T) { LocalObjectReference: corev1.LocalObjectReference{ Name: httpdConfigMapName, }, - DefaultMode: pointer.Int32Ptr(420), + DefaultMode: ptr.To(int32(420)), }, }, }, @@ -596,7 +606,7 @@ func TestPlugin_reconcileDeployment_changedTemplateLabels(t *testing.T) { err = fakeClient.Get(context.TODO(), types.NamespacedName{Name: gitopsPluginName, Namespace: serviceNamespace}, deployment) assertNoError(t, err) - assert.Equal(t, deployment.Spec.Template.ObjectMeta.Labels[kubeAppLabelApp], "gitops-plugin") + assert.Equal(t, deployment.Spec.Template.Labels[kubeAppLabelApp], "gitops-plugin") }) } } @@ -692,7 +702,7 @@ func TestPlugin_reconcileDeployment_changedRestartPolicy(t *testing.T) { reconciler := newReconcileGitOpsService(fakeClient, s) instance := &pipelinesv1alpha1.GitopsService{} - for _, test := range tests { + for x, test := range tests { t.Run(test.name, func(t *testing.T) { d := &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ @@ -770,7 +780,7 @@ func TestPlugin_reconcileDeployment_changedRestartPolicy(t *testing.T) { VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ SecretName: pluginServingCertName, - DefaultMode: pointer.Int32Ptr(420), + DefaultMode: ptr.To(int32(420)), }, }, }, @@ -781,7 +791,7 @@ func TestPlugin_reconcileDeployment_changedRestartPolicy(t *testing.T) { LocalObjectReference: corev1.LocalObjectReference{ Name: httpdConfigMapName, }, - DefaultMode: pointer.Int32Ptr(420), + DefaultMode: ptr.To(int32(420)), }, }, }, @@ -792,7 +802,11 @@ func TestPlugin_reconcileDeployment_changedRestartPolicy(t *testing.T) { }, }, } - reconciler.Client.Create(context.TODO(), d) + + if x == 0 { + err := reconciler.Client.Create(context.TODO(), d) + assertNoError(t, err) + } _, err := reconciler.reconcileConsolePlugin(instance, newRequest(serviceNamespace, gitopsPluginName)) assertNoError(t, err) @@ -828,7 +842,7 @@ func TestPlugin_reconcileDeployment_changedDNSPolicy(t *testing.T) { reconciler := newReconcileGitOpsService(fakeClient, s) instance := &pipelinesv1alpha1.GitopsService{} - for _, test := range tests { + for x, test := range tests { t.Run(test.name, func(t *testing.T) { d := &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ @@ -906,7 +920,7 @@ func TestPlugin_reconcileDeployment_changedDNSPolicy(t *testing.T) { VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ SecretName: pluginServingCertName, - DefaultMode: pointer.Int32Ptr(420), + DefaultMode: ptr.To(int32(420)), }, }, }, @@ -917,7 +931,7 @@ func TestPlugin_reconcileDeployment_changedDNSPolicy(t *testing.T) { LocalObjectReference: corev1.LocalObjectReference{ Name: httpdConfigMapName, }, - DefaultMode: pointer.Int32Ptr(420), + DefaultMode: ptr.To(int32(420)), }, }, }, @@ -928,7 +942,11 @@ func TestPlugin_reconcileDeployment_changedDNSPolicy(t *testing.T) { }, }, } - reconciler.Client.Create(context.TODO(), d) + + if x == 0 { + err := reconciler.Client.Create(context.TODO(), d) + assertNoError(t, err) + } _, err := reconciler.reconcileConsolePlugin(instance, newRequest(serviceNamespace, gitopsPluginName)) assertNoError(t, err) @@ -1029,7 +1047,7 @@ func TestPlugin_reconcileService_changedAnnotations(t *testing.T) { reconciler := newReconcileGitOpsService(fakeClient, s) instance := &pipelinesv1alpha1.GitopsService{} - for _, test := range tests { + for x, test := range tests { t.Run(test.name, func(t *testing.T) { svc := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ @@ -1057,7 +1075,11 @@ func TestPlugin_reconcileService_changedAnnotations(t *testing.T) { }}, }, } - reconciler.Client.Create(context.TODO(), svc) + + if x == 0 { + err := reconciler.Client.Create(context.TODO(), svc) + assertNoError(t, err) + } _, err := reconciler.reconcileConsolePlugin(instance, newRequest(serviceNamespace, gitopsPluginName)) assertNoError(t, err) @@ -1066,7 +1088,7 @@ func TestPlugin_reconcileService_changedAnnotations(t *testing.T) { err = fakeClient.Get(context.TODO(), types.NamespacedName{Name: gitopsPluginName, Namespace: serviceNamespace}, service) assertNoError(t, err) - assert.Equal(t, service.ObjectMeta.Annotations["service.beta.openshift.io/serving-cert-secret-name"], "console-serving-cert") + assert.Equal(t, service.Annotations["service.beta.openshift.io/serving-cert-secret-name"], "console-serving-cert") }) } } @@ -1103,7 +1125,7 @@ func TestPlugin_reconcileService_changedLabels(t *testing.T) { reconciler := newReconcileGitOpsService(fakeClient, s) instance := &pipelinesv1alpha1.GitopsService{} - for _, test := range tests { + for x, test := range tests { t.Run(test.name, func(t *testing.T) { svc := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ @@ -1126,7 +1148,10 @@ func TestPlugin_reconcileService_changedLabels(t *testing.T) { }}, }, } - reconciler.Client.Create(context.TODO(), svc) + if x == 0 { + err := reconciler.Client.Create(context.TODO(), svc) + assertNoError(t, err) + } _, err := reconciler.reconcileConsolePlugin(instance, newRequest(serviceNamespace, gitopsPluginName)) assertNoError(t, err) @@ -1135,10 +1160,10 @@ func TestPlugin_reconcileService_changedLabels(t *testing.T) { err = fakeClient.Get(context.TODO(), types.NamespacedName{Name: gitopsPluginName, Namespace: serviceNamespace}, service) assertNoError(t, err) - assert.Equal(t, service.ObjectMeta.Labels[kubeAppLabelApp], "gitops-plugin") - assert.Equal(t, service.ObjectMeta.Labels[kubeAppLabelComponent], "gitops-plugin") - assert.Equal(t, service.ObjectMeta.Labels[kubeAppLabelInstance], "gitops-plugin") - assert.Equal(t, service.ObjectMeta.Labels[kubeAppLabelPartOf], "gitops-plugin") + assert.Equal(t, service.Labels[kubeAppLabelApp], "gitops-plugin") + assert.Equal(t, service.Labels[kubeAppLabelComponent], "gitops-plugin") + assert.Equal(t, service.Labels[kubeAppLabelInstance], "gitops-plugin") + assert.Equal(t, service.Labels[kubeAppLabelPartOf], "gitops-plugin") }) } } @@ -1169,7 +1194,7 @@ func TestPlugin_reconcileService_changedSelector(t *testing.T) { reconciler := newReconcileGitOpsService(fakeClient, s) instance := &pipelinesv1alpha1.GitopsService{} - for _, test := range tests { + for x, test := range tests { t.Run(test.name, func(t *testing.T) { svc := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ @@ -1195,7 +1220,10 @@ func TestPlugin_reconcileService_changedSelector(t *testing.T) { }}, }, } - reconciler.Client.Create(context.TODO(), svc) + if x == 0 { + err := reconciler.Client.Create(context.TODO(), svc) + assertNoError(t, err) + } _, err := reconciler.reconcileConsolePlugin(instance, newRequest(serviceNamespace, gitopsPluginName)) assertNoError(t, err) @@ -1241,7 +1269,7 @@ func TestPlugin_reconcileService_changedPorts(t *testing.T) { reconciler := newReconcileGitOpsService(fakeClient, s) instance := &pipelinesv1alpha1.GitopsService{} - for _, test := range tests { + for x, test := range tests { t.Run(test.name, func(t *testing.T) { svc := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ @@ -1269,7 +1297,10 @@ func TestPlugin_reconcileService_changedPorts(t *testing.T) { }}, }, } - reconciler.Client.Create(context.TODO(), svc) + if x == 0 { + err := reconciler.Client.Create(context.TODO(), svc) + assertNoError(t, err) + } _, err := reconciler.reconcileConsolePlugin(instance, newRequest(serviceNamespace, gitopsPluginName)) assertNoError(t, err) @@ -1325,7 +1356,7 @@ func TestPlugin_reconcileConsolePlugin_changedDisplayName(t *testing.T) { reconciler := newReconcileGitOpsService(fakeClient, s) instance := &pipelinesv1alpha1.GitopsService{} - for _, test := range tests { + for x, test := range tests { t.Run(test.name, func(t *testing.T) { cp := &consolev1.ConsolePlugin{ ObjectMeta: metav1.ObjectMeta{ @@ -1344,7 +1375,10 @@ func TestPlugin_reconcileConsolePlugin_changedDisplayName(t *testing.T) { }, }, } - reconciler.Client.Create(context.TODO(), cp) + if x == 0 { + err := reconciler.Client.Create(context.TODO(), cp) + assertNoError(t, err) + } _, err := reconciler.reconcileConsolePlugin(instance, newRequest(serviceNamespace, gitopsPluginName)) assertNoError(t, err) @@ -1389,7 +1423,7 @@ func TestPlugin_reconcileConsolePlugin_changedService(t *testing.T) { reconciler := newReconcileGitOpsService(fakeClient, s) instance := &pipelinesv1alpha1.GitopsService{} - for _, test := range tests { + for x, test := range tests { t.Run(test.name, func(t *testing.T) { cp := &consolev1.ConsolePlugin{ ObjectMeta: metav1.ObjectMeta{ @@ -1403,7 +1437,10 @@ func TestPlugin_reconcileConsolePlugin_changedService(t *testing.T) { }, }, } - reconciler.Client.Create(context.TODO(), cp) + if x == 0 { + err := reconciler.Client.Create(context.TODO(), cp) + assertNoError(t, err) + } _, err := reconciler.reconcileConsolePlugin(instance, newRequest(serviceNamespace, gitopsPluginName)) assertNoError(t, err) @@ -1464,7 +1501,7 @@ func TestPlug_reconcileConfigMap_changedLabels(t *testing.T) { reconciler := newReconcileGitOpsService(fakeClient, s) instance := &pipelinesv1alpha1.GitopsService{} - for _, test := range tests { + for x, test := range tests { t.Run(test.name, func(t *testing.T) { cm := &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ @@ -1476,7 +1513,10 @@ func TestPlug_reconcileConfigMap_changedLabels(t *testing.T) { "httpd.conf": httpdConfig, }, } - reconciler.Client.Create(context.TODO(), cm) + if x == 0 { + err := reconciler.Client.Create(context.TODO(), cm) + assertNoError(t, err) + } _, err := reconciler.reconcileConsolePlugin(instance, newRequest(serviceNamespace, gitopsPluginName)) assertNoError(t, err) @@ -1485,8 +1525,8 @@ func TestPlug_reconcileConfigMap_changedLabels(t *testing.T) { err = fakeClient.Get(context.TODO(), types.NamespacedName{Name: httpdConfigMapName, Namespace: serviceNamespace}, configMap) assertNoError(t, err) - assert.Equal(t, configMap.ObjectMeta.Labels[kubeAppLabelApp], "gitops-plugin") - assert.Equal(t, configMap.ObjectMeta.Labels[kubeAppLabelPartOf], "gitops-plugin") + assert.Equal(t, configMap.Labels[kubeAppLabelApp], "gitops-plugin") + assert.Equal(t, configMap.Labels[kubeAppLabelPartOf], "gitops-plugin") }) } } diff --git a/controllers/gitopsservice_controller.go b/controllers/gitopsservice_controller.go index 1e6f9c569..75ae389e9 100644 --- a/controllers/gitopsservice_controller.go +++ b/controllers/gitopsservice_controller.go @@ -61,7 +61,6 @@ var logs = logf.Log.WithName("controller_gitopsservice") // defaults must some somewhere else.. var ( port int32 = 8080 - portTLS int32 = 8443 backendImage string = "quay.io/redhat-developer/gitops-backend:v0.0.1" backendImageEnvName = "BACKEND_IMAGE" serviceName = "cluster" @@ -468,8 +467,10 @@ func (r *ReconcileGitopsService) reconcileDefaultArgoCDInstance(instance *pipeli changed = true } - if existingArgoCD.Spec.Grafana.Resources == nil { - existingArgoCD.Spec.Grafana.Resources = defaultArgoCDInstance.Spec.Grafana.Resources + //lint:ignore SA1019 known to be deprecated + if existingArgoCD.Spec.Grafana.Resources == nil { //nolint:staticcheck // SA1019: We must test deprecated fields. + //lint:ignore SA1019 known to be deprecated + existingArgoCD.Spec.Grafana.Resources = defaultArgoCDInstance.Spec.Grafana.Resources //nolint:staticcheck // SA1019: We must test deprecated fields. changed = true } diff --git a/controllers/gitopsservice_controller_test.go b/controllers/gitopsservice_controller_test.go index 63894460e..e1bbc3005 100644 --- a/controllers/gitopsservice_controller_test.go +++ b/controllers/gitopsservice_controller_test.go @@ -524,7 +524,8 @@ func TestReconcile_testArgoCDForOperatorUpgrade(t *testing.T) { assert.Check(t, updateArgoCD.Spec.ApplicationSet.Resources != nil) assert.Check(t, updateArgoCD.Spec.Controller.Resources != nil) assert.Check(t, updateArgoCD.Spec.SSO.Dex.Resources != nil) - assert.Check(t, updateArgoCD.Spec.Grafana.Resources != nil) + //lint:ignore SA1019 known to be deprecated + assert.Check(t, updateArgoCD.Spec.Grafana.Resources != nil) //nolint:staticcheck // SA1019: We must test deprecated fields. assert.Check(t, updateArgoCD.Spec.HA.Resources != nil) assert.Check(t, updateArgoCD.Spec.Redis.Resources != nil) assert.Check(t, updateArgoCD.Spec.Repo.Resources != nil) @@ -546,7 +547,8 @@ func TestReconcile_VerifyResourceQuotaDeletionForUpgrade(t *testing.T) { Namespace: serviceNamespace, }, } - fakeClient.Create(context.TODO(), defaultArgoNS) + err := fakeClient.Create(context.TODO(), defaultArgoNS) + assertNoError(t, err) dummyResourceObj := &corev1.ResourceQuota{ ObjectMeta: v1.ObjectMeta{ @@ -554,9 +556,10 @@ func TestReconcile_VerifyResourceQuotaDeletionForUpgrade(t *testing.T) { Namespace: serviceNamespace, }, } - fakeClient.Create(context.TODO(), dummyResourceObj) + err = fakeClient.Create(context.TODO(), dummyResourceObj) + assertNoError(t, err) - _, err := reconciler.Reconcile(context.TODO(), newRequest("test", "test")) + _, err = reconciler.Reconcile(context.TODO(), newRequest("test", "test")) assertNoError(t, err) // Verify that resource quota object is deleted after reconciliation. @@ -707,7 +710,7 @@ func TestReconcile_PSSLabels(t *testing.T) { reconciled_ns) assertNoError(t, err) - for label, _ := range reconciled_ns.ObjectMeta.Labels { + for label := range reconciled_ns.Labels { _, found := expected_labels[label] // Fail if label is found assert.Check(t, found != true) @@ -718,18 +721,19 @@ func TestReconcile_PSSLabels(t *testing.T) { assert.NilError(t, fakeClient.Get(context.TODO(), types.NamespacedName{Name: tc.namespace}, existing_ns), err) // Assign new values, confirm the assignment and update the PSS labels - existing_ns.ObjectMeta.Labels = tc.labels - fakeClient.Update(context.TODO(), existing_ns) + existing_ns.Labels = tc.labels + err := fakeClient.Update(context.TODO(), existing_ns) + assert.NilError(t, err) assert.NilError(t, fakeClient.Get(context.TODO(), types.NamespacedName{Name: tc.namespace}, existing_ns), err) - assert.DeepEqual(t, existing_ns.ObjectMeta.Labels, tc.labels) + assert.DeepEqual(t, existing_ns.Labels, tc.labels) - _, err := reconciler.Reconcile(context.TODO(), newRequest("test", "test")) + _, err = reconciler.Reconcile(context.TODO(), newRequest("test", "test")) assertNoError(t, err) assert.NilError(t, fakeClient.Get(context.TODO(), types.NamespacedName{Name: tc.namespace}, reconciled_ns), err) for key, value := range expected_labels { - label, found := reconciled_ns.ObjectMeta.Labels[key] + label, found := reconciled_ns.Labels[key] // Fail if label is not found, comapre the values with the expected values if found assert.Check(t, found) assert.Equal(t, label, value) diff --git a/hack/upgrade-rollouts-manager/go.sum b/hack/upgrade-rollouts-manager/go.sum index 603936e87..703631de5 100644 --- a/hack/upgrade-rollouts-manager/go.sum +++ b/hack/upgrade-rollouts-manager/go.sum @@ -1,8 +1,5 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY= -github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= github.com/google/go-github/v58 v58.0.0 h1:Una7GGERlF/37XfkPwpzYJe0Vp4dt2k1kCjlxwjIvzw= github.com/google/go-github/v58 v58.0.0/go.mod h1:k4hxDKEfoWpSqFlc8LTpGd9fu2KrV1YAa6Hi6FmDNY4= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= diff --git a/hack/upgrade-rollouts-manager/main.go b/hack/upgrade-rollouts-manager/main.go index dc5375b4e..3cd300c7d 100644 --- a/hack/upgrade-rollouts-manager/main.go +++ b/hack/upgrade-rollouts-manager/main.go @@ -218,12 +218,14 @@ func copyCRDsFromRolloutsManagerRepo(pathToRolloutsManagerGitRepo string, pathTo destinationPath := filepath.Join(pathToGitRepo, "config/crd/bases") for _, crdYAML := range crdYAMLs { + // #nosec G304 destFile, err := os.Create(filepath.Join(destinationPath, crdYAML)) if err != nil { return fmt.Errorf("unable to create file for '%s': %w", crdYAML, err) } defer destFile.Close() + // #nosec G304 srcFile, err := os.Open(filepath.Join(rolloutManagerCRDPath, crdYAML)) if err != nil { return fmt.Errorf("unable to open source file for '%s': %w", crdYAML, err) @@ -248,6 +250,7 @@ func regenerateE2ETestScript(commitID string, pathToGitRepo string) error { path := filepath.Join(pathToGitRepo, "scripts/run-rollouts-e2e-tests.sh") + // #nosec G304 fileBytes, err := os.ReadFile(path) if err != nil { return err @@ -299,6 +302,7 @@ func extractCurrentRolloutsManagerGitCommitFromGoMod(pathToGitOpsOperatorGitRepo path := filepath.Join(pathToGitOpsOperatorGitRepo, "go.mod") + // #nosec G304 fileBytes, err := os.ReadFile(path) if err != nil { return "", err @@ -346,6 +350,7 @@ func runCommandWithWorkDir(workingDir string, cmdList ...string) (string, string fmt.Println(cmdList) + // #nosec G204 cmd := exec.Command(cmdList[0], cmdList[1:]...) var stdout bytes.Buffer var stderr bytes.Buffer diff --git a/test/e2e/argocd_route_test.go b/test/e2e/argocd_route_test.go index ba3a8ee75..20e39acee 100644 --- a/test/e2e/argocd_route_test.go +++ b/test/e2e/argocd_route_test.go @@ -51,7 +51,7 @@ var _ = Describe("Argo CD ConsoleLink controller", func() { if err != nil { return err } - clLink := strings.TrimLeft(consoleLink.Spec.Href, "https://") + clLink := strings.TrimPrefix(consoleLink.Spec.Href, "https://") routeLink := route.Spec.Host if clLink != routeLink { return fmt.Errorf("URL mismatch, route: %s, consoleLink: %s", routeLink, clLink) diff --git a/test/e2e/gitopsservice_test.go b/test/e2e/gitopsservice_test.go index beabf70ef..e6fbeb82d 100644 --- a/test/e2e/gitopsservice_test.go +++ b/test/e2e/gitopsservice_test.go @@ -176,6 +176,8 @@ var _ = Describe("GitOpsServiceController", func() { By("create a new Argo CD instance in test ns") argocdNonDefaultNamespaceInstance, err := argocd.NewCR(argocdNonDefaultInstanceName, argocdNonDefaultNamespace) + Expect(err).NotTo(HaveOccurred()) + err = k8sClient.Create(context.TODO(), argocdNonDefaultNamespaceInstance) Expect(err).NotTo(HaveOccurred()) @@ -210,7 +212,7 @@ var _ = Describe("GitOpsServiceController", func() { }) It("Clean up test resources", func() { - Expect(helper.DeleteNamespace(k8sClient, argocdNonDefaultNamespace)) + Expect(helper.DeleteNamespace(k8sClient, argocdNonDefaultNamespace)).To(Succeed()) }) }) @@ -297,7 +299,7 @@ var _ = Describe("GitOpsServiceController", func() { }) It("Clean up test resources", func() { - Expect(helper.DeleteNamespace(k8sClient, helper.StandaloneArgoCDNamespace)) + Expect(helper.DeleteNamespace(k8sClient, helper.StandaloneArgoCDNamespace)).To(Succeed()) }) }) @@ -640,17 +642,15 @@ var _ = Describe("GitOpsServiceController", func() { It("Keycloak deployment is created", func() { Eventually(func() error { - dc := &osappsv1.DeploymentConfig{} - err := k8sClient.Get(context.TODO(), types.NamespacedName{Name: defaultKeycloakIdentifier, Namespace: namespace}, dc) + dc := osappsv1.DeploymentConfig{} + err := k8sClient.Get(context.TODO(), types.NamespacedName{Name: defaultKeycloakIdentifier, Namespace: namespace}, &dc) if err != nil { return err } - if dc != nil { - got := dc.Status.AvailableReplicas - want := int32(1) - if got != want { - return fmt.Errorf("expected %d, got %d", want, got) - } + got := dc.Status.AvailableReplicas + want := int32(1) + if got != want { + return fmt.Errorf("expected %d, got %d", want, got) } return nil }, timeout, interval).ShouldNot(HaveOccurred()) @@ -723,7 +723,7 @@ var _ = Describe("GitOpsServiceController", func() { idp := idps[0].(map[string]interface{}) Expect(idp["alias"]).To(Equal("openshift-v4")) - Expect(idp["displayName"] == "Login with OpenShift") + Expect(idp["displayName"]).To(Equal("Login with OpenShift")) Expect(idp["providerId"]).To(Equal("openshift-v4")) Expect(idp["firstBrokerLoginFlowAlias"]).To(Equal("first broker login")) }) @@ -944,71 +944,6 @@ func getAccessToken(user, pass, accessURL string) (string, error) { return tokenRes.AccessToken, nil } -func applyMissingPermissions(name, namespace string) error { - // Check the role was created. If not, create a new role - roleName := fmt.Sprintf("%s-openshift-gitops-argocd-application-controller", namespace) - role := &rbacv1.Role{ - ObjectMeta: metav1.ObjectMeta{ - Name: roleName, - Namespace: namespace, - }, - Rules: []rbacv1.PolicyRule{ - { - Verbs: []string{"*"}, - APIGroups: []string{"*"}, - Resources: []string{"*"}, - }, - }, - } - err := k8sClient.Get(context.TODO(), - types.NamespacedName{Name: roleName, Namespace: namespace}, role) - if err != nil { - if kubeerrors.IsNotFound(err) { - err := k8sClient.Create(context.TODO(), role) - if err != nil { - return err - } - } else { - return err - } - } - - // Check the role binding was created. If not, create a new role binding - roleBindingName := fmt.Sprintf("%s-openshift-gitops-argocd-application-controller", namespace) - roleBinding := &rbacv1.RoleBinding{ - ObjectMeta: metav1.ObjectMeta{ - Name: roleBindingName, - Namespace: namespace, - }, - RoleRef: rbacv1.RoleRef{ - Name: roleName, - Kind: "Role", - APIGroup: "rbac.authorization.k8s.io", - }, - Subjects: []rbacv1.Subject{ - { - Name: fmt.Sprintf("%s-argocd-application-controller", name), - Kind: "ServiceAccount", - }, - }, - } - err = k8sClient.Get(context.TODO(), - types.NamespacedName{Name: roleBindingName, Namespace: namespace}, - roleBinding) - if err != nil { - if kubeerrors.IsNotFound(err) { - err := k8sClient.Create(context.TODO(), roleBinding) - if err != nil { - return err - } - } else { - return err - } - } - - return nil -} - func runCommandWithOutput(cmdList ...string) (string, string, error) { // Output the commands to be run, so that if the test fails we can determine why diff --git a/test/e2e/suite_test.go b/test/e2e/suite_test.go index f2b5fb387..5db84de98 100644 --- a/test/e2e/suite_test.go +++ b/test/e2e/suite_test.go @@ -43,11 +43,9 @@ import ( "github.com/redhat-developer/gitops-operator/controllers" "github.com/redhat-developer/gitops-operator/controllers/util" "github.com/redhat-developer/gitops-operator/test/helper" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes/scheme" _ "k8s.io/client-go/plugin/pkg/client/auth" - "k8s.io/client-go/rest" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/envtest" @@ -59,7 +57,6 @@ import ( // These tests use Ginkgo (BDD-style Go testing framework). Refer to // http://onsi.github.io/ginkgo/ to learn more about Ginkgo. -var cfg *rest.Config var k8sClient client.Client var testEnv *envtest.Environment @@ -207,15 +204,3 @@ func checkIfPresent(ns types.NamespacedName, obj client.Object) { return nil }, timeout, interval).ShouldNot(HaveOccurred()) } - -// checks if a given resource is deleted -// continouslly polls until the object is deleted or a timeout occurs -func checkIfDeleted(ns types.NamespacedName, obj client.Object) { - Eventually(func() error { - err := k8sClient.Get(context.TODO(), ns, obj) - if errors.IsNotFound(err) { - return nil - } - return err - }, timeout, interval).ShouldNot(HaveOccurred()) -} diff --git a/test/helper/application_status.go b/test/helper/application_status.go index c653863a2..4ab9845f6 100644 --- a/test/helper/application_status.go +++ b/test/helper/application_status.go @@ -26,7 +26,8 @@ import ( "time" argoapp "github.com/argoproj-labs/argocd-operator/api/v1beta1" - . "github.com/onsi/ginkgo/v2" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/ginkgo/v2" //nolint:all corev1 "k8s.io/api/core/v1" kubeerrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -49,6 +50,7 @@ func ProjectExists(projectName string, namespace string) (bool, error) { return false, err } + // #nosec G204 cmd := exec.Command(ocPath, "get", "appproject/"+projectName, "-n", namespace) cmd.Stdout = &stdout cmd.Stderr = &stderr @@ -67,6 +69,7 @@ func ApplicationHealthStatus(appname string, namespace string) error { return err } + // #nosec G204 cmd := exec.Command(ocPath, "get", "application/"+appname, "-n", namespace, "-o", "jsonpath='{.status.health.status}'") cmd.Stdout = &stdout cmd.Stderr = &stderr @@ -89,6 +92,7 @@ func ApplicationSyncStatus(appname string, namespace string) error { return err } + // #nosec G204 cmd := exec.Command(ocPath, "get", "application/"+appname, "-n", namespace, "-o", "jsonpath='{.status.sync.status}'") cmd.Stdout = &stdout cmd.Stderr = &stderr @@ -118,12 +122,12 @@ type ResourceList struct { // Returns error if the resources could not be found within the given time frame. func WaitForResourcesByName(k8sClient client.Client, resourceList []ResourceList, namespace string, timeout time.Duration) error { // Wait X seconds for all the resources to be created - err := wait.Poll(time.Second*1, timeout, func() (bool, error) { + return wait.PollUntilContextTimeout(context.Background(), time.Second*1, timeout, true, func(ctx context.Context) (bool, error) { for _, resourceListEntry := range resourceList { for _, resourceName := range resourceListEntry.ExpectedResources { resource := resourceListEntry.Resource namespacedName := types.NamespacedName{Name: resourceName, Namespace: namespace} - if err := k8sClient.Get(context.TODO(), namespacedName, resource); err != nil { + if err := k8sClient.Get(ctx, namespacedName, resource); err != nil { log.Printf("Unable to retrieve expected resource %s: %v", resourceName, err) return false, nil } @@ -132,7 +136,6 @@ func WaitForResourcesByName(k8sClient client.Client, resourceList []ResourceList } return true, nil }) - return err } // EnsureCleanSlate runs before the tests, to ensure that the cluster is in the expected pre-test state @@ -161,7 +164,7 @@ func DeleteNamespace(k8sClient client.Client, nsToDelete string) error { return fmt.Errorf("unable to delete namespace %v", err) } - err = wait.Poll(1*time.Second, 5*time.Minute, func() (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), 1*time.Second, 5*time.Minute, true, func(ctx context.Context) (bool, error) { defer GinkgoRecover() @@ -171,7 +174,7 @@ func DeleteNamespace(k8sClient client.Client, nsToDelete string) error { opts := &client.ListOptions{ Namespace: nsToDelete, } - if err = k8sClient.List(context.Background(), &list, opts); err != nil { + if err = k8sClient.List(ctx, &list, opts); err != nil { GinkgoT().Errorf("Unable to list ArgoCDs %v", err) // Report failure, but still continue } @@ -185,7 +188,7 @@ func DeleteNamespace(k8sClient client.Client, nsToDelete string) error { item.Finalizers = []string{} GinkgoT().Logf("Updating ArgoCD operand '%s' to remove finalizers, for deletion.", item.Name) err = retry.RetryOnConflict(retry.DefaultBackoff, func() error { - err := k8sClient.Get(context.Background(), types.NamespacedName{Namespace: item.Namespace, Name: item.Name}, &item) + err := k8sClient.Get(ctx, types.NamespacedName{Namespace: item.Namespace, Name: item.Name}, &item) if err != nil { if kubeerrors.IsNotFound(err) { return nil @@ -193,7 +196,7 @@ func DeleteNamespace(k8sClient client.Client, nsToDelete string) error { return err } item.Finalizers = []string{} - return k8sClient.Update(context.Background(), &item) + return k8sClient.Update(ctx, &item) }) if err != nil { GinkgoT().Errorf("Unable to update ArgoCD application finalizer on '%s': %v", item.Name, err) @@ -201,8 +204,7 @@ func DeleteNamespace(k8sClient client.Client, nsToDelete string) error { } } - if err := k8sClient.Get(context.Background(), types.NamespacedName{Name: nsTarget.Name}, - nsTarget); kubeerrors.IsNotFound(err) { + if err := k8sClient.Get(ctx, types.NamespacedName{Name: nsTarget.Name}, nsTarget); kubeerrors.IsNotFound(err) { GinkgoT().Logf("Namespace '%s' no longer exists", nsTarget.Name) return true, nil } diff --git a/test/nondefaulte2e/gitops_service_nondefault_test.go b/test/nondefaulte2e/gitops_service_nondefault_test.go index 5f8e9fcc8..71f6c3f7f 100644 --- a/test/nondefaulte2e/gitops_service_nondefault_test.go +++ b/test/nondefaulte2e/gitops_service_nondefault_test.go @@ -155,7 +155,7 @@ var _ = Describe("GitOpsServiceNoDefaultInstall", func() { }) It("Clean up test resources", func() { - Expect(helper.DeleteNamespace(k8sClient, helper.StandaloneArgoCDNamespace)) + Expect(helper.DeleteNamespace(k8sClient, helper.StandaloneArgoCDNamespace)).To(Succeed()) }) }) }) diff --git a/test/nondefaulte2e/suite_test.go b/test/nondefaulte2e/suite_test.go index 3d50a98e1..6ca0bf6d5 100644 --- a/test/nondefaulte2e/suite_test.go +++ b/test/nondefaulte2e/suite_test.go @@ -45,11 +45,9 @@ import ( "github.com/redhat-developer/gitops-operator/controllers" "github.com/redhat-developer/gitops-operator/controllers/util" "github.com/redhat-developer/gitops-operator/test/helper" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes/scheme" _ "k8s.io/client-go/plugin/pkg/client/auth" - "k8s.io/client-go/rest" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/envtest" @@ -61,7 +59,6 @@ import ( // These tests use Ginkgo (BDD-style Go testing framework). Refer to // http://onsi.github.io/ginkgo/ to learn more about Ginkgo. -var cfg *rest.Config var k8sClient client.Client var testEnv *envtest.Environment @@ -177,27 +174,3 @@ var _ = AfterSuite(func() { err = testEnv.Stop() Expect(err).NotTo(HaveOccurred()) }) - -// checks if a given resource is present in the cluster -// continouslly polls until it returns nil or a timeout occurs -func checkIfPresent(ns types.NamespacedName, obj client.Object) { - Eventually(func() error { - err := k8sClient.Get(context.TODO(), ns, obj) - if err != nil { - return err - } - return nil - }, timeout, interval).ShouldNot(HaveOccurred()) -} - -// checks if a given resource is deleted -// continouslly polls until the object is deleted or a timeout occurs -func checkIfDeleted(ns types.NamespacedName, obj client.Object) { - Eventually(func() error { - err := k8sClient.Get(context.TODO(), ns, obj) - if errors.IsNotFound(err) { - return nil - } - return err - }, timeout, interval).ShouldNot(HaveOccurred()) -} diff --git a/test/openshift/e2e/ginkgo/fixture/application/fixture.go b/test/openshift/e2e/ginkgo/fixture/application/fixture.go index 68a57dcca..8f3f53e49 100644 --- a/test/openshift/e2e/ginkgo/fixture/application/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/application/fixture.go @@ -1,7 +1,8 @@ package application import ( - . "github.com/onsi/gomega" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/gomega" //nolint:all "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils" "k8s.io/client-go/util/retry" @@ -10,7 +11,8 @@ import ( "github.com/argoproj/gitops-engine/pkg/sync/common" matcher "github.com/onsi/gomega/types" - . "github.com/onsi/ginkgo/v2" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/ginkgo/v2" //nolint:all "context" diff --git a/test/openshift/e2e/ginkgo/fixture/argocd/fixture.go b/test/openshift/e2e/ginkgo/fixture/argocd/fixture.go index 180f12eec..1159a190d 100644 --- a/test/openshift/e2e/ginkgo/fixture/argocd/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/argocd/fixture.go @@ -8,8 +8,11 @@ import ( "time" argov1beta1api "github.com/argoproj-labs/argocd-operator/api/v1beta1" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/ginkgo/v2" //nolint:all + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/gomega" //nolint:all + matcher "github.com/onsi/gomega/types" routev1 "github.com/openshift/api/route/v1" "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils" @@ -148,7 +151,7 @@ func HaveHost(host string) matcher.GomegaMatcher { func HaveApplicationControllerOperationProcessors(operationProcessors int) matcher.GomegaMatcher { return fetchArgoCD(func(argocd *argov1beta1api.ArgoCD) bool { GinkgoWriter.Println("HaveApplicationControllerOperationProcessors:", "Expected:", operationProcessors, "/ actual:", argocd.Spec.Controller.Processors.Operation) - return argocd.Spec.Controller.Processors.Operation == int32(operationProcessors) + return int(argocd.Spec.Controller.Processors.Operation) == operationProcessors }) } @@ -221,6 +224,7 @@ func RunArgoCDCLI(args ...string) (string, error) { GinkgoWriter.Println("executing command", cmdArgs) + // #nosec G204 cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...) output, err := cmd.CombinedOutput() diff --git a/test/openshift/e2e/ginkgo/fixture/clusterrole/fixture.go b/test/openshift/e2e/ginkgo/fixture/clusterrole/fixture.go index 9e6bad057..5a4087623 100644 --- a/test/openshift/e2e/ginkgo/fixture/clusterrole/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/clusterrole/fixture.go @@ -3,8 +3,10 @@ package clusterrole import ( "context" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/ginkgo/v2" //nolint:all + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/gomega" //nolint:all matcher "github.com/onsi/gomega/types" "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils" rbacv1 "k8s.io/api/rbac/v1" @@ -33,6 +35,8 @@ func Update(obj *rbacv1.ClusterRole, modify func(*rbacv1.ClusterRole)) { } // This is intentionally NOT exported, for now. Create another function in this file/package that calls this function, and export that. +// +//nolint:unused func fetchRole(f func(*rbacv1.ClusterRole) bool) matcher.GomegaMatcher { return WithTransform(func(cr *rbacv1.ClusterRole) bool { diff --git a/test/openshift/e2e/ginkgo/fixture/clusterrolebinding/fixture.go b/test/openshift/e2e/ginkgo/fixture/clusterrolebinding/fixture.go index 37888474c..7016dbea7 100644 --- a/test/openshift/e2e/ginkgo/fixture/clusterrolebinding/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/clusterrolebinding/fixture.go @@ -3,8 +3,10 @@ package clusterrolebinding import ( "context" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/ginkgo/v2" //nolint:all + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/gomega" //nolint:all matcher "github.com/onsi/gomega/types" "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils" rbacv1 "k8s.io/api/rbac/v1" @@ -12,6 +14,8 @@ import ( ) // This is intentionally NOT exported, for now. Create another function in this file/package that calls this function, and export that. +// +//nolint:unused func fetchClusterRoleBinding(f func(*rbacv1.ClusterRoleBinding) bool) matcher.GomegaMatcher { return WithTransform(func(crb *rbacv1.ClusterRoleBinding) bool { diff --git a/test/openshift/e2e/ginkgo/fixture/clusterserviceversion/fixture.go b/test/openshift/e2e/ginkgo/fixture/clusterserviceversion/fixture.go index 867a26279..df0f16f95 100644 --- a/test/openshift/e2e/ginkgo/fixture/clusterserviceversion/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/clusterserviceversion/fixture.go @@ -3,7 +3,8 @@ package clusterserviceversion import ( "context" - . "github.com/onsi/gomega" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/gomega" //nolint:all olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1" "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils" "k8s.io/client-go/util/retry" diff --git a/test/openshift/e2e/ginkgo/fixture/configmap/fixture.go b/test/openshift/e2e/ginkgo/fixture/configmap/fixture.go index b6284504b..65e456909 100644 --- a/test/openshift/e2e/ginkgo/fixture/configmap/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/configmap/fixture.go @@ -4,8 +4,10 @@ import ( "context" "strings" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/ginkgo/v2" //nolint:all + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/gomega" //nolint:all matcher "github.com/onsi/gomega/types" "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils" corev1 "k8s.io/api/core/v1" diff --git a/test/openshift/e2e/ginkgo/fixture/deployment/fixture.go b/test/openshift/e2e/ginkgo/fixture/deployment/fixture.go index f6ed079fd..fa51bcfc6 100644 --- a/test/openshift/e2e/ginkgo/fixture/deployment/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/deployment/fixture.go @@ -5,8 +5,10 @@ import ( "reflect" "strings" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/ginkgo/v2" //nolint:all + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/gomega" //nolint:all matcher "github.com/onsi/gomega/types" "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils" @@ -30,7 +32,7 @@ func GetEnv(d *appsv1.Deployment, key string) (*string, error) { containers := d.Spec.Template.Spec.Containers - Expect(len(containers)).Should(BeNumerically("==", 1)) + Expect(containers).Should(HaveLen(1)) for idx := range containers[0].Env { @@ -50,7 +52,7 @@ func SetEnv(depl *appsv1.Deployment, key string, value string) { Update(depl, func(d *appsv1.Deployment) { containers := d.Spec.Template.Spec.Containers - Expect(len(containers)).Should(BeNumerically("==", 1)) + Expect(containers).Should(HaveLen(1)) newEnvVars := []corev1.EnvVar{} @@ -83,7 +85,7 @@ func RemoveEnv(depl *appsv1.Deployment, key string) { Update(depl, func(d *appsv1.Deployment) { containers := d.Spec.Template.Spec.Containers - Expect(len(containers)).Should(BeNumerically("==", 1)) + Expect(containers).Should(HaveLen(1)) newEnvVars := []corev1.EnvVar{} @@ -243,28 +245,28 @@ func HaveObservedGeneration(observedGeneration int) matcher.GomegaMatcher { func HaveReplicas(replicas int) matcher.GomegaMatcher { return fetchDeployment(func(depl *appsv1.Deployment) bool { GinkgoWriter.Println("Deployment", depl.Name, "- HaveReplicas:", "expected: ", replicas, "actual: ", depl.Status.Replicas) - return depl.Status.Replicas == int32(replicas) && depl.Generation == depl.Status.ObservedGeneration + return int(depl.Status.Replicas) == replicas && depl.Generation == depl.Status.ObservedGeneration }) } func HaveReadyReplicas(readyReplicas int) matcher.GomegaMatcher { return fetchDeployment(func(depl *appsv1.Deployment) bool { GinkgoWriter.Println("Deployment ", depl.Name, "- HaveReadyReplicas:", "expected: ", readyReplicas, "actual: ", depl.Status.ReadyReplicas) - return depl.Status.ReadyReplicas == int32(readyReplicas) && depl.Generation == depl.Status.ObservedGeneration + return int(depl.Status.ReadyReplicas) == readyReplicas && depl.Generation == depl.Status.ObservedGeneration }) } func HaveUpdatedReplicas(updatedReplicas int) matcher.GomegaMatcher { return fetchDeployment(func(depl *appsv1.Deployment) bool { GinkgoWriter.Println("Deployment HaveUpdatedReplicas:", "expected: ", updatedReplicas, "actual: ", depl.Status.UpdatedReplicas) - return depl.Status.UpdatedReplicas == int32(updatedReplicas) && depl.Generation == depl.Status.ObservedGeneration + return int(depl.Status.UpdatedReplicas) == updatedReplicas && depl.Generation == depl.Status.ObservedGeneration }) } func HaveAvailableReplicas(availableReplicas int) matcher.GomegaMatcher { return fetchDeployment(func(depl *appsv1.Deployment) bool { GinkgoWriter.Println("Deployment HaveAvailableReplicas:", "expected: ", availableReplicas, "actual: ", depl.Status.AvailableReplicas) - return depl.Status.AvailableReplicas == int32(availableReplicas) && depl.Generation == depl.Status.ObservedGeneration + return int(depl.Status.AvailableReplicas) == availableReplicas && depl.Generation == depl.Status.ObservedGeneration }) } diff --git a/test/openshift/e2e/ginkgo/fixture/deploymentconfig/fixture.go b/test/openshift/e2e/ginkgo/fixture/deploymentconfig/fixture.go index c889fac97..7afc43d49 100644 --- a/test/openshift/e2e/ginkgo/fixture/deploymentconfig/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/deploymentconfig/fixture.go @@ -3,8 +3,11 @@ package deploymentconfig import ( "context" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/ginkgo/v2" //nolint:all + + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/gomega" //nolint:all matcher "github.com/onsi/gomega/types" "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils" @@ -16,14 +19,14 @@ import ( func HaveReplicas(replicas int) matcher.GomegaMatcher { return fetchDeploymentConfig(func(depl *openshiftappsv1.DeploymentConfig) bool { GinkgoWriter.Println("DeploymentConfig - HaveReplicas:", "expected: ", replicas, "actual: ", depl.Status.Replicas) - return depl.Status.Replicas == int32(replicas) && depl.Generation == depl.Status.ObservedGeneration + return int(depl.Status.Replicas) == replicas && depl.Generation == depl.Status.ObservedGeneration }) } func HaveReadyReplicas(readyReplicas int) matcher.GomegaMatcher { return fetchDeploymentConfig(func(depl *openshiftappsv1.DeploymentConfig) bool { GinkgoWriter.Println("DeploymentConfig - HaveReadyReplicas:", "expected: ", readyReplicas, "actual: ", depl.Status.ReadyReplicas) - return depl.Status.ReadyReplicas == int32(readyReplicas) && depl.Generation == depl.Status.ObservedGeneration + return int(depl.Status.ReadyReplicas) == readyReplicas && depl.Generation == depl.Status.ObservedGeneration }) } diff --git a/test/openshift/e2e/ginkgo/fixture/fixture.go b/test/openshift/e2e/ginkgo/fixture/fixture.go index f9d753573..f5cf8e9a2 100644 --- a/test/openshift/e2e/ginkgo/fixture/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/fixture.go @@ -8,8 +8,10 @@ import ( "sync" "time" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/ginkgo/v2" //nolint:all + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/gomega" //nolint:all securityv1 "github.com/openshift/api/security/v1" "k8s.io/apimachinery/pkg/labels" @@ -99,9 +101,7 @@ func EnsureSequentialCleanSlateWithError() error { return err } - if err := RestoreSubcriptionToDefault(); err != nil { - return err - } + RestoreSubcriptionToDefault() // ensure namespaces created during test are deleted err := ensureTestNamespacesDeleted(ctx, k8sClient) @@ -504,12 +504,10 @@ func GetSubscriptionInEnvCIEnvironment(k8sClient client.Client) (*olmv1alpha1.Su } // RestoreSubcriptionToDefault ensures that the Subscription (or Deployment env vars) are restored to a default state before each test. -func RestoreSubcriptionToDefault() error { +func RestoreSubcriptionToDefault() { k8sClient, _, err := utils.GetE2ETestKubeClientWithError() - if err != nil { - return err - } + Expect(err).ToNot(HaveOccurred()) // optionalEnvVarsToRemove is a non-exhaustive list of environment variables that are known to be added to Subscription or operator Deployment by tests optionalEnvVarsToRemove := []string{"DISABLE_DEFAULT_ARGOCD_CONSOLELINK", "CONTROLLER_CLUSTER_ROLE", "SERVER_CLUSTER_ROLE", "ARGOCD_LABEL_SELECTOR"} @@ -522,50 +520,42 @@ func RestoreSubcriptionToDefault() error { deploymentFixture.RemoveEnv(depl, envKey) } - if err := waitForAllEnvVarsToBeRemovedFromDeployments(depl.Namespace, optionalEnvVarsToRemove, k8sClient); err != nil { - return err - } + err := waitForAllEnvVarsToBeRemovedFromDeployments(depl.Namespace, optionalEnvVarsToRemove, k8sClient) + Expect(err).ToNot(HaveOccurred()) Eventually(depl, "3m", "1s").Should(deploymentFixture.HaveReadyReplicas(1)) } else if EnvCI() { sub, err := GetSubscriptionInEnvCIEnvironment(k8sClient) - if err != nil { - return err - } + Expect(err).ToNot(HaveOccurred()) if sub != nil { subscriptionFixture.RemoveSpecConfig(sub) } - if err := waitForAllEnvVarsToBeRemovedFromDeployments("openshift-gitops-operator", optionalEnvVarsToRemove, k8sClient); err != nil { - return err - } + err = waitForAllEnvVarsToBeRemovedFromDeployments("openshift-gitops-operator", optionalEnvVarsToRemove, k8sClient) + Expect(err).ToNot(HaveOccurred()) WaitForAllDeploymentsInTheNamespaceToBeReady("openshift-gitops-operator", k8sClient) } else if EnvLocalRun() { // When running locally, there are no cluster resources to clean up - return nil } else { sub := &olmv1alpha1.Subscription{ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator", Namespace: "openshift-gitops-operator"}} - if err := k8sClient.Get(context.Background(), client.ObjectKeyFromObject(sub), sub); err != nil { - return err - } + err := k8sClient.Get(context.Background(), client.ObjectKeyFromObject(sub), sub) + Expect(err).ToNot(HaveOccurred()) subscriptionFixture.RemoveSpecConfig(sub) - if err := waitForAllEnvVarsToBeRemovedFromDeployments("openshift-gitops-operator", optionalEnvVarsToRemove, k8sClient); err != nil { - return err - } + err = waitForAllEnvVarsToBeRemovedFromDeployments("openshift-gitops-operator", optionalEnvVarsToRemove, k8sClient) + Expect(err).ToNot(HaveOccurred()) WaitForAllDeploymentsInTheNamespaceToBeReady("openshift-gitops-operator", k8sClient) - } - return nil + } } diff --git a/test/openshift/e2e/ginkgo/fixture/gitopsservice/fixture.go b/test/openshift/e2e/ginkgo/fixture/gitopsservice/fixture.go index 56b795192..78b431c77 100644 --- a/test/openshift/e2e/ginkgo/fixture/gitopsservice/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/gitopsservice/fixture.go @@ -3,7 +3,8 @@ package gitopsservice import ( "context" - . "github.com/onsi/gomega" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/gomega" //nolint:all gitopsoperatorv1alpha1 "github.com/redhat-developer/gitops-operator/api/v1alpha1" "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils" "k8s.io/client-go/util/retry" diff --git a/test/openshift/e2e/ginkgo/fixture/k8s/fixture.go b/test/openshift/e2e/ginkgo/fixture/k8s/fixture.go index 8380c2e5d..70d5f4b84 100644 --- a/test/openshift/e2e/ginkgo/fixture/k8s/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/k8s/fixture.go @@ -7,8 +7,10 @@ import ( "k8s.io/client-go/util/retry" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/ginkgo/v2" //nolint:all + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/gomega" //nolint:all matcher "github.com/onsi/gomega/types" "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils" diff --git a/test/openshift/e2e/ginkgo/fixture/namespace/fixture.go b/test/openshift/e2e/ginkgo/fixture/namespace/fixture.go index e1264bc6d..59c1c2c42 100644 --- a/test/openshift/e2e/ginkgo/fixture/namespace/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/namespace/fixture.go @@ -3,8 +3,10 @@ package namespace import ( "context" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/ginkgo/v2" //nolint:all + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/gomega" //nolint:all matcher "github.com/onsi/gomega/types" @@ -23,8 +25,8 @@ func HavePhase(expectedPhase corev1.NamespacePhase) matcher.GomegaMatcher { func HaveLabel(key string, value string) matcher.GomegaMatcher { return fetchNamespace(func(ns *corev1.Namespace) bool { - GinkgoWriter.Println("Namespace - HaveLabel: Key:", key, "Expected:", value, "/ Actual:", ns.ObjectMeta.Labels[key]) - return ns.ObjectMeta.Labels[key] == value + GinkgoWriter.Println("Namespace - HaveLabel: Key:", key, "Expected:", value, "/ Actual:", ns.Labels[key]) + return ns.Labels[key] == value }) } diff --git a/test/openshift/e2e/ginkgo/fixture/node/fixture.go b/test/openshift/e2e/ginkgo/fixture/node/fixture.go index 8605eb1ea..09bbb68ba 100644 --- a/test/openshift/e2e/ginkgo/fixture/node/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/node/fixture.go @@ -5,8 +5,10 @@ import ( "os" "strings" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/ginkgo/v2" //nolint:all + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/gomega" //nolint:all corev1 "k8s.io/api/core/v1" diff --git a/test/openshift/e2e/ginkgo/fixture/notificationsconfiguration/fixture.go b/test/openshift/e2e/ginkgo/fixture/notificationsconfiguration/fixture.go index b9f021b33..996787dd1 100644 --- a/test/openshift/e2e/ginkgo/fixture/notificationsconfiguration/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/notificationsconfiguration/fixture.go @@ -3,8 +3,10 @@ package notificationsconfiguration import ( "context" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/ginkgo/v2" //nolint:all + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/gomega" //nolint:all matcher "github.com/onsi/gomega/types" @@ -34,6 +36,8 @@ func Update(obj *argov1alpha1api.NotificationsConfiguration, modify func(*argov1 } // This is intentionally NOT exported, for now. Create another function in this file/package that calls this function, and export that. +// +//nolint:unused func fetchNotificationsConfiguration(f func(*argov1alpha1api.NotificationsConfiguration) bool) matcher.GomegaMatcher { return WithTransform(func(depl *argov1alpha1api.NotificationsConfiguration) bool { diff --git a/test/openshift/e2e/ginkgo/fixture/os/fixture.go b/test/openshift/e2e/ginkgo/fixture/os/fixture.go index 24cc9e8d5..608631ea2 100644 --- a/test/openshift/e2e/ginkgo/fixture/os/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/os/fixture.go @@ -3,7 +3,8 @@ package os import ( "os/exec" - . "github.com/onsi/ginkgo/v2" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/ginkgo/v2" //nolint:all ) func ExecCommand(cmdArgs ...string) (string, error) { @@ -14,6 +15,7 @@ func ExecCommand(cmdArgs ...string) (string, error) { func ExecCommandWithOutputParam(printOutput bool, cmdArgs ...string) (string, error) { GinkgoWriter.Println("executing command:", cmdArgs) + // #nosec G204 cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...) outputBytes, err := cmd.CombinedOutput() diff --git a/test/openshift/e2e/ginkgo/fixture/persistentvolume/fixture.go b/test/openshift/e2e/ginkgo/fixture/persistentvolume/fixture.go index 865d27e50..bbb4de02c 100644 --- a/test/openshift/e2e/ginkgo/fixture/persistentvolume/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/persistentvolume/fixture.go @@ -3,8 +3,10 @@ package persistentvolume import ( "context" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/ginkgo/v2" //nolint:all + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/gomega" //nolint:all matcher "github.com/onsi/gomega/types" "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils" corev1 "k8s.io/api/core/v1" diff --git a/test/openshift/e2e/ginkgo/fixture/pod/fixture.go b/test/openshift/e2e/ginkgo/fixture/pod/fixture.go index e646f43c2..301596555 100644 --- a/test/openshift/e2e/ginkgo/fixture/pod/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/pod/fixture.go @@ -3,8 +3,10 @@ package pod import ( "context" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/ginkgo/v2" //nolint:all + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/gomega" //nolint:all matcher "github.com/onsi/gomega/types" "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils" corev1 "k8s.io/api/core/v1" diff --git a/test/openshift/e2e/ginkgo/fixture/role/fixture.go b/test/openshift/e2e/ginkgo/fixture/role/fixture.go index e0399b7ac..1cfc4869b 100644 --- a/test/openshift/e2e/ginkgo/fixture/role/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/role/fixture.go @@ -4,8 +4,10 @@ import ( "context" "reflect" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/ginkgo/v2" //nolint:all + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/gomega" //nolint:all matcher "github.com/onsi/gomega/types" "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils" rbacv1 "k8s.io/api/rbac/v1" diff --git a/test/openshift/e2e/ginkgo/fixture/rolebinding/fixture.go b/test/openshift/e2e/ginkgo/fixture/rolebinding/fixture.go index f102af820..11f57997f 100644 --- a/test/openshift/e2e/ginkgo/fixture/rolebinding/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/rolebinding/fixture.go @@ -4,8 +4,10 @@ import ( "context" "reflect" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/ginkgo/v2" //nolint:all + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/gomega" //nolint:all matcher "github.com/onsi/gomega/types" "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils" rbacv1 "k8s.io/api/rbac/v1" diff --git a/test/openshift/e2e/ginkgo/fixture/route/fixture.go b/test/openshift/e2e/ginkgo/fixture/route/fixture.go index 17bddb02a..3558b2243 100644 --- a/test/openshift/e2e/ginkgo/fixture/route/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/route/fixture.go @@ -4,8 +4,10 @@ import ( "context" "reflect" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/ginkgo/v2" //nolint:all + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/gomega" //nolint:all matcher "github.com/onsi/gomega/types" corev1 "k8s.io/api/core/v1" diff --git a/test/openshift/e2e/ginkgo/fixture/secret/fixture.go b/test/openshift/e2e/ginkgo/fixture/secret/fixture.go index cd0763a63..abb9e6266 100644 --- a/test/openshift/e2e/ginkgo/fixture/secret/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/secret/fixture.go @@ -4,8 +4,10 @@ import ( "bytes" "context" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/ginkgo/v2" //nolint:all + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/gomega" //nolint:all matcher "github.com/onsi/gomega/types" "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils" corev1 "k8s.io/api/core/v1" diff --git a/test/openshift/e2e/ginkgo/fixture/statefulset/fixture.go b/test/openshift/e2e/ginkgo/fixture/statefulset/fixture.go index 3fb2e75d4..21ca42152 100644 --- a/test/openshift/e2e/ginkgo/fixture/statefulset/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/statefulset/fixture.go @@ -5,8 +5,10 @@ import ( "reflect" "strings" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/ginkgo/v2" //nolint:all + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/gomega" //nolint:all matcher "github.com/onsi/gomega/types" "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils" @@ -39,14 +41,14 @@ func Update(obj *appsv1.StatefulSet, modify func(*appsv1.StatefulSet)) { func HaveReplicas(replicas int) matcher.GomegaMatcher { return fetchStatefulSet(func(ss *appsv1.StatefulSet) bool { GinkgoWriter.Println("StatefulSet HaveReplicas:", "expected: ", replicas, "actual: ", ss.Status.Replicas) - return ss.Status.Replicas == int32(replicas) && ss.Generation == ss.Status.ObservedGeneration + return int(ss.Status.Replicas) == replicas && ss.Generation == ss.Status.ObservedGeneration }) } func HaveReadyReplicas(readyReplicas int) matcher.GomegaMatcher { return fetchStatefulSet(func(ss *appsv1.StatefulSet) bool { GinkgoWriter.Println("StatefulSet HaveReadyReplicas:", "expected: ", readyReplicas, "actual: ", ss.Status.ReadyReplicas) - return ss.Status.ReadyReplicas == int32(readyReplicas) && ss.Generation == ss.Status.ObservedGeneration + return int(ss.Status.ReadyReplicas) == readyReplicas && ss.Generation == ss.Status.ObservedGeneration }) } diff --git a/test/openshift/e2e/ginkgo/fixture/subscription/fixture.go b/test/openshift/e2e/ginkgo/fixture/subscription/fixture.go index 7a4b2ab8a..a2e54a964 100644 --- a/test/openshift/e2e/ginkgo/fixture/subscription/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/subscription/fixture.go @@ -10,7 +10,8 @@ import ( "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils" corev1 "k8s.io/api/core/v1" - . "github.com/onsi/gomega" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/gomega" //nolint:all ) func GetEnv(s *olmv1alpha1.Subscription, key string) (*string, error) { diff --git a/test/openshift/e2e/ginkgo/fixture/utils/fixtureUtils.go b/test/openshift/e2e/ginkgo/fixture/utils/fixtureUtils.go index 2c6237613..67ffeb771 100644 --- a/test/openshift/e2e/ginkgo/fixture/utils/fixtureUtils.go +++ b/test/openshift/e2e/ginkgo/fixture/utils/fixtureUtils.go @@ -29,7 +29,8 @@ import ( rbacv1 "k8s.io/api/rbac/v1" crdv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" - . "github.com/onsi/gomega" + //lint:ignore ST1001 "This is a common practice in Gomega tests for readability." + . "github.com/onsi/gomega" //nolint:all ) func GetE2ETestKubeClient() (client.Client, *runtime.Scheme) { diff --git a/test/openshift/e2e/ginkgo/parallel/1-001_alpha_to_beta_dex_conversion_test.go b/test/openshift/e2e/ginkgo/parallel/1-001_alpha_to_beta_dex_conversion_test.go index 25e4d8dee..f681706d9 100644 --- a/test/openshift/e2e/ginkgo/parallel/1-001_alpha_to_beta_dex_conversion_test.go +++ b/test/openshift/e2e/ginkgo/parallel/1-001_alpha_to_beta_dex_conversion_test.go @@ -92,8 +92,8 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { And(argocdFixture.HavePhase("Available"), argocdFixture.HaveSSOStatus("Running"))) Expect(argoCDbeta1.Spec.SSO.Provider).To(Equal(argov1beta1api.SSOProviderTypeDex)) - Expect(argoCDbeta1.Spec.SSO.Dex.OpenShiftOAuth).To(Equal(true)) - Expect(argoCDbeta1.Spec.Server.Route.Enabled).To(Equal(true)) + Expect(argoCDbeta1.Spec.SSO.Dex.OpenShiftOAuth).To(BeTrue()) + Expect(argoCDbeta1.Spec.Server.Route.Enabled).To(BeTrue()) By("deleting ArgoCD CR via v1alpha1 API") Expect(k8sClient.Delete(ctx, argoCDalpha1)).To(Succeed()) diff --git a/test/openshift/e2e/ginkgo/parallel/1-002_alpha_to_beta_keycloak_conversion_test.go b/test/openshift/e2e/ginkgo/parallel/1-002_alpha_to_beta_keycloak_conversion_test.go index 842d6c123..cb1d7384a 100644 --- a/test/openshift/e2e/ginkgo/parallel/1-002_alpha_to_beta_keycloak_conversion_test.go +++ b/test/openshift/e2e/ginkgo/parallel/1-002_alpha_to_beta_keycloak_conversion_test.go @@ -91,7 +91,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { And(argocdFixture.HavePhase("Available"))) Expect(argoCDbeta1.Spec.SSO.Provider).To(Equal(argov1beta1api.SSOProviderTypeKeycloak)) - Expect(*argoCDbeta1.Spec.SSO.Keycloak.VerifyTLS).To(Equal(false)) + Expect(*argoCDbeta1.Spec.SSO.Keycloak.VerifyTLS).To(BeFalse()) Expect(argoCDbeta1.Spec.ExtraConfig["oidc.tls.insecure.skip.verify"]).To(Equal("true")) By("deleting ArgoCD CR via v1alpha1 API") diff --git a/test/openshift/e2e/ginkgo/parallel/1-003_alpha_to_beta_sso_conflict_conversion_test.go b/test/openshift/e2e/ginkgo/parallel/1-003_alpha_to_beta_sso_conflict_conversion_test.go index bd7870e1e..f8cb6460d 100644 --- a/test/openshift/e2e/ginkgo/parallel/1-003_alpha_to_beta_sso_conflict_conversion_test.go +++ b/test/openshift/e2e/ginkgo/parallel/1-003_alpha_to_beta_sso_conflict_conversion_test.go @@ -97,9 +97,9 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { And(argocdFixture.HaveSSOStatus("Failed"))) Expect(argoCDbeta1.Spec.SSO.Provider).To(Equal(argov1beta1api.SSOProviderTypeDex)) - Expect(argoCDbeta1.Spec.SSO.Dex.OpenShiftOAuth).To(Equal(true)) + Expect(argoCDbeta1.Spec.SSO.Dex.OpenShiftOAuth).To(BeTrue()) Expect(argoCDbeta1.Spec.SSO.Keycloak.RootCA).To(Equal("\"---BEGIN---END---\"")) - Expect(*argoCDbeta1.Spec.SSO.Keycloak.VerifyTLS).To(Equal(false)) + Expect(*argoCDbeta1.Spec.SSO.Keycloak.VerifyTLS).To(BeFalse()) Expect(argoCDbeta1.Spec.ExtraConfig["oidc.tls.insecure.skip.verify"]).To(Equal("true")) By("deleting ArgoCD CR via v1alpha1 API") diff --git a/test/openshift/e2e/ginkgo/parallel/1-004_beta_to_alpha_conversion_test.go b/test/openshift/e2e/ginkgo/parallel/1-004_beta_to_alpha_conversion_test.go index 867d1bc08..930338e1c 100644 --- a/test/openshift/e2e/ginkgo/parallel/1-004_beta_to_alpha_conversion_test.go +++ b/test/openshift/e2e/ginkgo/parallel/1-004_beta_to_alpha_conversion_test.go @@ -103,8 +103,8 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { }, "4m", "5s").Should(BeTrue()) Expect(argoCDAlpha1.Spec.SSO.Provider).To(Equal(argov1alpha1api.SSOProviderTypeDex)) - Expect(argoCDAlpha1.Spec.SSO.Dex.OpenShiftOAuth).To(Equal(true)) - Expect(argoCDAlpha1.Spec.Server.Route.Enabled).To(Equal(true)) + Expect(argoCDAlpha1.Spec.SSO.Dex.OpenShiftOAuth).To(BeTrue()) + Expect(argoCDAlpha1.Spec.Server.Route.Enabled).To(BeTrue()) dexDeployment := &corev1.Deployment{ ObjectMeta: metav1.ObjectMeta{ diff --git a/test/openshift/e2e/ginkgo/parallel/1-009_validate-manage-other-namespace_test.go b/test/openshift/e2e/ginkgo/parallel/1-009_validate-manage-other-namespace_test.go index 14432293c..85f3b09cc 100644 --- a/test/openshift/e2e/ginkgo/parallel/1-009_validate-manage-other-namespace_test.go +++ b/test/openshift/e2e/ginkgo/parallel/1-009_validate-manage-other-namespace_test.go @@ -72,7 +72,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { By("modifying the labels of another namespace to add the argocd managed-by label") namespace.Update(nsTest_1_9_custom, func(n *corev1.Namespace) { - n.ObjectMeta.Labels["argocd.argoproj.io/managed-by"] = argoCDInRandomNS.Namespace + n.Labels["argocd.argoproj.io/managed-by"] = argoCDInRandomNS.Namespace }) By("verifying that Argo CD eventually includes this other namespace in its Secret list of managed namespaces") @@ -114,7 +114,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { By("removing managed-by label from that other Namespace") namespace.Update(nsTest_1_9_custom, func(n *corev1.Namespace) { - delete(n.ObjectMeta.Labels, "argocd.argoproj.io/managed-by") + delete(n.Labels, "argocd.argoproj.io/managed-by") }) By("verifying label is removed from Argo CD Secret") diff --git a/test/openshift/e2e/ginkgo/parallel/1-012_validate-managed-by-chain_test.go b/test/openshift/e2e/ginkgo/parallel/1-012_validate-managed-by-chain_test.go index 7c55eeca5..ec0cfd484 100644 --- a/test/openshift/e2e/ginkgo/parallel/1-012_validate-managed-by-chain_test.go +++ b/test/openshift/e2e/ginkgo/parallel/1-012_validate-managed-by-chain_test.go @@ -95,7 +95,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { Expect(rb.RoleRef.APIGroup).To(Equal("rbac.authorization.k8s.io")) Expect(rb.RoleRef.Kind).To(Equal("Role")) Expect(rb.RoleRef.Name).To(Equal("argocd-argocd-server")) - Expect(len(rb.Subjects)).To(Equal(1)) + Expect(rb.Subjects).To(HaveLen(1)) Expect(rb.Subjects[0]).To(Equal(rbacv1.Subject{Kind: "ServiceAccount", Name: "argocd-argocd-server", Namespace: argoCDRandomNS.Namespace})) } expectRoleAndRoleBindingAreValidForManagedNamespace(nsTest_1_12_custom.Name) diff --git a/test/openshift/e2e/ginkgo/parallel/1-057_validate_notifications_test.go b/test/openshift/e2e/ginkgo/parallel/1-057_validate_notifications_test.go index 3ec27e145..fb3df407c 100644 --- a/test/openshift/e2e/ginkgo/parallel/1-057_validate_notifications_test.go +++ b/test/openshift/e2e/ginkgo/parallel/1-057_validate_notifications_test.go @@ -213,7 +213,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { By("waiting for Argo CD to send an email to smtp4dev Pod indicating that the Application was created") podList := &corev1.PodList{} - Expect(k8sClient.List(ctx, podList, &client.ListOptions{Namespace: ns.Name})) + Expect(k8sClient.List(ctx, podList, &client.ListOptions{Namespace: ns.Name})).To(Succeed()) var smtp4DevPod *corev1.Pod for idx := range podList.Items { item := podList.Items[idx] diff --git a/test/openshift/e2e/ginkgo/parallel/1-064_validate_security_contexts_test.go b/test/openshift/e2e/ginkgo/parallel/1-064_validate_security_contexts_test.go index 763b4725b..73b25d902 100644 --- a/test/openshift/e2e/ginkgo/parallel/1-064_validate_security_contexts_test.go +++ b/test/openshift/e2e/ginkgo/parallel/1-064_validate_security_contexts_test.go @@ -114,7 +114,8 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { secContext := container.SecurityContext Expect(secContext).ToNot(BeNil()) - if depl.Name == "argocd-applicationset-controller" { + switch depl.Name { + case "argocd-applicationset-controller": Expect(*secContext).To(Equal(corev1.SecurityContext{ Capabilities: &corev1.Capabilities{Drop: []corev1.Capability{"ALL"}}, AllowPrivilegeEscalation: ptr.To(false), @@ -125,7 +126,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { LocalhostProfile: nil, }, })) - } else if depl.Name == "argocd-dex-server" { + case "argocd-dex-server": Expect(*secContext).To(Equal(corev1.SecurityContext{ Capabilities: &corev1.Capabilities{Drop: []corev1.Capability{"ALL"}}, AllowPrivilegeEscalation: ptr.To(false), @@ -136,7 +137,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { LocalhostProfile: nil, }, })) - } else if depl.Name == "argocd-notifications-controller" { + case "argocd-notifications-controller": Expect(*secContext).To(Equal(corev1.SecurityContext{ Capabilities: &corev1.Capabilities{Drop: []corev1.Capability{"ALL"}}, AllowPrivilegeEscalation: ptr.To(false), @@ -150,7 +151,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { Expect(depl.Spec.Template.Spec.SecurityContext.RunAsNonRoot).To(Equal(ptr.To(true))) - } else if depl.Name == "argocd-redis" { + case "argocd-redis": Expect(*secContext).To(Equal(corev1.SecurityContext{ Capabilities: &corev1.Capabilities{Drop: []corev1.Capability{"ALL"}}, AllowPrivilegeEscalation: ptr.To(false), @@ -162,7 +163,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { }, })) - } else if depl.Name == "argocd-repo-server" { + case "argocd-repo-server": Expect(*secContext).To(Equal(corev1.SecurityContext{ Capabilities: &corev1.Capabilities{Drop: []corev1.Capability{"ALL"}}, AllowPrivilegeEscalation: ptr.To(false), @@ -174,7 +175,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { }, })) - } else if depl.Name == "argocd-server" { + case "argocd-server": Expect(*secContext).To(Equal(corev1.SecurityContext{ Capabilities: &corev1.Capabilities{Drop: []corev1.Capability{"ALL"}}, AllowPrivilegeEscalation: ptr.To(false), @@ -186,7 +187,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { }, })) - } else { + default: Fail("unrecognized deployment: " + depl.Name) } } diff --git a/test/openshift/e2e/ginkgo/parallel/1-066_validate_redis_secure_comm_no_autotls_no_ha_test.go b/test/openshift/e2e/ginkgo/parallel/1-066_validate_redis_secure_comm_no_autotls_no_ha_test.go index f09a2c6c3..02bc26a10 100644 --- a/test/openshift/e2e/ginkgo/parallel/1-066_validate_redis_secure_comm_no_autotls_no_ha_test.go +++ b/test/openshift/e2e/ginkgo/parallel/1-066_validate_redis_secure_comm_no_autotls_no_ha_test.go @@ -90,18 +90,18 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { By("generating a test certificate to use with redis, using openssl") redis_crt_File, err := os.CreateTemp("", "redis.crt") - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) redis_key_File, err := os.CreateTemp("", "redis.key") - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) openssl_test_File, err := os.CreateTemp("", "openssl_test.cnf") - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) opensslTestCNFContents := "\n[SAN]\nsubjectAltName=DNS:argocd-redis." + ns.Name + ".svc.cluster.local\n[req]\ndistinguished_name=req" err = os.WriteFile(openssl_test_File.Name(), ([]byte)(opensslTestCNFContents), 0666) - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) _, err = osFixture.ExecCommandWithOutputParam(false, "openssl", "req", "-new", "-x509", "-sha256", "-subj", "/C=XX/ST=XX/O=Testing/CN=redis", diff --git a/test/openshift/e2e/ginkgo/parallel/1-067_validate_redis_secure_comm_no_autotls_ha_test.go b/test/openshift/e2e/ginkgo/parallel/1-067_validate_redis_secure_comm_no_autotls_ha_test.go index 98054f27a..cd82dfae8 100644 --- a/test/openshift/e2e/ginkgo/parallel/1-067_validate_redis_secure_comm_no_autotls_ha_test.go +++ b/test/openshift/e2e/ginkgo/parallel/1-067_validate_redis_secure_comm_no_autotls_ha_test.go @@ -108,18 +108,18 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { By("generating a test certificate to use with redis, using openssl") redis_crt_File, err := os.CreateTemp("", "redis.crt") - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) redis_key_File, err := os.CreateTemp("", "redis.key") - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) openssl_test_File, err := os.CreateTemp("", "openssl_test.cnf") - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) opensslTestCNFContents := "\n[SAN]\nsubjectAltName=DNS:argocd-redis." + ns.Name + ".svc.cluster.local\n[req]\ndistinguished_name=req" err = os.WriteFile(openssl_test_File.Name(), ([]byte)(opensslTestCNFContents), 0666) - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) _, err = osFixture.ExecCommandWithOutputParam(false, "openssl", "req", "-new", "-x509", "-sha256", "-subj", "/C=XX/ST=XX/O=Testing/CN=redis", diff --git a/test/openshift/e2e/ginkgo/parallel/1-083_validate_resource_customization_subkeys_test.go b/test/openshift/e2e/ginkgo/parallel/1-083_validate_resource_customization_subkeys_test.go index 7704e6860..8e814b022 100644 --- a/test/openshift/e2e/ginkgo/parallel/1-083_validate_resource_customization_subkeys_test.go +++ b/test/openshift/e2e/ginkgo/parallel/1-083_validate_resource_customization_subkeys_test.go @@ -144,7 +144,7 @@ spec: // We unmarshal YAML into ArgoCD CR, so that we don't have to convert it into Go structs (it would be painful) argoCD := &argov1beta1api.ArgoCD{} Expect(yaml.UnmarshalStrict([]byte(argoCDYAML), &argoCD)).To(Succeed()) - argoCD.ObjectMeta.Namespace = ns.Name + argoCD.Namespace = ns.Name Expect(k8sClient.Create(ctx, argoCD)).To(Succeed()) By("waiting for ArgoCD CR to be reconciled and the instance to be ready") diff --git a/test/openshift/e2e/ginkgo/parallel/1-090_validate_permissions_test.go b/test/openshift/e2e/ginkgo/parallel/1-090_validate_permissions_test.go index 4005a7388..a47de6eb3 100644 --- a/test/openshift/e2e/ginkgo/parallel/1-090_validate_permissions_test.go +++ b/test/openshift/e2e/ginkgo/parallel/1-090_validate_permissions_test.go @@ -727,10 +727,10 @@ spec: Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(actualCsv), actualCsv)).To(Succeed()) // We don't need to compare the .serviceAccountName field so set it to empty - Expect(len(actualCsv.Spec.InstallStrategy.StrategySpec.ClusterPermissions)).To(Equal(1)) + Expect(actualCsv.Spec.InstallStrategy.StrategySpec.ClusterPermissions).To(HaveLen(1)) actualCsv.Spec.InstallStrategy.StrategySpec.ClusterPermissions[0].ServiceAccountName = "" - Expect(len(expectedCsv.Spec.InstallStrategy.StrategySpec.ClusterPermissions)).To(Equal(1)) + Expect(expectedCsv.Spec.InstallStrategy.StrategySpec.ClusterPermissions).To(HaveLen(1)) Expect(actualCsv.Spec.InstallStrategy.StrategySpec.ClusterPermissions).To(Equal(expectedCsv.Spec.InstallStrategy.StrategySpec.ClusterPermissions)) diff --git a/test/openshift/e2e/ginkgo/parallel/1-111_validate_appcontroller_initcontainers_test.go b/test/openshift/e2e/ginkgo/parallel/1-111_validate_appcontroller_initcontainers_test.go index 271759572..5432a5e4f 100644 --- a/test/openshift/e2e/ginkgo/parallel/1-111_validate_appcontroller_initcontainers_test.go +++ b/test/openshift/e2e/ginkgo/parallel/1-111_validate_appcontroller_initcontainers_test.go @@ -85,7 +85,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { Eventually(pod, "4m", "5s").Should(k8sFixture.ExistByName()) - Expect(len(pod.Spec.InitContainers)).To(Equal(1)) + Expect(pod.Spec.InitContainers).To(HaveLen(1)) Expect(pod.Spec.InitContainers[0].Name).To(Equal("argocd-init")) Expect(pod.Spec.InitContainers[0].Image).To(Equal("quay.io/nginx/nginx-unprivileged:latest")) @@ -103,7 +103,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { }, })) - Expect(len(pod.Spec.Containers)).To(Equal(1)) + Expect(pod.Spec.Containers).To(HaveLen(1)) Expect(pod.Spec.Containers[0].Name).To(Equal("argocd-application-controller")) diff --git a/test/openshift/e2e/ginkgo/parallel/1-112_validate_server_initcontainers_test.go b/test/openshift/e2e/ginkgo/parallel/1-112_validate_server_initcontainers_test.go index df5d9e4e9..c59b6d835 100644 --- a/test/openshift/e2e/ginkgo/parallel/1-112_validate_server_initcontainers_test.go +++ b/test/openshift/e2e/ginkgo/parallel/1-112_validate_server_initcontainers_test.go @@ -86,7 +86,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { Eventually(depl, "4m", "5s").Should(k8sFixture.ExistByName()) - Expect(len(depl.Spec.Template.Spec.InitContainers)).To(Equal(1)) + Expect(depl.Spec.Template.Spec.InitContainers).To(HaveLen(1)) Expect(depl.Spec.Template.Spec.InitContainers[0].Name).To(Equal("argocd-init")) Expect(depl.Spec.Template.Spec.InitContainers[0].Image).To(Equal("quay.io/nginx/nginx-unprivileged:latest")) @@ -104,7 +104,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { }, })) - Expect(len(depl.Spec.Template.Spec.Containers)).To(Equal(1)) + Expect(depl.Spec.Template.Spec.Containers).To(HaveLen(1)) Expect(depl.Spec.Template.Spec.Containers[0].Name).To(Equal("argocd-server")) diff --git a/test/openshift/e2e/ginkgo/parallel/1-113_validate_appcontroller_sidecar_test.go b/test/openshift/e2e/ginkgo/parallel/1-113_validate_appcontroller_sidecar_test.go index 09f1325f3..f6148c237 100644 --- a/test/openshift/e2e/ginkgo/parallel/1-113_validate_appcontroller_sidecar_test.go +++ b/test/openshift/e2e/ginkgo/parallel/1-113_validate_appcontroller_sidecar_test.go @@ -84,7 +84,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { Eventually(pod, "4m", "5s").Should(k8sFixture.ExistByName()) - Expect(len(pod.Spec.Containers)).To(Equal(2)) + Expect(pod.Spec.Containers).To(HaveLen(2)) Expect(pod.Spec.Containers[1].Name).To(Equal("sidecar")) Expect(pod.Spec.Containers[1].Image).To(Equal("quay.io/fedora/fedora:latest")) diff --git a/test/openshift/e2e/ginkgo/parallel/1-114_validate_server_sidecar_test.go b/test/openshift/e2e/ginkgo/parallel/1-114_validate_server_sidecar_test.go index 4652ae459..b002d5935 100644 --- a/test/openshift/e2e/ginkgo/parallel/1-114_validate_server_sidecar_test.go +++ b/test/openshift/e2e/ginkgo/parallel/1-114_validate_server_sidecar_test.go @@ -85,7 +85,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { Eventually(pod, "4m", "5s").Should(k8sFixture.ExistByName()) - Expect(len(pod.Spec.Template.Spec.Containers)).To(Equal(2)) + Expect(pod.Spec.Template.Spec.Containers).To(HaveLen(2)) Expect(pod.Spec.Template.Spec.Containers[1].Name).To(Equal("sidecar")) Expect(pod.Spec.Template.Spec.Containers[1].Image).To(Equal("quay.io/fedora/fedora:latest")) diff --git a/test/openshift/e2e/ginkgo/sequential/1-010_validate-ootb-manage-other-namespace_test.go b/test/openshift/e2e/ginkgo/sequential/1-010_validate-ootb-manage-other-namespace_test.go index a4427da04..dc89f1563 100644 --- a/test/openshift/e2e/ginkgo/sequential/1-010_validate-ootb-manage-other-namespace_test.go +++ b/test/openshift/e2e/ginkgo/sequential/1-010_validate-ootb-manage-other-namespace_test.go @@ -123,7 +123,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() { By("removing managed-by label from the other namespace") namespace.Update(nsTest_1_10_custom, func(n *corev1.Namespace) { - delete(n.ObjectMeta.Labels, "argocd.argoproj.io/managed-by") + delete(n.Labels, "argocd.argoproj.io/managed-by") }) By("verifying Argo CD managed-by roles and rolebindings are removed from other namespace") diff --git a/test/openshift/e2e/ginkgo/sequential/1-018_validate_disable_default_instance_test.go b/test/openshift/e2e/ginkgo/sequential/1-018_validate_disable_default_instance_test.go index f480de2db..069c7261e 100644 --- a/test/openshift/e2e/ginkgo/sequential/1-018_validate_disable_default_instance_test.go +++ b/test/openshift/e2e/ginkgo/sequential/1-018_validate_disable_default_instance_test.go @@ -85,7 +85,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() { Eventually(gitopsServerDepl).Should(k8sFixture.NotExistByName()) By("remove the DISABLE_DEFAULT_ARGOCD_INSTANCE env var we set above") - Expect(fixture.RestoreSubcriptionToDefault()).To(Succeed()) + fixture.RestoreSubcriptionToDefault() Eventually(openshiftGitopsArgoCD, "3m", "5s").Should(k8sFixture.ExistByName()) Eventually(openshiftGitopsArgoCD, "5m", "5s").Should(argocdFixture.BeAvailable()) diff --git a/test/openshift/e2e/ginkgo/sequential/1-028-validate_run_on_infra_test.go b/test/openshift/e2e/ginkgo/sequential/1-028-validate_run_on_infra_test.go index 721b36f07..0190160ea 100644 --- a/test/openshift/e2e/ginkgo/sequential/1-028-validate_run_on_infra_test.go +++ b/test/openshift/e2e/ginkgo/sequential/1-028-validate_run_on_infra_test.go @@ -197,12 +197,12 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() { By("verifying that the resources in openshift-gitops no longer have run on infra tolerations/label set") clusterDepl = &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: "openshift-gitops"}} - Eventually(serverDepl).ShouldNot(deploymentFixture.HaveTemplateSpecNodeSelector(map[string]string{ + Eventually(clusterDepl).ShouldNot(deploymentFixture.HaveTemplateSpecNodeSelector(map[string]string{ "node-role.kubernetes.io/infra": "", "kubernetes.io/os": "linux", })) - Eventually(serverDepl).ShouldNot(deploymentFixture.HaveTolerations([]corev1.Toleration{ + Eventually(clusterDepl).ShouldNot(deploymentFixture.HaveTolerations([]corev1.Toleration{ {Key: "infra", Effect: "NoSchedule", Value: "reserved"}}), ) diff --git a/test/openshift/e2e/ginkgo/sequential/1-034_validate_custom_roles_test.go b/test/openshift/e2e/ginkgo/sequential/1-034_validate_custom_roles_test.go index 337c8bf84..c2642b76f 100644 --- a/test/openshift/e2e/ginkgo/sequential/1-034_validate_custom_roles_test.go +++ b/test/openshift/e2e/ginkgo/sequential/1-034_validate_custom_roles_test.go @@ -119,7 +119,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() { defer func() { By("cleaning up changes to the Subscription or operator Deployment") - Expect(fixture.RestoreSubcriptionToDefault()).To(Succeed()) + fixture.RestoreSubcriptionToDefault() }() By("checking if the default roles are removed from the namespace") diff --git a/test/openshift/e2e/ginkgo/sequential/1-036_validate_role_rolebinding_for_source_namespace_test.go b/test/openshift/e2e/ginkgo/sequential/1-036_validate_role_rolebinding_for_source_namespace_test.go index b8ff61aa6..a064c5df2 100644 --- a/test/openshift/e2e/ginkgo/sequential/1-036_validate_role_rolebinding_for_source_namespace_test.go +++ b/test/openshift/e2e/ginkgo/sequential/1-036_validate_role_rolebinding_for_source_namespace_test.go @@ -85,9 +85,9 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() { }, } Eventually(roleTestNamespace).Should(k8sFixture.ExistByName()) - Expect(roleTestNamespace.ObjectMeta.Labels["app.kubernetes.io/managed-by"], "example-argocd") - Expect(roleTestNamespace.ObjectMeta.Labels["app.kubernetes.io/name"], "example-argocd") - Expect(roleTestNamespace.ObjectMeta.Labels["app.kubernetes.io/part-of"], "argocd") + Expect(roleTestNamespace.Labels["app.kubernetes.io/managed-by"]).To(Equal("example-argocd")) + Expect(roleTestNamespace.Labels["app.kubernetes.io/name"]).To(Equal("example-argocd")) + Expect(roleTestNamespace.Labels["app.kubernetes.io/part-of"]).To(Equal("argocd")) rbTestNamespace := &rbacv1.RoleBinding{ ObjectMeta: metav1.ObjectMeta{ diff --git a/test/openshift/e2e/ginkgo/sequential/1-071_validate_SCC_HA_test.go b/test/openshift/e2e/ginkgo/sequential/1-071_validate_SCC_HA_test.go index e7c093711..500b879c2 100644 --- a/test/openshift/e2e/ginkgo/sequential/1-071_validate_SCC_HA_test.go +++ b/test/openshift/e2e/ginkgo/sequential/1-071_validate_SCC_HA_test.go @@ -63,7 +63,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() { if err := k8sClient.Get(ctx, client.ObjectKeyFromObject(scc), scc); err == nil { Expect(k8sClient.Delete(ctx, scc)).To(Succeed()) } else { - Expect(err).ToNot(BeNil()) + Expect(err).To(HaveOccurred()) } scc = &securityv1.SecurityContextConstraints{ diff --git a/test/openshift/e2e/ginkgo/sequential/1-074_validate_terminating_namespace_block_test.go b/test/openshift/e2e/ginkgo/sequential/1-074_validate_terminating_namespace_block_test.go index 5ca8ab835..4158b29cc 100644 --- a/test/openshift/e2e/ginkgo/sequential/1-074_validate_terminating_namespace_block_test.go +++ b/test/openshift/e2e/ginkgo/sequential/1-074_validate_terminating_namespace_block_test.go @@ -111,7 +111,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() { defer func() { // At the end of the test, remove the finalizer from the ConfigMap so the NS can be deleted. configmapFixture.Update(firstConfigMap, func(cm *corev1.ConfigMap) { - cm.ObjectMeta.Finalizers = nil + cm.Finalizers = nil }) }() diff --git a/test/openshift/e2e/ginkgo/sequential/1-078_validate_default_argocd_consoleLink_test.go b/test/openshift/e2e/ginkgo/sequential/1-078_validate_default_argocd_consoleLink_test.go index 5bf52d1eb..f820f6324 100644 --- a/test/openshift/e2e/ginkgo/sequential/1-078_validate_default_argocd_consoleLink_test.go +++ b/test/openshift/e2e/ginkgo/sequential/1-078_validate_default_argocd_consoleLink_test.go @@ -101,7 +101,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() { By("cleaning up operator and ensuring ConsoleLink exists") - Expect(fixture.RestoreSubcriptionToDefault()).To(Succeed()) + fixture.RestoreSubcriptionToDefault() Eventually(consoleLink).Should(k8sFixture.ExistByName()) Consistently(consoleLink).Should(k8sFixture.ExistByName()) diff --git a/test/openshift/e2e/ginkgo/sequential/1-083_validate_apps_in_any_namespace_test.go b/test/openshift/e2e/ginkgo/sequential/1-083_validate_apps_in_any_namespace_test.go index 776615f2b..b17a4e535 100644 --- a/test/openshift/e2e/ginkgo/sequential/1-083_validate_apps_in_any_namespace_test.go +++ b/test/openshift/e2e/ginkgo/sequential/1-083_validate_apps_in_any_namespace_test.go @@ -300,7 +300,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() { By("7) Remove managed-by from test-1-24-custom and verify the roles exist again") namespaceFixture.Update(test_1_24_customNS, func(n *corev1.Namespace) { - delete(n.ObjectMeta.Labels, "argocd.argoproj.io/managed-by") + delete(n.Labels, "argocd.argoproj.io/managed-by") }) By("restarts the server and app controller workloads. I presume this is because their startup is too slow to pick up the RBAC changes we have made (removing the label)") diff --git a/test/openshift/e2e/ginkgo/sequential/1-102_validate_handle_terminating_namespaces_test.go b/test/openshift/e2e/ginkgo/sequential/1-102_validate_handle_terminating_namespaces_test.go index 5042ad59a..f81d5636c 100644 --- a/test/openshift/e2e/ginkgo/sequential/1-102_validate_handle_terminating_namespaces_test.go +++ b/test/openshift/e2e/ginkgo/sequential/1-102_validate_handle_terminating_namespaces_test.go @@ -79,7 +79,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() { // At the end of the test, ensure the ConfigMap finalizer is removed so that the namespace is cleaned up defer func() { configmapFixture.Update(&configMapJaneNs, func(cm *corev1.ConfigMap) { - cm.ObjectMeta.Finalizers = nil + cm.Finalizers = nil }) }() diff --git a/test/openshift/e2e/ginkgo/sequential/1-105_validate_label_selector_test.go b/test/openshift/e2e/ginkgo/sequential/1-105_validate_label_selector_test.go index 4274e90fe..8bd04f5c5 100644 --- a/test/openshift/e2e/ginkgo/sequential/1-105_validate_label_selector_test.go +++ b/test/openshift/e2e/ginkgo/sequential/1-105_validate_label_selector_test.go @@ -44,7 +44,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() { fixture.SetEnvInOperatorSubscriptionOrDeployment("ARGOCD_LABEL_SELECTOR", "foo=bar") defer func() { // Restore subscription to default after test - Expect(fixture.RestoreSubcriptionToDefault()).To(Succeed()) + fixture.RestoreSubcriptionToDefault() }() By("creating new namespace-scoped ArgoCD instance in test-argocd") diff --git a/test/openshift/e2e/ginkgo/sequential/1-111_validate_default_argocd_route_test.go b/test/openshift/e2e/ginkgo/sequential/1-111_validate_default_argocd_route_test.go index 817af9655..c88f392fa 100644 --- a/test/openshift/e2e/ginkgo/sequential/1-111_validate_default_argocd_route_test.go +++ b/test/openshift/e2e/ginkgo/sequential/1-111_validate_default_argocd_route_test.go @@ -30,7 +30,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() { openshiftArgoCD, err := argocdFixture.GetOpenShiftGitOpsNSArgoCD() Expect(err).ToNot(HaveOccurred()) - Expect(openshiftArgoCD.Spec.Server.Route.Enabled).To(Equal(true)) + Expect(openshiftArgoCD.Spec.Server.Route.Enabled).To(BeTrue()) Eventually(openshiftArgoCD, "5m", "5s").Should(argocdFixture.BeAvailable()) serverRoute := &routev1.Route{