|
| 1 | +package test |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "time" |
| 7 | + |
| 8 | + //nolint:staticcheck // ST1001: dot-imports for readability |
| 9 | + . "github.com/onsi/ginkgo/v2" |
| 10 | + //nolint:staticcheck // ST1001: dot-imports for readability |
| 11 | + . "github.com/onsi/gomega" |
| 12 | + |
| 13 | + corev1 "k8s.io/api/core/v1" |
| 14 | + "k8s.io/apimachinery/pkg/api/meta" |
| 15 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 16 | + "k8s.io/apimachinery/pkg/util/rand" |
| 17 | + "sigs.k8s.io/controller-runtime/pkg/client" |
| 18 | + |
| 19 | + olmv1 "github.com/operator-framework/operator-controller/api/v1" |
| 20 | + |
| 21 | + "github/operator-framework-operator-controller/openshift/tests-extension/pkg/env" |
| 22 | + "github/operator-framework-operator-controller/openshift/tests-extension/pkg/helpers" |
| 23 | +) |
| 24 | + |
| 25 | +var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMOwnSingleNamespace][Skipped:Disconnected] OLMv1 operator installation support for singleNamespace watch mode with quay-operator", Serial, func() { |
| 26 | + var ( |
| 27 | + k8sClient client.Client |
| 28 | + namespace string |
| 29 | + ) |
| 30 | + |
| 31 | + BeforeEach(func() { |
| 32 | + if !env.Get().IsOpenShift { |
| 33 | + Skip("Requires OpenShift for the tests") |
| 34 | + } |
| 35 | + |
| 36 | + k8sClient = env.Get().K8sClient |
| 37 | + namespace = "olmv1-single-own-ns-" + rand.String(4) |
| 38 | + |
| 39 | + By(fmt.Sprintf("creating namespace %s for single-namespace tests", namespace)) |
| 40 | + ns := &corev1.Namespace{ |
| 41 | + ObjectMeta: metav1.ObjectMeta{ |
| 42 | + Name: namespace, |
| 43 | + }, |
| 44 | + } |
| 45 | + Expect(k8sClient.Create(context.Background(), ns)).To(Succeed(), "failed to create test namespace %q", namespace) |
| 46 | + DeferCleanup(func() { |
| 47 | + By(fmt.Sprintf("cleaning up namespace %s", namespace)) |
| 48 | + _ = k8sClient.Delete(context.Background(), ns) |
| 49 | + }) |
| 50 | + }) |
| 51 | + |
| 52 | + It("should install a cluster extension successfully", func(ctx SpecContext) { |
| 53 | + unique := rand.String(4) |
| 54 | + saName := "install-test-sa-" + unique |
| 55 | + crbName := "install-test-crb-" + unique |
| 56 | + ceName := "install-test-ce-" + unique |
| 57 | + |
| 58 | + By("creating ServiceAccount, ClusterRoleBinding, and ClusterExtension with the watch-namespace annotation") |
| 59 | + sa := helpers.NewServiceAccount(saName, namespace) |
| 60 | + Expect(k8sClient.Create(ctx, sa)).To(Succeed(), "failed to create ServiceAccount %q", saName) |
| 61 | + DeferCleanup(func() { _ = k8sClient.Delete(ctx, sa) }) |
| 62 | + |
| 63 | + crb := helpers.NewClusterRoleBinding(crbName, "cluster-admin", saName, namespace) |
| 64 | + Expect(k8sClient.Create(ctx, crb)).To(Succeed(), "failed to create ClusterRoleBinding %q", crbName) |
| 65 | + DeferCleanup(func() { _ = k8sClient.Delete(ctx, crb) }) |
| 66 | + |
| 67 | + ce := helpers.NewClusterExtensionObject("quay-operator", "3.14.2", ceName, saName, namespace) |
| 68 | + ce.Annotations = map[string]string{ |
| 69 | + "olm.operatorframework.io/watch-namespace": namespace, |
| 70 | + } |
| 71 | + Expect(k8sClient.Create(ctx, ce)).To(Succeed(), "failed to create ClusterExtension %q", ceName) |
| 72 | + DeferCleanup(func() { _ = k8sClient.Delete(ctx, ce) }) |
| 73 | + |
| 74 | + By("waiting for the ClusterExtension to be installed") |
| 75 | + helpers.ExpectClusterExtensionToBeInstalled(ctx, ceName) |
| 76 | + }) |
| 77 | +}) |
| 78 | + |
| 79 | +var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMOwnSingleNamespace][Skipped:Disconnected] OLMv1 operator installation support for ownNamespace watch mode with quay-operator", Serial, func() { |
| 80 | + var ( |
| 81 | + k8sClient client.Client |
| 82 | + namespace string |
| 83 | + ) |
| 84 | + |
| 85 | + BeforeEach(func() { |
| 86 | + if !env.Get().IsOpenShift { |
| 87 | + Skip("Requires OpenShift for the tests") |
| 88 | + } |
| 89 | + |
| 90 | + k8sClient = env.Get().K8sClient |
| 91 | + namespace = "olmv1-own-ns-" + rand.String(4) |
| 92 | + |
| 93 | + By(fmt.Sprintf("creating namespace %s for own-namespace tests", namespace)) |
| 94 | + ns := &corev1.Namespace{ |
| 95 | + ObjectMeta: metav1.ObjectMeta{ |
| 96 | + Name: namespace, |
| 97 | + }, |
| 98 | + } |
| 99 | + Expect(k8sClient.Create(context.Background(), ns)).To(Succeed(), "failed to create test namespace %q", namespace) |
| 100 | + DeferCleanup(func() { |
| 101 | + By(fmt.Sprintf("cleaning up namespace %s", namespace)) |
| 102 | + _ = k8sClient.Delete(context.Background(), ns) |
| 103 | + }) |
| 104 | + }) |
| 105 | + |
| 106 | + It("should install a cluster extension successfully", func(ctx SpecContext) { |
| 107 | + unique := rand.String(4) |
| 108 | + saName := "install-test-sa-" + unique |
| 109 | + crbName := "install-test-crb-" + unique |
| 110 | + ceName := "install-test-ce-" + unique |
| 111 | + |
| 112 | + By("creating ServiceAccount, ClusterRoleBinding, and ClusterExtension with the watch-namespace annotation") |
| 113 | + sa := helpers.NewServiceAccount(saName, namespace) |
| 114 | + Expect(k8sClient.Create(ctx, sa)).To(Succeed(), "failed to create ServiceAccount %q", saName) |
| 115 | + DeferCleanup(func() { _ = k8sClient.Delete(ctx, sa) }) |
| 116 | + |
| 117 | + crb := helpers.NewClusterRoleBinding(crbName, "cluster-admin", saName, namespace) |
| 118 | + Expect(k8sClient.Create(ctx, crb)).To(Succeed(), "failed to create ClusterRoleBinding %q", crbName) |
| 119 | + DeferCleanup(func() { _ = k8sClient.Delete(ctx, crb) }) |
| 120 | + |
| 121 | + ce := helpers.NewClusterExtensionObject("quay-operator", "3.14.2", ceName, saName, namespace) |
| 122 | + ce.Annotations = map[string]string{ |
| 123 | + "olm.operatorframework.io/watch-namespace": namespace, |
| 124 | + } |
| 125 | + Expect(k8sClient.Create(ctx, ce)).To(Succeed(), "failed to create ClusterExtension %q", ceName) |
| 126 | + DeferCleanup(func() { _ = k8sClient.Delete(ctx, ce) }) |
| 127 | + |
| 128 | + By("waiting for the ClusterExtension to be installed") |
| 129 | + helpers.ExpectClusterExtensionToBeInstalled(ctx, ceName) |
| 130 | + }) |
| 131 | +}) |
| 132 | + |
| 133 | +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", func() { |
| 134 | + var ( |
| 135 | + k8sClient client.Client |
| 136 | + namespace string |
| 137 | + ) |
| 138 | + |
| 139 | + BeforeEach(func() { |
| 140 | + if !env.Get().IsOpenShift { |
| 141 | + Skip("Requires OpenShift for the tests") |
| 142 | + } |
| 143 | + |
| 144 | + k8sClient = env.Get().K8sClient |
| 145 | + namespace = "olmv1-failing-own-ns-" + rand.String(4) |
| 146 | + |
| 147 | + By(fmt.Sprintf("creating namespace %s for failing tests", namespace)) |
| 148 | + ns := &corev1.Namespace{ |
| 149 | + ObjectMeta: metav1.ObjectMeta{ |
| 150 | + Name: namespace, |
| 151 | + }, |
| 152 | + } |
| 153 | + Expect(k8sClient.Create(context.Background(), ns)).To(Succeed(), "failed to create test namespace %q", namespace) |
| 154 | + DeferCleanup(func() { |
| 155 | + By(fmt.Sprintf("cleaning up namespace %s", namespace)) |
| 156 | + _ = k8sClient.Delete(context.Background(), ns) |
| 157 | + }) |
| 158 | + }) |
| 159 | + |
| 160 | + It("should fail to install a cluster extension successfully", func(ctx SpecContext) { |
| 161 | + unique := rand.String(4) |
| 162 | + saName := "install-test-sa-" + unique |
| 163 | + crbName := "install-test-crb-" + unique |
| 164 | + ceName := "install-test-ce-" + unique |
| 165 | + |
| 166 | + By("creating ServiceAccount, ClusterRoleBinding, and ClusterExtension with the watch-namespace annotation") |
| 167 | + sa := helpers.NewServiceAccount(saName, namespace) |
| 168 | + Expect(k8sClient.Create(ctx, sa)).To(Succeed(), "failed to create ServiceAccount %q", saName) |
| 169 | + DeferCleanup(func() { _ = k8sClient.Delete(ctx, sa) }) |
| 170 | + |
| 171 | + crb := helpers.NewClusterRoleBinding(crbName, "cluster-admin", saName, namespace) |
| 172 | + Expect(k8sClient.Create(ctx, crb)).To(Succeed(), "failed to create ClusterRoleBinding %q", crbName) |
| 173 | + DeferCleanup(func() { _ = k8sClient.Delete(ctx, crb) }) |
| 174 | + |
| 175 | + ce := helpers.NewClusterExtensionObject("openshift-pipelines-operator-rh", "1.17.1", ceName, saName, namespace) |
| 176 | + ce.Annotations = map[string]string{ |
| 177 | + "olm.operatorframework.io/watch-namespace": namespace, |
| 178 | + } |
| 179 | + Expect(k8sClient.Create(ctx, ce)).To(Succeed(), "failed to create ClusterExtension %q", ceName) |
| 180 | + DeferCleanup(func() { _ = k8sClient.Delete(ctx, ce) }) |
| 181 | + |
| 182 | + By("waiting for the ClusterExtension to fail installation") |
| 183 | + Eventually(func(g Gomega) { |
| 184 | + var ext olmv1.ClusterExtension |
| 185 | + err := k8sClient.Get(ctx, client.ObjectKey{Name: ceName}, &ext) |
| 186 | + g.Expect(err).ToNot(HaveOccurred(), "failed to get ClusterExtension %q", ceName) |
| 187 | + |
| 188 | + conditions := ext.Status.Conditions |
| 189 | + g.Expect(conditions).ToNot(BeEmpty(), "ClusterExtension %q has empty status.conditions", ceName) |
| 190 | + |
| 191 | + installed := meta.FindStatusCondition(conditions, olmv1.TypeInstalled) |
| 192 | + g.Expect(installed).ToNot(BeNil(), "Installed condition not found") |
| 193 | + g.Expect(installed.Status).To(Equal(metav1.ConditionFalse), "Installed should be False") |
| 194 | + g.Expect(installed.Reason).To(Equal("Failed")) |
| 195 | + }).WithTimeout(5 * time.Minute).WithPolling(1 * time.Second).Should(Succeed()) |
| 196 | + }) |
| 197 | +}) |
0 commit comments