From bdcd83a46f25a3056e17710015f15d0802895d2e Mon Sep 17 00:00:00 2001 From: akhil nittala Date: Tue, 9 Sep 2025 12:38:41 +0530 Subject: [PATCH 1/5] [GITOPS-7475]: Default argocd instance does not get recreated after deletion Signed-off-by: akhil nittala Signed-off-by: akhil nittala --- Makefile | 24 ++++++++++++++++-------- controllers/gitopsservice_controller.go | 6 +++++- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 70fd28f68..bd0f41c6e 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,14 @@ # - use environment variables to overwrite this value (e.g export VERSION=0.0.2) VERSION ?= "" + +# Try to detect Docker or Podman +CONTAINER_RUNTIME := $(shell command -v docker 2> /dev/null || command -v podman 2> /dev/null) + +# If neither Docker nor Podman is found, print an error message and exit +ifeq ($(CONTAINER_RUNTIME),) +$(warning "No container runtime (Docker or Podman) found in PATH. Please install one of them.") +endif # CHANNELS define the bundle channels used in the bundle. # Add a new line here if you would like to change its default config. (E.g CHANNELS = "preview,fast,stable") # To re-generate a bundle for other specific channels without changing the standard setup, you can: @@ -206,12 +214,12 @@ run: manifests generate fmt vet ## Run a controller from your host. CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES=argo-rollouts,test-rom-ns-1,rom-ns-1,openshift-gitops ARGOCD_CLUSTER_CONFIG_NAMESPACES=openshift-gitops REDIS_CONFIG_PATH="build/redis" go run ./cmd/main.go .PHONY: docker-build -docker-build: test ## Build docker image with the manager. - docker build -t ${IMG} . +docker-build: test ## Build $(CONTAINER_RUNTIME) image with the manager. + $(CONTAINER_RUNTIME) build -t ${IMG} . .PHONY: docker-push -docker-push: ## Push docker image with the manager. - docker push ${IMG} +docker-push: ## Push $(CONTAINER_RUNTIME) image with the manager. + $(CONTAINER_RUNTIME) push ${IMG} ##@ Build Dependencies @@ -305,11 +313,11 @@ bundle: operator-sdk manifests kustomize ## Generate bundle manifests and metada .PHONY: bundle-build bundle-build: ## Build the bundle image. - docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . + $(CONTAINER_RUNTIME) build -f bundle.Dockerfile -t $(BUNDLE_IMG) . .PHONY: bundle-push bundle-push: ## Push the bundle image. - $(MAKE) docker-push IMG=$(BUNDLE_IMG) + $(MAKE) $(CONTAINER_RUNTIME)-push IMG=$(BUNDLE_IMG) .PHONY: opm OPM = ./bin/opm @@ -346,12 +354,12 @@ endif # https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator .PHONY: catalog-build catalog-build: opm ## Build a catalog image. - $(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT) + $(OPM) index add --container-tool $(CONTAINER_RUNTIME) --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT) # Push the catalog image. .PHONY: catalog-push catalog-push: ## Push a catalog image. - $(MAKE) docker-push IMG=$(CATALOG_IMG) + $(MAKE) $(CONTAINER_RUNTIME)-push IMG=$(CATALOG_IMG) .PHONY: gosec diff --git a/controllers/gitopsservice_controller.go b/controllers/gitopsservice_controller.go index df62b5ba7..4961a1695 100644 --- a/controllers/gitopsservice_controller.go +++ b/controllers/gitopsservice_controller.go @@ -112,7 +112,11 @@ func (r *ReconcileGitopsService) SetupWithManager(mgr ctrl.Manager) error { builder.WithPredicates(predicate.NewPredicateFuncs(func(obj client.Object) bool { return obj.GetName() == "openshift-gitops" })), - ). + ).Watches(&argoapp.ArgoCD{}, + &handler.EnqueueRequestForObject{}, + builder.WithPredicates(predicate.NewPredicateFuncs(func(obj client.Object) bool { + return obj.GetName() == "openshift-gitops" && obj.GetNamespace() == "openshift-gitops" + }))). Complete(r) } From 3b7d2325c7f3578ca1ffa9f93123cc1483800b65 Mon Sep 17 00:00:00 2001 From: akhil nittala Date: Wed, 10 Sep 2025 11:48:13 +0530 Subject: [PATCH 2/5] [GITOPS-7475]: Default argocd instance does not get recreated after deletion Signed-off-by: akhil nittala --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index bd0f41c6e..b939b847b 100644 --- a/Makefile +++ b/Makefile @@ -214,11 +214,11 @@ run: manifests generate fmt vet ## Run a controller from your host. CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES=argo-rollouts,test-rom-ns-1,rom-ns-1,openshift-gitops ARGOCD_CLUSTER_CONFIG_NAMESPACES=openshift-gitops REDIS_CONFIG_PATH="build/redis" go run ./cmd/main.go .PHONY: docker-build -docker-build: test ## Build $(CONTAINER_RUNTIME) image with the manager. +docker-build: test ## Build container image with the manager. $(CONTAINER_RUNTIME) build -t ${IMG} . .PHONY: docker-push -docker-push: ## Push $(CONTAINER_RUNTIME) image with the manager. +docker-push: ## Push container image with the manager. $(CONTAINER_RUNTIME) push ${IMG} ##@ Build Dependencies @@ -359,7 +359,7 @@ catalog-build: opm ## Build a catalog image. # Push the catalog image. .PHONY: catalog-push catalog-push: ## Push a catalog image. - $(MAKE) $(CONTAINER_RUNTIME)-push IMG=$(CATALOG_IMG) + $(MAKE) docker-push IMG=$(CATALOG_IMG) .PHONY: gosec From 978eae5f67817f9081ab231c9bb149e76b2fa07b Mon Sep 17 00:00:00 2001 From: akhil nittala Date: Wed, 10 Sep 2025 11:52:54 +0530 Subject: [PATCH 3/5] [GITOPS-7475]: Default argocd instance does not get recreated after deletion Signed-off-by: akhil nittala --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b939b847b..8c55d840a 100644 --- a/Makefile +++ b/Makefile @@ -317,7 +317,7 @@ bundle-build: ## Build the bundle image. .PHONY: bundle-push bundle-push: ## Push the bundle image. - $(MAKE) $(CONTAINER_RUNTIME)-push IMG=$(BUNDLE_IMG) + $(MAKE) docker-push IMG=$(BUNDLE_IMG) .PHONY: opm OPM = ./bin/opm From cc2b4e7f76e9647c6db3a8f1f7a88ea2403acaa1 Mon Sep 17 00:00:00 2001 From: akhil nittala Date: Thu, 11 Sep 2025 13:42:25 +0530 Subject: [PATCH 4/5] [GITOPS-7475]: Default argocd instance does not get recreated after deletion Signed-off-by: akhil nittala --- ..._validate_disable_default_instance_test.go | 65 ++++++++++++++++++- 1 file changed, 63 insertions(+), 2 deletions(-) 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 069c7261e..1fe168630 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 @@ -17,6 +17,8 @@ limitations under the License. package sequential import ( + "context" + "github.com/argoproj-labs/argocd-operator/api/v1beta1" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -25,6 +27,7 @@ import ( "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/deployment" k8sFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/k8s" statefulsetFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/statefulset" + "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils" appsv1 "k8s.io/api/apps/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -37,13 +40,71 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() { fixture.EnsureSequentialCleanSlate() }) - It("verifies that DISABLE_DEFAULT_ARGOCD_INSTANCE env var will delete the argo cd instance from openshift-gitops, and that default Argo CD instance will be restored when the env var is removed", func() { + It("verifies that ArgoCD instance can be manually deleted and resources are cleaned up", func() { + + openshiftGitopsArgoCD, err := argocdFixture.GetOpenShiftGitOpsNSArgoCD() + Expect(err).ToNot(HaveOccurred()) + + By("verifying that the openshift-gitops ArgoCD instance exists initially") + Eventually(openshiftGitopsArgoCD).Should(k8sFixture.ExistByName()) + Eventually(openshiftGitopsArgoCD).Should(argocdFixture.BeAvailable()) + + By("verifying associated deployments exist") + deploymentsToVerify := []string{ + "openshift-gitops-server", + "openshift-gitops-redis", + "openshift-gitops-repo-server", + "openshift-gitops-applicationset-controller", + } + + for _, deplName := range deploymentsToVerify { + depl := &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{Name: deplName, Namespace: "openshift-gitops"}, + } + Eventually(depl).Should(k8sFixture.ExistByName()) + } + + ss := &appsv1.StatefulSet{ + ObjectMeta: metav1.ObjectMeta{ + Name: "openshift-gitops-application-controller", + Namespace: "openshift-gitops", + }, + } + Eventually(ss).Should(k8sFixture.ExistByName()) + + By("manually deleting the openshift-gitops ArgoCD instance") + k8sClient, _ := utils.GetE2ETestKubeClient() + err = k8sClient.Delete(context.Background(), openshiftGitopsArgoCD) + Expect(err).ToNot(HaveOccurred()) + By("verifying ArgoCD CR gets recreated automatically by the operator") + openshiftGitopsArgoCD = &v1beta1.ArgoCD{ + ObjectMeta: metav1.ObjectMeta{ + Name: "openshift-gitops", + Namespace: "openshift-gitops", + }, + } + Eventually(openshiftGitopsArgoCD, "3m", "5s").Should(k8sFixture.ExistByName()) + Eventually(openshiftGitopsArgoCD, "5m", "5s").Should(argocdFixture.BeAvailable()) + + By("verifying deployments and statefulset are recreated and become ready") + for _, deplName := range deploymentsToVerify { + depl := &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{Name: deplName, Namespace: "openshift-gitops"}, + } + Eventually(depl, "3m", "5s").Should(k8sFixture.ExistByName()) + Eventually(depl, "5m", "5s").Should(deployment.HaveReadyReplicas(1)) + } + + Eventually(ss, "3m", "5s").Should(k8sFixture.ExistByName()) + Eventually(ss, "5m", "5s").Should(statefulsetFixture.HaveReadyReplicas(1)) + }) + + It("verifies that DISABLE_DEFAULT_ARGOCD_INSTANCE env var will delete the argo cd instance from openshift-gitops, and that default Argo CD instance will be restored when the env var is removed", func() { if fixture.EnvLocalRun() { Skip("when running locally, there is no subscription or operator deployment to modify, so this test is skipped.") return } - openshiftGitopsArgoCD, err := argocdFixture.GetOpenShiftGitOpsNSArgoCD() Expect(err).ToNot(HaveOccurred()) From a9c4b391564011c6160defc315ce81b2f2a62388 Mon Sep 17 00:00:00 2001 From: akhil nittala Date: Fri, 12 Sep 2025 09:03:07 +0530 Subject: [PATCH 5/5] [GITOPS-7475]: Default argocd instance does not get recreated after deletion Signed-off-by: akhil nittala --- .../sequential/1-018_validate_disable_default_instance_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1fe168630..ed5efb275 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 @@ -40,7 +40,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() { fixture.EnsureSequentialCleanSlate() }) - It("verifies that ArgoCD instance can be manually deleted and resources are cleaned up", func() { + It("verifies that the default ArgoCD instance from openshift-gitops namespace is recreated when deleted manually", func() { openshiftGitopsArgoCD, err := argocdFixture.GetOpenShiftGitOpsNSArgoCD() Expect(err).ToNot(HaveOccurred())