Skip to content

WIP: OPRUN-4057: Migrate single/own namespace tests #425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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 @@ -9,6 +9,36 @@
"lifecycle": "blocking",
"environmentSelector": {}
},
{
"name": "[sig-olmv1][OCPFeatureGate:NewOLMOwnSingleNamespace][Skipped:Disconnected] OLMv1 operator installation support for singleNamespace watch mode with quay-operator should install a cluster extension successfully",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@camilamacedo86 camilamacedo86 Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add SERIAL on the names but they are not today
So, it is a tech debt that we will need to sort out in a follow-up

"labels": {},
"resources": {
"isolation": {}
},
"source": "openshift:payload:olmv1",
"lifecycle": "blocking",
"environmentSelector": {}
},
{
"name": "[sig-olmv1][OCPFeatureGate:NewOLMOwnSingleNamespace][Skipped:Disconnected] OLMv1 operator installation support for ownNamespace watch mode with quay-operator should install a cluster extension successfully",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@camilamacedo86 camilamacedo86 Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add SERIAL on the names but they are not today
So, it is a tech debt that we will need to sort out in a follow-up

"labels": {},
"resources": {
"isolation": {}
},
"source": "openshift:payload:olmv1",
"lifecycle": "blocking",
"environmentSelector": {}
},
{
"name": "[sig-olmv1][OCPFeatureGate:NewOLMOwnSingleNamespace][Skipped:Disconnected] OLMv1 operator installation support for ownNamespace watch mode with an operator that does not support ownNamespace installation mode should fail to install a cluster extension successfully",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@camilamacedo86 camilamacedo86 Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add SERIAL on the names but they are not today
So, it is a tech debt that we will need to sort out in a follow-up

"labels": {},
"resources": {
"isolation": {}
},
"source": "openshift:payload:olmv1",
"lifecycle": "blocking",
"environmentSelector": {}
},
{
"name": "[sig-olmv1] OLMv1 should pass a trivial sanity check",
"labels": {},
Expand Down
266 changes: 266 additions & 0 deletions openshift/tests-extension/test/olmv1-singleownnamespace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
package test

import (
"context"
"fmt"
"time"

//nolint:staticcheck // ST1001: dot-imports for readability
. "github.com/onsi/ginkgo/v2"
//nolint:staticcheck // ST1001: dot-imports for readability
. "github.com/onsi/gomega"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/rand"
"sigs.k8s.io/controller-runtime/pkg/client"

olmv1 "github.com/operator-framework/operator-controller/api/v1"

"github/operator-framework-operator-controller/openshift/tests-extension/pkg/env"
"github/operator-framework-operator-controller/openshift/tests-extension/pkg/helpers"
)

var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMOwnSingleNamespace][Skipped:Disconnected] OLMv1 operator installation support for singleNamespace watch mode with quay-operator", Serial, func() {
var (
k8sClient client.Client
namespace string
testPrefix = "quay-singlens"
)

BeforeEach(func() {
By("checking if OpenShift is available for tests")
if !env.Get().IsOpenShift {
Skip("Requires OpenShift for the tests")
}

k8sClient = env.Get().K8sClient
namespace = fmt.Sprintf("olmv1-%s-ns-%s", testPrefix, rand.String(4))

By("ensuring no ClusterExtension and CRD for quay-operator")
helpers.EnsureCleanupClusterExtension(context.Background(), "quay-operator", "quayregistries.quay.redhat.com")

By(fmt.Sprintf("creating namespace %s for single-namespace tests", namespace))
ns := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: namespace,
},
}
Expect(k8sClient.Create(context.Background(), ns)).To(Succeed(), "failed to create test namespace %q", namespace)
DeferCleanup(func() {
By(fmt.Sprintf("cleaning up namespace %s", namespace))
_ = k8sClient.Delete(context.Background(), ns)
})
})

