Skip to content

Commit cfdfdb2

Browse files
[GITOPS-7475]: Default argocd instance does not get recreated after deletion (#960)
* [GITOPS-7475]: Default argocd instance does not get recreated after deletion Signed-off-by: akhil nittala <[email protected]> Signed-off-by: akhil nittala <[email protected]> * [GITOPS-7475]: Default argocd instance does not get recreated after deletion Signed-off-by: akhil nittala <[email protected]> * [GITOPS-7475]: Default argocd instance does not get recreated after deletion Signed-off-by: akhil nittala <[email protected]> * [GITOPS-7475]: Default argocd instance does not get recreated after deletion Signed-off-by: akhil nittala <[email protected]> * [GITOPS-7475]: Default argocd instance does not get recreated after deletion Signed-off-by: akhil nittala <[email protected]> --------- Signed-off-by: akhil nittala <[email protected]> Co-authored-by: Siddhesh Ghadi <[email protected]>
1 parent 60472d6 commit cfdfdb2

File tree

3 files changed

+82
-9
lines changed

3 files changed

+82
-9
lines changed

Makefile

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
66
VERSION ?= ""
77

8+
9+
# Try to detect Docker or Podman
10+
CONTAINER_RUNTIME := $(shell command -v docker 2> /dev/null || command -v podman 2> /dev/null)
11+
12+
# If neither Docker nor Podman is found, print an error message and exit
13+
ifeq ($(CONTAINER_RUNTIME),)
14+
$(warning "No container runtime (Docker or Podman) found in PATH. Please install one of them.")
15+
endif
816
# CHANNELS define the bundle channels used in the bundle.
917
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "preview,fast,stable")
1018
# 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.
206214
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
207215

208216
.PHONY: docker-build
209-
docker-build: test ## Build docker image with the manager.
210-
docker build -t ${IMG} .
217+
docker-build: test ## Build container image with the manager.
218+
$(CONTAINER_RUNTIME) build -t ${IMG} .
211219

212220
.PHONY: docker-push
213-
docker-push: ## Push docker image with the manager.
214-
docker push ${IMG}
221+
docker-push: ## Push container image with the manager.
222+
$(CONTAINER_RUNTIME) push ${IMG}
215223

216224
##@ Build Dependencies
217225

@@ -305,7 +313,7 @@ bundle: operator-sdk manifests kustomize ## Generate bundle manifests and metada
305313

306314
.PHONY: bundle-build
307315
bundle-build: ## Build the bundle image.
308-
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
316+
$(CONTAINER_RUNTIME) build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
309317

310318
.PHONY: bundle-push
311319
bundle-push: ## Push the bundle image.
@@ -346,7 +354,7 @@ endif
346354
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
347355
.PHONY: catalog-build
348356
catalog-build: opm ## Build a catalog image.
349-
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
357+
$(OPM) index add --container-tool $(CONTAINER_RUNTIME) --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
350358

351359
# Push the catalog image.
352360
.PHONY: catalog-push

controllers/gitopsservice_controller.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ func (r *ReconcileGitopsService) SetupWithManager(mgr ctrl.Manager) error {
112112
builder.WithPredicates(predicate.NewPredicateFuncs(func(obj client.Object) bool {
113113
return obj.GetName() == "openshift-gitops"
114114
})),
115-
).
115+
).Watches(&argoapp.ArgoCD{},
116+
&handler.EnqueueRequestForObject{},
117+
builder.WithPredicates(predicate.NewPredicateFuncs(func(obj client.Object) bool {
118+
return obj.GetName() == "openshift-gitops" && obj.GetNamespace() == "openshift-gitops"
119+
}))).
116120
Complete(r)
117121
}
118122

test/openshift/e2e/ginkgo/sequential/1-018_validate_disable_default_instance_test.go

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package sequential
1818

