Skip to content
Merged
20 changes: 14 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 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 image with the manager.
$(CONTAINER_RUNTIME) push ${IMG}

##@ Build Dependencies

Expand Down Expand Up @@ -305,7 +313,7 @@ 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.
Expand Down Expand Up @@ -346,7 +354,7 @@ 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
Expand Down
6 changes: 5 additions & 1 deletion controllers/gitopsservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)
Expand All @@ -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 the default ArgoCD instance from openshift-gitops namespace is recreated when deleted manually", 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())

Expand Down