It("should install a cluster extension successfully", func(ctx SpecContext) {
unique := rand.String(4)
saName := fmt.Sprintf("install-%s-sa-%s", testPrefix, unique)
crbName := fmt.Sprintf("install-%s-crb-%s", testPrefix, unique)
ceName := fmt.Sprintf("install-%s-ce-%s", testPrefix, unique)

By("creating ServiceAccount")
sa := helpers.NewServiceAccount(saName, namespace)
Expect(k8sClient.Create(ctx, sa)).To(Succeed(), "failed to create ServiceAccount %q", saName)
By("ensuring ServiceAccount is available before proceeding")
helpers.ExpectServiceAccountExists(ctx, saName, namespace)
By("registering cleanup for ServiceAccount")
DeferCleanup(func() {
By(fmt.Sprintf("cleanup: deleting ServiceAccount %s in namespace %s", sa.Name, sa.Namespace))
_ = k8sClient.Delete(ctx, sa)
})

By("creating ClusterRoleBinding")
crb := helpers.NewClusterRoleBinding(crbName, "cluster-admin", saName, namespace)
Expect(k8sClient.Create(ctx, crb)).To(Succeed(), "failed to create ClusterRoleBinding %q", crbName)
By("ensuring ClusterRoleBinding is available before proceeding")
helpers.ExpectClusterRoleBindingExists(ctx, crbName)
By("registering cleanup for ClusterRoleBinding")
DeferCleanup(func() {
By(fmt.Sprintf("cleanup: deleting ClusterRoleBinding %s", crb.Name))
_ = k8sClient.Delete(ctx, crb)
})

By("creating ClusterExtension with the watch-namespace annotation")
ce := helpers.NewClusterExtensionObject("quay-operator", "3.14.2", ceName, saName, namespace)
ce.Annotations = map[string]string{
"olm.operatorframework.io/watch-namespace": namespace,
}
Expect(k8sClient.Create(ctx, ce)).To(Succeed(), "failed to create ClusterExtension %q", ceName)
By("registering cleanup for ClusterExtension")
DeferCleanup(func() {
By(fmt.Sprintf("cleanup: deleting ClusterExtension %s", ce.Name))
_ = k8sClient.Delete(ctx, ce)
})

By("waiting for the ClusterExtension to be installed")
helpers.ExpectClusterExtensionToBeInstalled(ctx, ceName)
})
})

var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMOwnSingleNamespace][Skipped:Disconnected] OLMv1 operator installation support for ownNamespace watch mode with quay-operator", Serial, func() {
var (
k8sClient client.Client
namespace string
testPrefix = "quay-own-ns"
)

BeforeEach(func() {
By("checking if OpenShift is available for tests")
if !env.Get().IsOpenShift {
Skip("Requires OpenShift for the tests")
}

k8sClient = env.Get().K8sClient
namespace = fmt.Sprintf("olmv1-%s-ns-%s", testPrefix, rand.String(4))

By("ensuring no ClusterExtension and CRD for quay-operator")
helpers.EnsureCleanupClusterExtension(context.Background(), "quay-operator", "quayregistries.quay.redhat.com")

By(fmt.Sprintf("creating namespace %s for own-namespace tests", namespace))
ns := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: namespace,
},
}
Expect(k8sClient.Create(context.Background(), ns)).To(Succeed(), "failed to create test namespace %q", namespace)
DeferCleanup(func() {
By(fmt.Sprintf("cleaning up namespace %s", namespace))
_ = k8sClient.Delete(context.Background(), ns)
})
})

It("should install a cluster extension successfully", func(ctx SpecContext) {
unique := rand.String(4)
saName := fmt.Sprintf("install-%s-sa-%s", testPrefix, unique)
crbName := fmt.Sprintf("install-%s-crb-%s", testPrefix, unique)
ceName := fmt.Sprintf("install-%s-ce-%s", testPrefix, unique)

By("creating ServiceAccount")
sa := helpers.NewServiceAccount(saName, namespace)
Expect(k8sClient.Create(ctx, sa)).To(Succeed(), "failed to create ServiceAccount %q", saName)
By("ensuring ServiceAccount is available before proceeding")
helpers.ExpectServiceAccountExists(ctx, saName, namespace)
By("registering cleanup for ServiceAccount")
DeferCleanup(func() {
By(fmt.Sprintf("cleanup: deleting ServiceAccount %s in namespace %s", sa.Name, sa.Namespace))
_ = k8sClient.Delete(ctx, sa)
})

By("creating ClusterRoleBinding")
crb := helpers.NewClusterRoleBinding(crbName, "cluster-admin", saName, namespace)
Expect(k8sClient.Create(ctx, crb)).To(Succeed(), "failed to create ClusterRoleBinding %q", crbName)
By("ensuring ClusterRoleBinding is available before proceeding")
helpers.ExpectClusterRoleBindingExists(ctx, crbName)
By("registering cleanup for ClusterRoleBinding")
DeferCleanup(func() {
By(fmt.Sprintf("cleanup: deleting ClusterRoleBinding %s", crb.Name))
_ = k8sClient.Delete(ctx, crb)
})

By("creating ClusterExtension with the watch-namespace annotation")
ce := helpers.NewClusterExtensionObject("quay-operator", "3.14.2", ceName, saName, namespace)
ce.Annotations = map[string]string{
"olm.operatorframework.io/watch-namespace": namespace,
}
Expect(k8sClient.Create(ctx, ce)).To(Succeed(), "failed to create ClusterExtension %q", ceName)
By("registering cleanup for ClusterExtension")
DeferCleanup(func() {
By(fmt.Sprintf("cleanup: deleting ClusterExtension %s", ce.Name))
_ = k8sClient.Delete(ctx, ce)
})

By("waiting for the ClusterExtension to be installed")
helpers.ExpectClusterExtensionToBeInstalled(ctx, ceName)
})
})