1919
import (
20+
"context"
21+
2022
"github.com/argoproj-labs/argocd-operator/api/v1beta1"
2123
. "github.com/onsi/ginkgo/v2"
2224
. "github.com/onsi/gomega"
@@ -25,6 +27,7 @@ import (
2527
"github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/deployment"
2628
k8sFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/k8s"
2729
statefulsetFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/statefulset"
30+
"github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils"
2831
appsv1 "k8s.io/api/apps/v1"
2932
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3033
)
@@ -37,13 +40,71 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
3740
fixture.EnsureSequentialCleanSlate()
3841
})
3942

40-
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() {
43+
It("verifies that the default ArgoCD instance from openshift-gitops namespace is recreated when deleted manually", func() {
44+
45+
openshiftGitopsArgoCD, err := argocdFixture.GetOpenShiftGitOpsNSArgoCD()
46+
Expect(err).ToNot(HaveOccurred())
47+
48+
By("verifying that the openshift-gitops ArgoCD instance exists initially")
49+
Eventually(openshiftGitopsArgoCD).Should(k8sFixture.ExistByName())
50+
Eventually(openshiftGitopsArgoCD).Should(argocdFixture.BeAvailable())
51+
52+
By("verifying associated deployments exist")
53+
deploymentsToVerify := []string{
54+
"openshift-gitops-server",
55+
"openshift-gitops-redis",
56+
"openshift-gitops-repo-server",
57+
"openshift-gitops-applicationset-controller",
58+
}
59+
60+
for _, deplName := range deploymentsToVerify {
61+
depl := &appsv1.Deployment{
62+
ObjectMeta: metav1.ObjectMeta{Name: deplName, Namespace: "openshift-gitops"},
63+
}
64+
Eventually(depl).Should(k8sFixture.ExistByName())
65+
}
66+
67+
ss := &appsv1.StatefulSet{
68+
ObjectMeta: metav1.ObjectMeta{
69+
Name: "openshift-gitops-application-controller",
70+
Namespace: "openshift-gitops",
71+
},
72+
}
73+
Eventually(ss).Should(k8sFixture.ExistByName())
74+
75+
By("manually deleting the openshift-gitops ArgoCD instance")
76+
k8sClient, _ := utils.GetE2ETestKubeClient()
77+
err = k8sClient.Delete(context.Background(), openshiftGitopsArgoCD)
78+
Expect(err).ToNot(HaveOccurred())
4179

80+
By("verifying ArgoCD CR gets recreated automatically by the operator")
81+
openshiftGitopsArgoCD = &v1beta1.ArgoCD{
82+
ObjectMeta: metav1.ObjectMeta{
83+
Name: "openshift-gitops",
84+
Namespace: "openshift-gitops",
85+
},
86+
}
87+
Eventually(openshiftGitopsArgoCD, "3m", "5s").Should(k8sFixture.ExistByName())
88+
Eventually(openshiftGitopsArgoCD, "5m", "5s").Should(argocdFixture.BeAvailable())
89+
90+
By("verifying deployments and statefulset are recreated and become ready")
91+
for _, deplName := range deploymentsToVerify {
92+
depl := &appsv1.Deployment{
93+
ObjectMeta: metav1.ObjectMeta{Name: deplName, Namespace: "openshift-gitops"},
94+
}
95+
Eventually(depl, "3m", "5s").Should(k8sFixture.ExistByName())
96+
Eventually(depl, "5m", "5s").Should(deployment.HaveReadyReplicas(1))
97+
}
98+
99+
Eventually(ss, "3m", "5s").Should(k8sFixture.ExistByName())
100+
Eventually(ss, "5m", "5s").Should(statefulsetFixture.HaveReadyReplicas(1))
101+
})
102+
103+
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() {
42104
if fixture.EnvLocalRun() {
43105
Skip("when running locally, there is no subscription or operator deployment to modify, so this test is skipped.")
44106
return
45107
}
46-
47108
openshiftGitopsArgoCD, err := argocdFixture.GetOpenShiftGitOpsNSArgoCD()
48109
Expect(err).ToNot(HaveOccurred())
49110

0 commit comments

Comments
 (0)