|
| 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 | + testPrefix = "quay-singlens" |
| 30 | + ) |
| 31 | + |
| 32 | + BeforeEach(func() { |
| 33 | + By("checking if OpenShift is available for tests") |
| 34 | + if !env.Get().IsOpenShift { |
| 35 | + Skip("Requires OpenShift for the tests") |
| 36 | + } |
| 37 | + |
| 38 | + k8sClient = env.Get().K8sClient |
| 39 | + namespace = fmt.Sprintf("olmv1-%s-ns-%s", testPrefix, rand.String(4)) |
| 40 | + |
| 41 | + By("ensuring no ClusterExtension and CRD for quay-operator") |
| 42 | + helpers.EnsureCleanupClusterExtension(context.Background(), "quay-operator", "quayregistries.quay.redhat.com") |
| 43 | + |
| 44 | + By(fmt.Sprintf("creating namespace %s for single-namespace tests", namespace)) |
| 45 | + ns := &corev1.Namespace{ |
| 46 | + ObjectMeta: metav1.ObjectMeta{ |
| 47 | + Name: namespace, |
| 48 | + }, |
| 49 | + } |
| 50 | + Expect(k8sClient.Create(context.Background(), ns)).To(Succeed(), "failed to create test namespace %q", namespace) |
| 51 | + DeferCleanup(func() { |
| 52 | + By(fmt.Sprintf("cleaning up namespace %s", namespace)) |
| 53 | + _ = k8sClient.Delete(context.Background(), ns) |
| 54 | + }) |
| 55 | + }) |
| 56 | + |
| 57 | + It("should install a cluster extension successfully", func(ctx SpecContext) { |
| 58 | + unique := rand.String(4) |
| 59 | + saName := fmt.Sprintf("install-%s-sa-%s", testPrefix, unique) |
| 60 | + crbName := fmt.Sprintf("install-%s-crb-%s", testPrefix, unique) |
| 61 | + ceName := fmt.Sprintf("install-%s-ce-%s", testPrefix, unique) |
| 62 | + |
| 63 | + By("creating ServiceAccount") |
| 64 | + sa := helpers.NewServiceAccount(saName, namespace) |
| 65 | + Expect(k8sClient.Create(ctx, sa)).To(Succeed(), "failed to create ServiceAccount %q", saName) |
| 66 | + By("ensuring ServiceAccount is available before proceeding") |
| 67 | + helpers.ExpectServiceAccountExists(ctx, saName, namespace) |
| 68 | + By("registering cleanup for ServiceAccount") |
| 69 | + DeferCleanup(func() { |
| 70 | + By(fmt.Sprintf("cleanup: deleting ServiceAccount %s in namespace %s", sa.Name, sa.Namespace)) |
| 71 | + _ = k8sClient.Delete(ctx, sa) |
| 72 | + }) |
| 73 | + |
| 74 | + By("creating ClusterRoleBinding") |
| 75 | + crb := helpers.NewClusterRoleBinding(crbName, "cluster-admin", saName, namespace) |
| 76 | + Expect(k8sClient.Create(ctx, crb)).To(Succeed(), "failed to create ClusterRoleBinding %q", crbName) |
| 77 | + By("ensuring ClusterRoleBinding is available before proceeding") |
| 78 | + helpers.ExpectClusterRoleBindingExists(ctx, crbName) |
| 79 | + By("registering cleanup for ClusterRoleBinding") |
| 80 | + DeferCleanup(func() { |
| 81 | + By(fmt.Sprintf("cleanup: deleting ClusterRoleBinding %s", crb.Name)) |
| 82 | + _ = k8sClient.Delete(ctx, crb) |
| 83 | + }) |
| 84 | + |
| 85 | + By("creating ClusterExtension with the watch-namespace annotation") |
| 86 | + ce := helpers.NewClusterExtensionObject("quay-operator", "3.14.2", ceName, saName, namespace) |
| 87 | + ce.Annotations = map[string]string{ |
| 88 | + "olm.operatorframework.io/watch-namespace": namespace, |
| 89 | + } |
| 90 | + Expect(k8sClient.Create(ctx, ce)).To(Succeed(), "failed to create ClusterExtension %q", ceName) |
| 91 | + By("registering cleanup for ClusterExtension") |
| 92 | + DeferCleanup(func() { |
| 93 | + By(fmt.Sprintf("cleanup: deleting ClusterExtension %s", ce.Name)) |
| 94 | + _ = k8sClient.Delete(ctx, ce) |
| 95 | + }) |
| 96 | + |
| 97 | + By("waiting for the ClusterExtension to be installed") |
| 98 | + helpers.ExpectClusterExtensionToBeInstalled(ctx, ceName) |
| 99 | + }) |
| 100 | +}) |
| 101 | + |
| 102 | +var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMOwnSingleNamespace][Skipped:Disconnected] OLMv1 operator installation support for ownNamespace watch mode with quay-operator", Serial, func() { |
| 103 | + var ( |
| 104 | + k8sClient client.Client |
| 105 | + namespace string |
| 106 | + testPrefix = "quay-own-ns" |
| 107 | + ) |
| 108 | + |
| 109 | + BeforeEach(func() { |
| 110 | + By("checking if OpenShift is available for tests") |
| 111 | + if !env.Get().IsOpenShift { |
| 112 | + Skip("Requires OpenShift for the tests") |
| 113 | + } |
| 114 | + |
| 115 | + k8sClient = env.Get().K8sClient |
| 116 | + namespace = fmt.Sprintf("olmv1-%s-ns-%s", testPrefix, rand.String(4)) |
| 117 | + |
| 118 | + By("ensuring no ClusterExtension and CRD for quay-operator") |
| 119 | + helpers.EnsureCleanupClusterExtension(context.Background(), "quay-operator", "quayregistries.quay.redhat.com") |
| 120 | + |
| 121 | + By(fmt.Sprintf("creating namespace %s for own-namespace tests", namespace)) |
| 122 | + ns := &corev1.Namespace{ |
| 123 | + ObjectMeta: metav1.ObjectMeta{ |
| 124 | + Name: namespace, |
| 125 | + }, |
| 126 | + } |
| 127 | + Expect(k8sClient.Create(context.Background(), ns)).To(Succeed(), "failed to create test namespace %q", namespace) |
| 128 | + DeferCleanup(func() { |
| 129 | + By(fmt.Sprintf("cleaning up namespace %s", namespace)) |
| 130 | + _ = k8sClient.Delete(context.Background(), ns) |
| 131 | + }) |
| 132 | + }) |
| 133 | + |
| 134 | + It("should install a cluster extension successfully", func(ctx SpecContext) { |
| 135 | + unique := rand.String(4) |
| 136 | + saName := fmt.Sprintf("install-%s-sa-%s", testPrefix, unique) |
| 137 | + crbName := fmt.Sprintf("install-%s-crb-%s", testPrefix, unique) |
| 138 | + ceName := fmt.Sprintf("install-%s-ce-%s", testPrefix, unique) |
| 139 | + |
| 140 | + By("creating ServiceAccount") |
| 141 | + sa := helpers.NewServiceAccount(saName, namespace) |
| 142 | + Expect(k8sClient.Create(ctx, sa)).To(Succeed(), "failed to create ServiceAccount %q", saName) |
| 143 | + By("ensuring ServiceAccount is available before proceeding") |
| 144 | + helpers.ExpectServiceAccountExists(ctx, saName, namespace) |
| 145 | + By("registering cleanup for ServiceAccount") |
| 146 | + DeferCleanup(func() { |
| 147 | + By(fmt.Sprintf("cleanup: deleting ServiceAccount %s in namespace %s", sa.Name, sa.Namespace)) |
| 148 | + _ = k8sClient.Delete(ctx, sa) |
| 149 | + }) |
| 150 | + |
| 151 | + By("creating ClusterRoleBinding") |
| 152 | + crb := helpers.NewClusterRoleBinding(crbName, "cluster-admin", saName, namespace) |
| 153 | + Expect(k8sClient.Create(ctx, crb)).To(Succeed(), "failed to create ClusterRoleBinding %q", crbName) |
| 154 | + By("ensuring ClusterRoleBinding is available before proceeding") |
| 155 | + helpers.ExpectClusterRoleBindingExists(ctx, crbName) |
| 156 | + By("registering cleanup for ClusterRoleBinding") |
| 157 | + DeferCleanup(func() { |
| 158 | + By(fmt.Sprintf("cleanup: deleting ClusterRoleBinding %s", crb.Name)) |
| 159 | + _ = k8sClient.Delete(ctx, crb) |
| 160 | + }) |
| 161 | + |
| 162 | + By("creating ClusterExtension with the watch-namespace annotation") |
| 163 | + ce := helpers.NewClusterExtensionObject("quay-operator", "3.14.2", ceName, saName, namespace) |
| 164 | + ce.Annotations = map[string]string{ |
| 165 | + "olm.operatorframework.io/watch-namespace": namespace, |
| 166 | + } |
| 167 | + Expect(k8sClient.Create(ctx, ce)).To(Succeed(), "failed to create ClusterExtension %q", ceName) |
| 168 | + By("registering cleanup for ClusterExtension") |
| 169 | + DeferCleanup(func() { |
| 170 | + By(fmt.Sprintf("cleanup: deleting ClusterExtension %s", ce.Name)) |
| 171 | + _ = k8sClient.Delete(ctx, ce) |
| 172 | + }) |
| 173 | + |
| 174 | + By("waiting for the ClusterExtension to be installed") |
| 175 | + helpers.ExpectClusterExtensionToBeInstalled(ctx, ceName) |
| 176 | + }) |
| 177 | +}) |
| 178 | + |
| 179 | +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() { |
| 180 | + var ( |
| 181 | + k8sClient client.Client |
| 182 | + namespace string |
| 183 | + testPrefix = "pipelines-fail-own-ns" |
| 184 | + ) |
| 185 | + |
| 186 | + BeforeEach(func() { |
| 187 | + By("checking if OpenShift is available for tests") |
| 188 | + if !env.Get().IsOpenShift { |
| 189 | + Skip("Requires OpenShift for the tests") |
| 190 | + } |
| 191 | + |
| 192 | + k8sClient = env.Get().K8sClient |
| 193 | + namespace = fmt.Sprintf("olmv1-%s-ns-%s", testPrefix, rand.String(4)) |
| 194 | + |
| 195 | + By("ensuring no ClusterExtension and CRD for openshift-pipelines-operator-rh") |
| 196 | + helpers.EnsureCleanupClusterExtension(context.Background(), "openshift-pipelines-operator-rh", "clustertasks.tekton.dev") |
| 197 | + |
| 198 | + By(fmt.Sprintf("creating namespace %s for failing tests", namespace)) |
| 199 | + ns := &corev1.Namespace{ |
| 200 | + ObjectMeta: metav1.ObjectMeta{ |
| 201 | + Name: namespace, |
| 202 | + }, |
| 203 | + } |
| 204 | + Expect(k8sClient.Create(context.Background(), ns)).To(Succeed(), "failed to create test namespace %q", namespace) |
| 205 | + DeferCleanup(func() { |
| 206 | + By(fmt.Sprintf("cleaning up namespace %s", namespace)) |
| 207 | + _ = k8sClient.Delete(context.Background(), ns) |
| 208 | + }) |
| 209 | + }) |
| 210 | + |
| 211 | + It("should fail to install a cluster extension successfully", func(ctx SpecContext) { |
| 212 | + unique := rand.String(4) |
| 213 | + saName := fmt.Sprintf("install-%s-sa-%s", testPrefix, unique) |
| 214 | + crbName := fmt.Sprintf("install-%s-crb-%s", testPrefix, unique) |
| 215 | + ceName := fmt.Sprintf("install-%s-ce-%s", testPrefix, unique) |
| 216 | + |
| 217 | + By("creating ServiceAccount") |
| 218 | + sa := helpers.NewServiceAccount(saName, namespace) |
| 219 | + Expect(k8sClient.Create(ctx, sa)).To(Succeed(), "failed to create ServiceAccount %q", saName) |
| 220 | + By("ensuring ServiceAccount is available before proceeding") |
| 221 | + helpers.ExpectServiceAccountExists(ctx, saName, namespace) |
| 222 | + By("registering cleanup for ServiceAccount") |
| 223 | + DeferCleanup(func() { |
| 224 | + By(fmt.Sprintf("cleanup: deleting ServiceAccount %s in namespace %s", sa.Name, sa.Namespace)) |
| 225 | + _ = k8sClient.Delete(ctx, sa) |
| 226 | + }) |
| 227 | + |
| 228 | + By("creating ClusterRoleBinding") |
| 229 | + crb := helpers.NewClusterRoleBinding(crbName, "cluster-admin", saName, namespace) |
| 230 | + Expect(k8sClient.Create(ctx, crb)).To(Succeed(), "failed to create ClusterRoleBinding %q", crbName) |
| 231 | + By("ensuring ClusterRoleBinding is available before proceeding") |
| 232 | + helpers.ExpectClusterRoleBindingExists(ctx, crbName) |
| 233 | + By("registering cleanup for ClusterRoleBinding") |
| 234 | + DeferCleanup(func() { |
| 235 | + By(fmt.Sprintf("cleanup: deleting ClusterRoleBinding %s", crb.Name)) |
| 236 | + _ = k8sClient.Delete(ctx, crb) |
| 237 | + }) |
| 238 | + |
| 239 | + By("creating ClusterExtension with the watch-namespace annotation") |
| 240 | + ce := helpers.NewClusterExtensionObject("openshift-pipelines-operator-rh", "1.17.1", ceName, saName, namespace) |
| 241 | + ce.Annotations = map[string]string{ |
| 242 | + "olm.operatorframework.io/watch-namespace": namespace, |
| 243 | + } |
| 244 | + Expect(k8sClient.Create(ctx, ce)).To(Succeed(), "failed to create ClusterExtension %q", ceName) |
| 245 | + By("registering cleanup for ClusterExtension") |
| 246 | + DeferCleanup(func() { |
| 247 | + By(fmt.Sprintf("cleanup: deleting ClusterExtension %s", ce.Name)) |
| 248 | + _ = k8sClient.Delete(ctx, ce) |
| 249 | + }) |
| 250 | + |
| 251 | + By("waiting for the ClusterExtension to fail installation") |
| 252 | + Eventually(func(g Gomega) { |
| 253 | + var ext olmv1.ClusterExtension |
| 254 | + err := k8sClient.Get(ctx, client.ObjectKey{Name: ceName}, &ext) |
| 255 | + g.Expect(err).ToNot(HaveOccurred(), "failed to get ClusterExtension %q", ceName) |
| 256 | + |
| 257 | + conditions := ext.Status.Conditions |
| 258 | + g.Expect(conditions).ToNot(BeEmpty(), "ClusterExtension %q has empty status.conditions", ceName) |
| 259 | + |
| 260 | + installed := meta.FindStatusCondition(conditions, olmv1.TypeInstalled) |
| 261 | + g.Expect(installed).ToNot(BeNil(), "Installed condition not found") |
| 262 | + g.Expect(installed.Status).To(Equal(metav1.ConditionFalse), "Installed should be False") |
| 263 | + g.Expect(installed.Reason).To(Equal("Failed")) |
| 264 | + }).WithTimeout(5 * time.Minute).WithPolling(1 * time.Second).Should(Succeed()) |
| 265 | + }) |
| 266 | +}) |
0 commit comments