Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
Context("1-010_validate-ootb-manage-other-namespace", func() {

var (
ctx context.Context
k8sClient client.Client
ctx context.Context
k8sClient client.Client
nsTest_1_10_custom *corev1.Namespace
nsCleanupFunc func()
app *argocdv1alpha1.Application
)

BeforeEach(func() {
Expand All @@ -51,11 +54,21 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
ctx = context.Background()
})

AfterEach(func() {
fixture.OutputDebugOnFail(nsTest_1_10_custom, "openshift-gitops")

if nsCleanupFunc != nil {
nsCleanupFunc()
}
if app != nil {
_ = k8sClient.Delete(ctx, app)
}
})

It("verifies that openshift-gitops Argo CD instance is able to manage/unmanage other namespaces via managed-by label", func() {

By("creating a new namespace that is managed by openshift-gitops Argo CD instance")
nsTest_1_10_custom, cleanupFunc1 := fixture.CreateManagedNamespaceWithCleanupFunc("test-1-10-custom", "openshift-gitops")
defer cleanupFunc1()
nsTest_1_10_custom, nsCleanupFunc = fixture.CreateManagedNamespaceWithCleanupFunc("test-1-10-custom", "openshift-gitops")

openshiftgitopsArgoCD, err := argocdFixture.GetOpenShiftGitOpsNSArgoCD()
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -91,7 +104,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
}}))

By("creating a new Argo CD application in openshift-gitops ns, targeting the new namespace")
app := &argocdv1alpha1.Application{
app = &argocdv1alpha1.Application{
ObjectMeta: metav1.ObjectMeta{Name: "test-1-10-custom", Namespace: openshiftgitopsArgoCD.Namespace},
Spec: argocdv1alpha1.ApplicationSpec{
Source: &argocdv1alpha1.ApplicationSource{
Expand All @@ -113,9 +126,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
},
}
Expect(k8sClient.Create(ctx, app)).To(Succeed())
defer func() { // cleanup on test exit
Expect(k8sClient.Delete(ctx, app)).To(Succeed())
}()

By("verifying that Argo CD is able to deploy to that other namespace")
Eventually(app, "4m", "5s").Should(appFixture.HaveHealthStatusCode(health.HealthStatusHealthy))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
deploymentsShouldExist := []string{"argocd-redis", "argocd-server", "argocd-repo-server", "nginx-deployment"}
for _, depl := range deploymentsShouldExist {
depl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: depl, Namespace: test_1_27_customNS.Name}}
Eventually(depl).Should(k8sFixture.ExistByName())
Eventually(depl).Should(deploymentFixture.HaveReplicas(1))
Eventually(depl).Should(deploymentFixture.HaveReadyReplicas(1))
Eventually(depl, "4m", "5s").Should(k8sFixture.ExistByName())
Eventually(depl, "4m", "5s").Should(deploymentFixture.HaveReplicas(1))
Eventually(depl, "4m", "5s").Should(deploymentFixture.HaveReadyReplicas(1))
}

statefulSet := &appsv1.StatefulSet{ObjectMeta: metav1.ObjectMeta{Name: "argocd-application-controller", Namespace: test_1_27_customNS.Name}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package sequential

import (
"strings"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture"
Expand All @@ -16,27 +18,45 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
})

AfterEach(func() {

// Delete the new role we created during the test
defer func() {
By("deleting the role we created during the test")
_, err := argocdFixture.RunArgoCDCLI("proj", "role", "delete", "default", "somerole")
Expect(err).ToNot(HaveOccurred())
}()

fixture.OutputDebugOnFail()

})

