From 9bd1513efe6fef586cf40762005c298805ba5c88 Mon Sep 17 00:00:00 2001 From: varshab1210 Date: Tue, 22 Nov 2022 12:33:29 +0530 Subject: [PATCH 1/7] Skip test based on condition Signed-off-by: varshab1210 --- scripts/openshiftci-presubmit-all-tests.sh | 3 + test/e2e/gitopsservice_test.go | 219 +++++++++++---------- 2 files changed, 116 insertions(+), 106 deletions(-) diff --git a/scripts/openshiftci-presubmit-all-tests.sh b/scripts/openshiftci-presubmit-all-tests.sh index bdbc29cd414..12df3446d4c 100755 --- a/scripts/openshiftci-presubmit-all-tests.sh +++ b/scripts/openshiftci-presubmit-all-tests.sh @@ -24,5 +24,8 @@ cp $KUBECONFIG $TMP_DIR/kubeconfig chmod 640 $TMP_DIR/kubeconfig export KUBECONFIG=$TMP_DIR/kubeconfig +export OCP_VERSION="$(oc version)" +echo $OCP_VERSION + # Run e2e test make test-e2e diff --git a/test/e2e/gitopsservice_test.go b/test/e2e/gitopsservice_test.go index 5509679d9e2..520f81796a8 100644 --- a/test/e2e/gitopsservice_test.go +++ b/test/e2e/gitopsservice_test.go @@ -23,6 +23,7 @@ import ( "io/ioutil" "net/http" "net/url" + "os" "os/exec" "path/filepath" "strings" @@ -381,112 +382,118 @@ var _ = Describe("GitOpsServiceController", func() { }) }) - // Context("Validate granting permissions by label", func() { - // sourceNS := "source-ns" - // argocdInstance := "argocd-label" - // targetNS := "target-ns" - - // It("Create source and target namespaces", func() { - // // create a new source namespace - // sourceNamespaceObj := &corev1.Namespace{ - // ObjectMeta: metav1.ObjectMeta{ - // Name: sourceNS, - // }, - // } - // err := k8sClient.Create(context.TODO(), sourceNamespaceObj) - // if !kubeerrors.IsAlreadyExists(err) { - // Expect(err).NotTo(HaveOccurred()) - // } - - // // create an ArgoCD instance in the source namespace - // argoCDInstanceObj, err := argocd.NewCR(argocdInstance, sourceNS) - // Expect(err).NotTo(HaveOccurred()) - // err = k8sClient.Create(context.TODO(), argoCDInstanceObj) - // if !kubeerrors.IsAlreadyExists(err) { - // Expect(err).NotTo(HaveOccurred()) - // } - - // // Wait for the default project to exist; this avoids a race condition where the Application - // // can be created before the Project that it targets. - // Eventually(func() error { - // _, err := helper.ProjectExists("default", sourceNS) - // if err != nil { - // return err - // } - // return nil - // }, time.Minute*10, interval).ShouldNot(HaveOccurred()) - - // // 'When GitOps operator is run locally (not installed via OLM), it does not correctly setup - // // the 'argoproj.io' Role rules for the 'argocd-application-controller' - // // Thus, applying missing rules for 'argocd-application-controller' - // // TODO: Remove once https://github.com/redhat-developer/gitops-operator/issues/148 is fixed - // if err := applyMissingPermissions(argocdInstance, sourceNS); err != nil { - // Expect(err).NotTo(HaveOccurred()) - // } - - // // create a target namespace to deploy resources - // // allow argocd to create resources in the target namespace by adding managed-by label - // targetNamespaceObj := &corev1.Namespace{ - // ObjectMeta: metav1.ObjectMeta{ - // Name: targetNS, - // Labels: map[string]string{ - // "argocd.argoproj.io/managed-by": sourceNS, - // }, - // }, - // } - // err = k8sClient.Create(context.TODO(), targetNamespaceObj) - // if !kubeerrors.IsAlreadyExists(err) { - // Expect(err).NotTo(HaveOccurred()) - // } - // }) - - // It("Required RBAC resources are created in the target namespace", func() { - // resourceList := []helper.ResourceList{ - // { - // Resource: &rbacv1.Role{}, - // ExpectedResources: []string{ - // argocdInstance + "-argocd-application-controller", - // argocdInstance + "-argocd-server", - // }, - // }, - // { - // Resource: &rbacv1.RoleBinding{}, - // ExpectedResources: []string{ - // argocdInstance + "-argocd-application-controller", - // argocdInstance + "-argocd-server", - // }, - // }, - // } - // err := helper.WaitForResourcesByName(k8sClient, resourceList, targetNS, time.Second*180) - // Expect(err).NotTo(HaveOccurred()) - // }) - - // It("Check if an application could be deployed in target namespace", func() { - // nginxAppCr := filepath.Join("..", "appcrs", "nginx_appcr.yaml") - // ocPath, err := exec.LookPath("oc") - // Expect(err).NotTo(HaveOccurred()) - // cmd := exec.Command(ocPath, "apply", "-f", nginxAppCr) - // err = cmd.Run() - // Expect(err).NotTo(HaveOccurred()) - - // Eventually(func() error { - // err := helper.ApplicationHealthStatus("nginx", sourceNS) - // if err != nil { - // return err - // } - // err = helper.ApplicationSyncStatus("nginx", sourceNS) - // if err != nil { - // return err - // } - // return nil - // }, time.Second*300, interval).ShouldNot(HaveOccurred()) - // }) - - // It("Clean up resources", func() { - // Expect(helper.DeleteNamespace(k8sClient, sourceNS)).NotTo(HaveOccurred()) - // Expect(helper.DeleteNamespace(k8sClient, targetNS)).NotTo(HaveOccurred()) - // }) - // }) + Context("Validate granting permissions by label", func() { + + version := os.Getenv("OCP_VERSION") + + if !strings.Contains(version, "Server Version: 4.9") { + + sourceNS := "source-ns" + argocdInstance := "argocd-label" + targetNS := "target-ns" + + It("Create source and target namespaces", func() { + // create a new source namespace + sourceNamespaceObj := &corev1.Namespace{ + ObjectMeta: metav1.ObjectMeta{ + Name: sourceNS, + }, + } + err := k8sClient.Create(context.TODO(), sourceNamespaceObj) + if !kubeerrors.IsAlreadyExists(err) { + Expect(err).NotTo(HaveOccurred()) + } + + // create an ArgoCD instance in the source namespace + argoCDInstanceObj, err := argocd.NewCR(argocdInstance, sourceNS) + Expect(err).NotTo(HaveOccurred()) + err = k8sClient.Create(context.TODO(), argoCDInstanceObj) + if !kubeerrors.IsAlreadyExists(err) { + Expect(err).NotTo(HaveOccurred()) + } + + // Wait for the default project to exist; this avoids a race condition where the Application + // can be created before the Project that it targets. + Eventually(func() error { + _, err := helper.ProjectExists("default", sourceNS) + if err != nil { + return err + } + return nil + }, time.Minute*10, interval).ShouldNot(HaveOccurred()) + + // 'When GitOps operator is run locally (not installed via OLM), it does not correctly setup + // the 'argoproj.io' Role rules for the 'argocd-application-controller' + // Thus, applying missing rules for 'argocd-application-controller' + // TODO: Remove once https://github.com/redhat-developer/gitops-operator/issues/148 is fixed + if err := applyMissingPermissions(argocdInstance, sourceNS); err != nil { + Expect(err).NotTo(HaveOccurred()) + } + + // create a target namespace to deploy resources + // allow argocd to create resources in the target namespace by adding managed-by label + targetNamespaceObj := &corev1.Namespace{ + ObjectMeta: metav1.ObjectMeta{ + Name: targetNS, + Labels: map[string]string{ + "argocd.argoproj.io/managed-by": sourceNS, + }, + }, + } + err = k8sClient.Create(context.TODO(), targetNamespaceObj) + if !kubeerrors.IsAlreadyExists(err) { + Expect(err).NotTo(HaveOccurred()) + } + }) + + It("Required RBAC resources are created in the target namespace", func() { + resourceList := []helper.ResourceList{ + { + Resource: &rbacv1.Role{}, + ExpectedResources: []string{ + argocdInstance + "-argocd-application-controller", + argocdInstance + "-argocd-server", + }, + }, + { + Resource: &rbacv1.RoleBinding{}, + ExpectedResources: []string{ + argocdInstance + "-argocd-application-controller", + argocdInstance + "-argocd-server", + }, + }, + } + err := helper.WaitForResourcesByName(k8sClient, resourceList, targetNS, time.Second*180) + Expect(err).NotTo(HaveOccurred()) + }) + + It("Check if an application could be deployed in target namespace", func() { + nginxAppCr := filepath.Join("..", "appcrs", "nginx_appcr.yaml") + ocPath, err := exec.LookPath("oc") + Expect(err).NotTo(HaveOccurred()) + cmd := exec.Command(ocPath, "apply", "-f", nginxAppCr) + err = cmd.Run() + Expect(err).NotTo(HaveOccurred()) + + Eventually(func() error { + err := helper.ApplicationHealthStatus("nginx", sourceNS) + if err != nil { + return err + } + err = helper.ApplicationSyncStatus("nginx", sourceNS) + if err != nil { + return err + } + return nil + }, time.Second*300, interval).ShouldNot(HaveOccurred()) + }) + + It("Clean up resources", func() { + Expect(helper.DeleteNamespace(k8sClient, sourceNS)).NotTo(HaveOccurred()) + Expect(helper.DeleteNamespace(k8sClient, targetNS)).NotTo(HaveOccurred()) + }) + } + }) Context("Validate permission label feature for OOTB Argo CD instance", func() { argocdTargetNamespace := "argocd-target" From b169c520f7ee19a8674e611aed364d4a205a7714 Mon Sep 17 00:00:00 2001 From: ishitasequeira Date: Mon, 21 Nov 2022 16:57:32 -0500 Subject: [PATCH 2/7] chore: pick up latest argocd-operator commit Signed-off-by: ishitasequeira Signed-off-by: varshab1210 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 3a1712c309c..195c261aed3 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/redhat-developer/gitops-operator go 1.18 require ( - github.com/argoproj-labs/argocd-operator v0.0.16-0.20221121122742-4e6dc06c8389 + github.com/argoproj-labs/argocd-operator v0.0.16-0.20221121214014-e0b755525224 github.com/coreos/prometheus-operator v0.40.0 github.com/go-logr/logr v1.2.3 github.com/google/go-cmp v0.5.8 diff --git a/go.sum b/go.sum index 94ca9686268..bf78679dcef 100644 --- a/go.sum +++ b/go.sum @@ -147,8 +147,8 @@ github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210826220005-b48c857c3a0e/go.m github.com/apache/arrow/go/arrow v0.0.0-20191024131854-af6fa24be0db/go.mod h1:VTxUBvSJ3s3eHAg65PNgrsn5BtqCRPdmyXh6rAfdxN0= github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= -github.com/argoproj-labs/argocd-operator v0.0.16-0.20221121122742-4e6dc06c8389 h1:psSV/+d+fvu8nX//AmbRD5hIb1kBYjOEgPPOanPDthk= -github.com/argoproj-labs/argocd-operator v0.0.16-0.20221121122742-4e6dc06c8389/go.mod h1:4uHOPh2+gCJD3NGPViJOj87tIIOnmHZ97I0njkL5qRU= +github.com/argoproj-labs/argocd-operator v0.0.16-0.20221121214014-e0b755525224 h1:3AJoSM3gZp54x5tLsQQ5C+xhxWhsWX/X15M4EvJ9b38= +github.com/argoproj-labs/argocd-operator v0.0.16-0.20221121214014-e0b755525224/go.mod h1:4uHOPh2+gCJD3NGPViJOj87tIIOnmHZ97I0njkL5qRU= github.com/argoproj/argo-cd/v2 v2.5.2 h1:hyPi8NFXW3tG2yURslIMI20GfCdTN1/BDnt4+v5lpoA= github.com/argoproj/argo-cd/v2 v2.5.2/go.mod h1:3ToENm286PFVlZKNMutBzOwNyhevz4fw9dcgyiq3FIY= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= From 54ca3058b49150716f619ada191a45253e9da510 Mon Sep 17 00:00:00 2001 From: Yi Cai Date: Wed, 23 Nov 2022 03:03:28 -0500 Subject: [PATCH 3/7] Add reconcile plugin condition (#402) Signed-off-by: Yi Cai Signed-off-by: Yi Cai Signed-off-by: varshab1210 --- common/common.go | 2 + controllers/gitopsservice_controller.go | 56 ++++++++++++++++---- controllers/gitopsservice_controller_test.go | 34 +++++++++++- go.mod | 1 + go.sum | 2 + 5 files changed, 84 insertions(+), 11 deletions(-) diff --git a/common/common.go b/common/common.go index 0ea13a79c59..459ca8fcb44 100644 --- a/common/common.go +++ b/common/common.go @@ -29,6 +29,8 @@ const ( DefaultConsoleImage = "quay.io/redhat-developer/gitops-console-plugin" // Default console plugin version DefaultConsoleVersion = "v0.1.0" + // Default console plugin installation OCP version + DefaultDynamicPluginStartOCPVersion = "4.15.0" ) // InfraNodeSelector returns openshift label for infrastructure nodes diff --git a/controllers/gitopsservice_controller.go b/controllers/gitopsservice_controller.go index afefb995bfb..7a475bf01fb 100644 --- a/controllers/gitopsservice_controller.go +++ b/controllers/gitopsservice_controller.go @@ -19,6 +19,7 @@ package controllers import ( "context" "fmt" + "log" "os" "reflect" "strings" @@ -28,6 +29,7 @@ import ( argocdcontroller "github.com/argoproj-labs/argocd-operator/controllers/argocd" argocdutil "github.com/argoproj-labs/argocd-operator/controllers/argoutil" "github.com/go-logr/logr" + version "github.com/hashicorp/go-version" routev1 "github.com/openshift/api/route/v1" pipelinesv1alpha1 "github.com/redhat-developer/gitops-operator/api/v1alpha1" "github.com/redhat-developer/gitops-operator/common" @@ -57,15 +59,16 @@ 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" - insecureEnvVar = "INSECURE" - insecureEnvVarValue = "true" - serviceNamespace = "openshift-gitops" - deprecatedServiceNamespace = "openshift-pipelines-app-delivery" + port int32 = 8080 + portTLS int32 = 8443 + backendImage string = "quay.io/redhat-developer/gitops-backend:v0.0.1" + backendImageEnvName = "BACKEND_IMAGE" + serviceName = "cluster" + insecureEnvVar = "INSECURE" + insecureEnvVarValue = "true" + serviceNamespace = "openshift-gitops" + deprecatedServiceNamespace = "openshift-pipelines-app-delivery" + dynamicPluginStartOCPVersionEnv = "DYNAMIC_PLUGIN_START_OCP_VERSION" ) const ( @@ -224,7 +227,40 @@ func (r *ReconcileGitopsService) Reconcile(ctx context.Context, request reconcil return result, err } - return r.reconcilePlugin(instance, request) + dynamicPluginStartOCPVersion := os.Getenv(dynamicPluginStartOCPVersionEnv) + if dynamicPluginStartOCPVersion == "" { + dynamicPluginStartOCPVersion = common.DefaultDynamicPluginStartOCPVersion + } + + OCPVersion, err := util.GetClusterVersion(r.Client) + if err != nil { + log.Printf("Unable to get cluster version: %v", err) + return reconcile.Result{}, nil + } + + v1, err := version.NewVersion(OCPVersion) + if err != nil { + log.Printf("Unable to retrieve current OCP version: %v", err) + return reconcile.Result{}, nil + } + realVersion := v1.Segments() + realMajorVersion := realVersion[0] + realMinorVersion := realVersion[1] + + v2, err := version.NewVersion(dynamicPluginStartOCPVersion) + if err != nil { + return reconcile.Result{}, nil + } + startVersion := v2.Segments() + startMajorVersion := startVersion[0] + startMinorVersion := startVersion[1] + + if realMajorVersion < startMajorVersion || (realMajorVersion == startMajorVersion && realMinorVersion < startMinorVersion) { + // Skip plugin reconciliation if real OCP version is less than dynamic plugin start OCP version + return reconcile.Result{}, nil + } else { + return r.reconcilePlugin(instance, request) + } } func (r *ReconcileGitopsService) ensureDefaultArgoCDInstanceDoesntExist(instance *pipelinesv1alpha1.GitopsService, reqLogger logr.Logger) error { diff --git a/controllers/gitopsservice_controller_test.go b/controllers/gitopsservice_controller_test.go index 35ec5d48972..e6d3e3994a4 100644 --- a/controllers/gitopsservice_controller_test.go +++ b/controllers/gitopsservice_controller_test.go @@ -188,7 +188,7 @@ func TestReconcile(t *testing.T) { s := scheme.Scheme addKnownTypesToScheme(s) - fakeClient := fake.NewFakeClient(newGitopsService()) + fakeClient := fake.NewFakeClient(util.NewClusterVersion("4.15.1"), newGitopsService()) reconciler := newReconcileGitOpsService(fakeClient, s) _, err := reconciler.Reconcile(context.TODO(), newRequest("test", "test")) @@ -327,6 +327,38 @@ func TestReconcile_consoleAPINotFound(t *testing.T) { assert.Error(t, err, "configmaps \"httpd-cfg\" not found") } +func TestReconcile_ocpVersionLowerThan4_15(t *testing.T) { + defer util.SetConsoleAPIFound(util.IsConsoleAPIFound()) + util.SetConsoleAPIFound(false) + + logf.SetLogger(argocd.ZapLogger(true)) + s := scheme.Scheme + addKnownTypesToScheme(s) + + fakeClient := fake.NewFakeClient(util.NewClusterVersion("4.11.1"), newGitopsService()) + reconciler := newReconcileGitOpsService(fakeClient, s) + + _, err := reconciler.Reconcile(context.TODO(), newRequest("test", "test")) + assertNoError(t, err) + + // Check consolePlugin and other resources are not created + consolePlugin := &consolepluginv1.ConsolePlugin{} + err = fakeClient.Get(context.TODO(), types.NamespacedName{Name: gitopsPluginName}, consolePlugin) + assert.Error(t, err, "consoleplugins.console.openshift.io \"gitops-plugin\" not found") + + pluginDeploy := &appsv1.Deployment{} + err = fakeClient.Get(context.TODO(), types.NamespacedName{Name: gitopsPluginName, Namespace: serviceNamespace}, pluginDeploy) + assert.Error(t, err, "deployments.apps \"gitops-plugin\" not found") + + pluginService := &corev1.Service{} + err = fakeClient.Get(context.TODO(), types.NamespacedName{Name: gitopsPluginName, Namespace: serviceNamespace}, pluginService) + assert.Error(t, err, "services \"gitops-plugin\" not found") + + pluginConfigMap := &corev1.ConfigMap{} + err = fakeClient.Get(context.TODO(), types.NamespacedName{Name: httpdConfigMapName, Namespace: serviceNamespace}, pluginConfigMap) + assert.Error(t, err, "configmaps \"httpd-cfg\" not found") +} + func TestReconcile_GitOpsNamespace(t *testing.T) { logf.SetLogger(argocd.ZapLogger(true)) s := scheme.Scheme diff --git a/go.mod b/go.mod index 195c261aed3..8f861db2a50 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/coreos/prometheus-operator v0.40.0 github.com/go-logr/logr v1.2.3 github.com/google/go-cmp v0.5.8 + github.com/hashicorp/go-version v1.2.1 github.com/onsi/ginkgo v1.16.5 github.com/onsi/gomega v1.17.0 github.com/openshift/api v3.9.1-0.20190916204813-cdbe64fb0c91+incompatible diff --git a/go.sum b/go.sum index bf78679dcef..1f9805054b5 100644 --- a/go.sum +++ b/go.sum @@ -687,6 +687,8 @@ github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI= +github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= From 62600c5e17b2d96c37e3bfc9d1493d1269dba7cb Mon Sep 17 00:00:00 2001 From: varshab1210 Date: Wed, 7 Dec 2022 21:49:55 +0530 Subject: [PATCH 4/7] increase timeout and skip condition Signed-off-by: varshab1210 --- test/e2e/gitopsservice_test.go | 185 ++++++++++++++++----------------- 1 file changed, 92 insertions(+), 93 deletions(-) diff --git a/test/e2e/gitopsservice_test.go b/test/e2e/gitopsservice_test.go index 520f81796a8..8656c816aa7 100644 --- a/test/e2e/gitopsservice_test.go +++ b/test/e2e/gitopsservice_test.go @@ -386,113 +386,112 @@ var _ = Describe("GitOpsServiceController", func() { version := os.Getenv("OCP_VERSION") - if !strings.Contains(version, "Server Version: 4.9") { + //if !strings.Contains(version, "Server Version: 4.9") { - sourceNS := "source-ns" - argocdInstance := "argocd-label" - targetNS := "target-ns" + sourceNS := "source-ns" + argocdInstance := "argocd-label" + targetNS := "target-ns" - It("Create source and target namespaces", func() { - // create a new source namespace - sourceNamespaceObj := &corev1.Namespace{ - ObjectMeta: metav1.ObjectMeta{ - Name: sourceNS, - }, - } - err := k8sClient.Create(context.TODO(), sourceNamespaceObj) - if !kubeerrors.IsAlreadyExists(err) { - Expect(err).NotTo(HaveOccurred()) - } + It("Create source and target namespaces", func() { + // create a new source namespace + sourceNamespaceObj := &corev1.Namespace{ + ObjectMeta: metav1.ObjectMeta{ + Name: sourceNS, + }, + } + err := k8sClient.Create(context.TODO(), sourceNamespaceObj) + if !kubeerrors.IsAlreadyExists(err) { + Expect(err).NotTo(HaveOccurred()) + } - // create an ArgoCD instance in the source namespace - argoCDInstanceObj, err := argocd.NewCR(argocdInstance, sourceNS) + // create an ArgoCD instance in the source namespace + argoCDInstanceObj, err := argocd.NewCR(argocdInstance, sourceNS) + Expect(err).NotTo(HaveOccurred()) + err = k8sClient.Create(context.TODO(), argoCDInstanceObj) + if !kubeerrors.IsAlreadyExists(err) { Expect(err).NotTo(HaveOccurred()) - err = k8sClient.Create(context.TODO(), argoCDInstanceObj) - if !kubeerrors.IsAlreadyExists(err) { - Expect(err).NotTo(HaveOccurred()) - } + } - // Wait for the default project to exist; this avoids a race condition where the Application - // can be created before the Project that it targets. - Eventually(func() error { - _, err := helper.ProjectExists("default", sourceNS) - if err != nil { - return err - } - return nil - }, time.Minute*10, interval).ShouldNot(HaveOccurred()) - - // 'When GitOps operator is run locally (not installed via OLM), it does not correctly setup - // the 'argoproj.io' Role rules for the 'argocd-application-controller' - // Thus, applying missing rules for 'argocd-application-controller' - // TODO: Remove once https://github.com/redhat-developer/gitops-operator/issues/148 is fixed - if err := applyMissingPermissions(argocdInstance, sourceNS); err != nil { - Expect(err).NotTo(HaveOccurred()) + // Wait for the default project to exist; this avoids a race condition where the Application + // can be created before the Project that it targets. + Eventually(func() error { + _, err := helper.ProjectExists("default", sourceNS) + if err != nil { + return err } + return nil + }, time.Minute*30, interval).ShouldNot(HaveOccurred()) - // create a target namespace to deploy resources - // allow argocd to create resources in the target namespace by adding managed-by label - targetNamespaceObj := &corev1.Namespace{ - ObjectMeta: metav1.ObjectMeta{ - Name: targetNS, - Labels: map[string]string{ - "argocd.argoproj.io/managed-by": sourceNS, - }, + // 'When GitOps operator is run locally (not installed via OLM), it does not correctly setup + // the 'argoproj.io' Role rules for the 'argocd-application-controller' + // Thus, applying missing rules for 'argocd-application-controller' + // TODO: Remove once https://github.com/redhat-developer/gitops-operator/issues/148 is fixed + if err := applyMissingPermissions(argocdInstance, sourceNS); err != nil { + Expect(err).NotTo(HaveOccurred()) + } + + // create a target namespace to deploy resources + // allow argocd to create resources in the target namespace by adding managed-by label + targetNamespaceObj := &corev1.Namespace{ + ObjectMeta: metav1.ObjectMeta{ + Name: targetNS, + Labels: map[string]string{ + "argocd.argoproj.io/managed-by": sourceNS, }, - } - err = k8sClient.Create(context.TODO(), targetNamespaceObj) - if !kubeerrors.IsAlreadyExists(err) { - Expect(err).NotTo(HaveOccurred()) - } - }) + }, + } + err = k8sClient.Create(context.TODO(), targetNamespaceObj) + if !kubeerrors.IsAlreadyExists(err) { + Expect(err).NotTo(HaveOccurred()) + } + }) - It("Required RBAC resources are created in the target namespace", func() { - resourceList := []helper.ResourceList{ - { - Resource: &rbacv1.Role{}, - ExpectedResources: []string{ - argocdInstance + "-argocd-application-controller", - argocdInstance + "-argocd-server", - }, + It("Required RBAC resources are created in the target namespace", func() { + resourceList := []helper.ResourceList{ + { + Resource: &rbacv1.Role{}, + ExpectedResources: []string{ + argocdInstance + "-argocd-application-controller", + argocdInstance + "-argocd-server", }, - { - Resource: &rbacv1.RoleBinding{}, - ExpectedResources: []string{ - argocdInstance + "-argocd-application-controller", - argocdInstance + "-argocd-server", - }, + }, + { + Resource: &rbacv1.RoleBinding{}, + ExpectedResources: []string{ + argocdInstance + "-argocd-application-controller", + argocdInstance + "-argocd-server", }, - } - err := helper.WaitForResourcesByName(k8sClient, resourceList, targetNS, time.Second*180) - Expect(err).NotTo(HaveOccurred()) - }) + }, + } + err := helper.WaitForResourcesByName(k8sClient, resourceList, targetNS, time.Second*1200) + Expect(err).NotTo(HaveOccurred()) + }) - It("Check if an application could be deployed in target namespace", func() { - nginxAppCr := filepath.Join("..", "appcrs", "nginx_appcr.yaml") - ocPath, err := exec.LookPath("oc") - Expect(err).NotTo(HaveOccurred()) - cmd := exec.Command(ocPath, "apply", "-f", nginxAppCr) - err = cmd.Run() - Expect(err).NotTo(HaveOccurred()) + It("Check if an application could be deployed in target namespace", func() { + nginxAppCr := filepath.Join("..", "appcrs", "nginx_appcr.yaml") + ocPath, err := exec.LookPath("oc") + Expect(err).NotTo(HaveOccurred()) + cmd := exec.Command(ocPath, "apply", "-f", nginxAppCr) + err = cmd.Run() + Expect(err).NotTo(HaveOccurred()) - Eventually(func() error { - err := helper.ApplicationHealthStatus("nginx", sourceNS) - if err != nil { - return err - } - err = helper.ApplicationSyncStatus("nginx", sourceNS) - if err != nil { - return err - } - return nil - }, time.Second*300, interval).ShouldNot(HaveOccurred()) - }) + Eventually(func() error { + err := helper.ApplicationHealthStatus("nginx", sourceNS) + if err != nil { + return err + } + err = helper.ApplicationSyncStatus("nginx", sourceNS) + if err != nil { + return err + } + return nil + }, time.Second*2000, interval).ShouldNot(HaveOccurred()) + }) - It("Clean up resources", func() { - Expect(helper.DeleteNamespace(k8sClient, sourceNS)).NotTo(HaveOccurred()) - Expect(helper.DeleteNamespace(k8sClient, targetNS)).NotTo(HaveOccurred()) - }) - } + It("Clean up resources", func() { + Expect(helper.DeleteNamespace(k8sClient, sourceNS)).NotTo(HaveOccurred()) + Expect(helper.DeleteNamespace(k8sClient, targetNS)).NotTo(HaveOccurred()) + }) }) Context("Validate permission label feature for OOTB Argo CD instance", func() { From d835c0ee2745dbed82440c873816eac1b5e8fbfb Mon Sep 17 00:00:00 2001 From: varshab1210 Date: Wed, 7 Dec 2022 23:14:16 +0530 Subject: [PATCH 5/7] Removing additional variable Signed-off-by: varshab1210 --- test/e2e/gitopsservice_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/e2e/gitopsservice_test.go b/test/e2e/gitopsservice_test.go index 8656c816aa7..d38562230f4 100644 --- a/test/e2e/gitopsservice_test.go +++ b/test/e2e/gitopsservice_test.go @@ -23,7 +23,6 @@ import ( "io/ioutil" "net/http" "net/url" - "os" "os/exec" "path/filepath" "strings" @@ -384,7 +383,7 @@ var _ = Describe("GitOpsServiceController", func() { Context("Validate granting permissions by label", func() { - version := os.Getenv("OCP_VERSION") + //version := os.Getenv("OCP_VERSION") //if !strings.Contains(version, "Server Version: 4.9") { From bdbc41f6d94e17a5aea0b579e1675bbc9a84b54b Mon Sep 17 00:00:00 2001 From: varshab1210 Date: Thu, 8 Dec 2022 11:58:21 +0530 Subject: [PATCH 6/7] lowering timeout Signed-off-by: varshab1210 --- test/e2e/gitopsservice_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/gitopsservice_test.go b/test/e2e/gitopsservice_test.go index d38562230f4..77ca6eca225 100644 --- a/test/e2e/gitopsservice_test.go +++ b/test/e2e/gitopsservice_test.go @@ -484,7 +484,7 @@ var _ = Describe("GitOpsServiceController", func() { return err } return nil - }, time.Second*2000, interval).ShouldNot(HaveOccurred()) + }, time.Second*600, interval).ShouldNot(HaveOccurred()) }) It("Clean up resources", func() { From b938f3bc166a91f5bd5c40ded1669e340f9859f0 Mon Sep 17 00:00:00 2001 From: varshab1210 Date: Thu, 8 Dec 2022 19:07:44 +0530 Subject: [PATCH 7/7] Enable test Signed-off-by: varshab1210 --- scripts/openshiftci-presubmit-all-tests.sh | 3 --- test/e2e/gitopsservice_test.go | 9 ++------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/scripts/openshiftci-presubmit-all-tests.sh b/scripts/openshiftci-presubmit-all-tests.sh index 12df3446d4c..bdbc29cd414 100755 --- a/scripts/openshiftci-presubmit-all-tests.sh +++ b/scripts/openshiftci-presubmit-all-tests.sh @@ -24,8 +24,5 @@ cp $KUBECONFIG $TMP_DIR/kubeconfig chmod 640 $TMP_DIR/kubeconfig export KUBECONFIG=$TMP_DIR/kubeconfig -export OCP_VERSION="$(oc version)" -echo $OCP_VERSION - # Run e2e test make test-e2e diff --git a/test/e2e/gitopsservice_test.go b/test/e2e/gitopsservice_test.go index 77ca6eca225..e8ceb7cf599 100644 --- a/test/e2e/gitopsservice_test.go +++ b/test/e2e/gitopsservice_test.go @@ -382,11 +382,6 @@ var _ = Describe("GitOpsServiceController", func() { }) Context("Validate granting permissions by label", func() { - - //version := os.Getenv("OCP_VERSION") - - //if !strings.Contains(version, "Server Version: 4.9") { - sourceNS := "source-ns" argocdInstance := "argocd-label" targetNS := "target-ns" @@ -419,7 +414,7 @@ var _ = Describe("GitOpsServiceController", func() { return err } return nil - }, time.Minute*30, interval).ShouldNot(HaveOccurred()) + }, time.Minute*10, interval).ShouldNot(HaveOccurred()) // 'When GitOps operator is run locally (not installed via OLM), it does not correctly setup // the 'argoproj.io' Role rules for the 'argocd-application-controller' @@ -462,7 +457,7 @@ var _ = Describe("GitOpsServiceController", func() { }, }, } - err := helper.WaitForResourcesByName(k8sClient, resourceList, targetNS, time.Second*1200) + err := helper.WaitForResourcesByName(k8sClient, resourceList, targetNS, time.Second*180) Expect(err).NotTo(HaveOccurred()) })