var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMOwnSingleNamespace][Skipped:Disconnected] OLMv1 operator installation support for ownNamespace watch mode with an operator that does not support ownNamespace installation mode", Serial, func() {
var (
k8sClient client.Client
namespace string
testPrefix = "pipelines-fail-own-ns"
)

BeforeEach(func() {
By("checking if OpenShift is available for tests")
if !env.Get().IsOpenShift {
Skip("Requires OpenShift for the tests")
}

k8sClient = env.Get().K8sClient
namespace = fmt.Sprintf("olmv1-%s-ns-%s", testPrefix, rand.String(4))

By("ensuring no ClusterExtension and CRD for openshift-pipelines-operator-rh")
helpers.EnsureCleanupClusterExtension(context.Background(), "openshift-pipelines-operator-rh", "clustertasks.tekton.dev")

By(fmt.Sprintf("creating namespace %s for failing tests", namespace))
ns := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: namespace,
},
}
Expect(k8sClient.Create(context.Background(), ns)).To(Succeed(), "failed to create test namespace %q", namespace)
DeferCleanup(func() {
By(fmt.Sprintf("cleaning up namespace %s", namespace))
_ = k8sClient.Delete(context.Background(), ns)
})
})

It("should fail to install a cluster extension successfully", func(ctx SpecContext) {
unique := rand.String(4)
saName := fmt.Sprintf("install-%s-sa-%s", testPrefix, unique)
crbName := fmt.Sprintf("install-%s-crb-%s", testPrefix, unique)
ceName := fmt.Sprintf("install-%s-ce-%s", testPrefix, unique)

By("creating ServiceAccount")
sa := helpers.NewServiceAccount(saName, namespace)
Expect(k8sClient.Create(ctx, sa)).To(Succeed(), "failed to create ServiceAccount %q", saName)
By("ensuring ServiceAccount is available before proceeding")
helpers.ExpectServiceAccountExists(ctx, saName, namespace)
By("registering cleanup for ServiceAccount")
DeferCleanup(func() {
By(fmt.Sprintf("cleanup: deleting ServiceAccount %s in namespace %s", sa.Name, sa.Namespace))
_ = k8sClient.Delete(ctx, sa)
})

By("creating ClusterRoleBinding")
crb := helpers.NewClusterRoleBinding(crbName, "cluster-admin", saName, namespace)
Expect(k8sClient.Create(ctx, crb)).To(Succeed(), "failed to create ClusterRoleBinding %q", crbName)
By("ensuring ClusterRoleBinding is available before proceeding")
helpers.ExpectClusterRoleBindingExists(ctx, crbName)
By("registering cleanup for ClusterRoleBinding")
DeferCleanup(func() {
By(fmt.Sprintf("cleanup: deleting ClusterRoleBinding %s", crb.Name))
_ = k8sClient.Delete(ctx, crb)
})

By("creating ClusterExtension with the watch-namespace annotation")
ce := helpers.NewClusterExtensionObject("openshift-pipelines-operator-rh", "1.17.1", ceName, saName, namespace)
ce.Annotations = map[string]string{
"olm.operatorframework.io/watch-namespace": namespace,
}
Expect(k8sClient.Create(ctx, ce)).To(Succeed(), "failed to create ClusterExtension %q", ceName)
By("registering cleanup for ClusterExtension")
DeferCleanup(func() {
By(fmt.Sprintf("cleanup: deleting ClusterExtension %s", ce.Name))
_ = k8sClient.Delete(ctx, ce)
})

By("waiting for the ClusterExtension to fail installation")
Eventually(func(g Gomega) {
var ext olmv1.ClusterExtension
err := k8sClient.Get(ctx, client.ObjectKey{Name: ceName}, &ext)
g.Expect(err).ToNot(HaveOccurred(), "failed to get ClusterExtension %q", ceName)

conditions := ext.Status.Conditions
g.Expect(conditions).ToNot(BeEmpty(), "ClusterExtension %q has empty status.conditions", ceName)

installed := meta.FindStatusCondition(conditions, olmv1.TypeInstalled)
g.Expect(installed).ToNot(BeNil(), "Installed condition not found")
g.Expect(installed.Status).To(Equal(metav1.ConditionFalse), "Installed should be False")
g.Expect(installed.Reason).To(Equal("Failed"))
}).WithTimeout(5 * time.Minute).WithPolling(1 * time.Second).Should(Succeed())
})
})