It("creates a project role 'somerole' and group claim, and verifies group claim contains the expected data", func() {

defaultArgoCD, err := argocdFixture.GetOpenShiftGitOpsNSArgoCD()
Expect(err).ToNot(HaveOccurred())
Eventually(defaultArgoCD, "5m", "5s").Should(argocdFixture.BeAvailable())

By("logging in to Argo CD instance")
Expect(argocdFixture.LogInToDefaultArgoCDInstance()).To(Succeed())

By("Creating a new 'somerole' role in default project")
output, err := argocdFixture.RunArgoCDCLI("proj", "role", "create", "default", "somerole")
Expect(err).ToNot(HaveOccurred())

// Delete the new role we created during the test
defer func() {
By("deleting the role we created during the test")
_, err = argocdFixture.RunArgoCDCLI("proj", "role", "delete", "default", "somerole")
Expect(err).ToNot(HaveOccurred())
}()

Expect(output).To(ContainSubstring("Role 'somerole' created"))

By("waiting for Argo CD to verify the role exists before we add to it (there seems to be some kind of intermittent race condition here in Argo CD itself, where create succeeds in the previous step, but we received 503 in the next step)")
Eventually(func() bool {
output, err := argocdFixture.RunArgoCDCLI("proj", "role", "get", "default", "somerole")
if err != nil {
GinkgoWriter.Println("error:", err)
return false
}

return strings.Contains(output, "Role Name:")

}, "30s", "5s").Should(BeTrue())

By("adding a group claim to the somerole role")
output, err = argocdFixture.RunArgoCDCLI("proj", "role", "add-group", "default", "somerole", "\"CN=foo,OU=bar,O=baz\"")
Expect(err).ToNot(HaveOccurred())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,15 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
Context("1-102_validate_handle_terminating_namespaces", func() {

var (
k8sClient client.Client
ctx context.Context
k8sClient client.Client
ctx context.Context
ns *corev1.Namespace
janeNs *corev1.Namespace
johnNs *corev1.Namespace
configMapJaneNs *corev1.ConfigMap
nsCleanupFunc func()
janeNsCleanupFunc func()
johnNsCleanupFunc func()
)

BeforeEach(func() {
Expand All @@ -52,11 +59,31 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
ctx = context.Background()
})

AfterEach(func() {

fixture.OutputDebugOnFail(ns, janeNs, johnNs)

// Remove the ConfigMap finalizer so the namespace can be cleaned up
if configMapJaneNs != nil {
configmapFixture.Update(configMapJaneNs, func(cm *corev1.ConfigMap) {
cm.Finalizers = nil
})
}
if johnNsCleanupFunc != nil {
johnNsCleanupFunc()
}
if janeNsCleanupFunc != nil {
janeNsCleanupFunc()
}
if nsCleanupFunc != nil {
nsCleanupFunc()
}
})

It("ensures that if one managed-by namespace is stuck in terminating, it does not prevent other managed-by namespaces from being managed or deployed to", func() {

By("creating simple namespace-scoped Argo CD instance")
ns, cleanupFunc := fixture.CreateRandomE2ETestNamespaceWithCleanupFunc()
defer cleanupFunc()
ns, nsCleanupFunc = fixture.CreateRandomE2ETestNamespaceWithCleanupFunc()

argoCD := &argov1beta1api.ArgoCD{
ObjectMeta: metav1.ObjectMeta{Name: "argocd", Namespace: ns.Name},
Expand All @@ -68,20 +95,12 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
Eventually(argoCD, "5m", "5s").Should(argocdFixture.BeAvailable())

By("creating a namespace 'jane' containing a ConfigMap with a unowned finalizer")
janeNs, cleanupFunc := fixture.CreateManagedNamespaceWithCleanupFunc("jane", ns.Name)
defer cleanupFunc()
janeNs, janeNsCleanupFunc = fixture.CreateManagedNamespaceWithCleanupFunc("jane", ns.Name)

configMapJaneNs := corev1.ConfigMap{
configMapJaneNs = &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{Name: "my-config-map-2", Namespace: janeNs.Name, Finalizers: []string{"some.random/finalizer"}},
}
Expect(k8sClient.Create(ctx, &configMapJaneNs)).To(Succeed())

// 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.Finalizers = nil
})
}()
Expect(k8sClient.Create(ctx, configMapJaneNs)).To(Succeed())

By("deleting the jane NS in a background go routine, which puts the jane NS into a simulated stuck in terminating state")
go func() {
Expand All @@ -93,8 +112,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
Eventually(janeNs).Should(namespaceFixture.HavePhase(corev1.NamespaceTerminating))

By("creating John NS")
johnNs, cleanupFunc := fixture.CreateManagedNamespaceWithCleanupFunc("john", ns.Name)
defer cleanupFunc()
johnNs, johnNsCleanupFunc = fixture.CreateManagedNamespaceWithCleanupFunc("john", ns.Name)

By("Wait for managed-by rolebindings to be created in John NS")
Eventually(func() bool {
Expand Down