Skip to content

Commit 1959dab

Browse files
UPSTREAM: <carry>: Add new tests for single/own namespacess
1 parent 9ff2816 commit 1959dab

File tree

2 files changed

+156
-4
lines changed

2 files changed

+156
-4
lines changed

openshift/tests-extension/.openshift-tests-extension/openshift_payload_olmv1.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,17 @@
430430
},
431431
{
432432
"name": "[sig-olmv1][OCPFeatureGate:NewOLMOwnSingleNamespace][Skipped:Disconnected][Serial] OLMv1 operator installation support for ownNamespace watch mode with quay-operator should install a cluster extension successfully",
433-
"originalName": "[sig-olmv1][OCPFeatureGate:NewOLMOwnSingleNamespace][Skipped:Disconnected] OLMv1 operator installation support for ownNamespace watch mode with quay-operator should install a cluster extension successfully",
434-
"labels": {
435-
"original-name:[sig-olmv1][OCPFeatureGate:NewOLMOwnSingleNamespace][Skipped:Disconnected] OLMv1 operator installation support for ownNamespace watch mode with quay-operator should install a cluster extension successfully": {}
433+
"labels": {},
434+
"resources": {
435+
"isolation": {}
436436
},
437+
"source": "openshift:payload:olmv1",
438+
"lifecycle": "blocking",
439+
"environmentSelector": {}
440+
},
441+
{
442+
"name": "[sig-olmv1][OCPFeatureGate:NewOLMOwnSingleNamespace][Serial] OLMv1 operator installation support for operators supporting both singleNamespace and ownNamespace watch modes with quay-operator should install cluster extensions successfully in both singleNamespace and ownNamespace watch modes",
443+
"labels": {},
437444
"resources": {
438445
"isolation": {}
439446
},

openshift/tests-extension/test/olmv1-singleownnamespace.go

Lines changed: 146 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMOwnSingleNamespace][Skipped:D
161161
})
162162

163163
It("should install a cluster extension successfully",
164-
Label("original-name:[sig-olmv1][OCPFeatureGate:NewOLMOwnSingleNamespace][Skipped:Disconnected] OLMv1 operator installation support for ownNamespace watch mode with quay-operator should install a cluster extension successfully"),
165164
func(ctx SpecContext) {
166165
By("creating ServiceAccount")
167166
sa := helpers.NewServiceAccount(saName, namespace)
@@ -208,6 +207,152 @@ var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMOwnSingleNamespace][Skipped:D
208207
})
209208
})
210209

210+
var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMOwnSingleNamespace][Serial] OLMv1 operator installation support for operators supporting both singleNamespace and ownNamespace watch modes with quay-operator", Ordered, Serial, func() {
211+
var (
212+
k8sClient client.Client
213+
activeNamespaces map[string]struct{}
214+
)
215+
216+
BeforeEach(func() {
217+
By("checking if OpenShift is available for tests")
218+
if !env.Get().IsOpenShift {
219+
Skip("Requires OpenShift for the tests")
220+
}
221+
helpers.RequireOLMv1CapabilityOnOpenshift()
222+
k8sClient = env.Get().K8sClient
223+
activeNamespaces = map[string]struct{}{}
224+
})
225+
226+
AfterEach(func(ctx SpecContext) {
227+
if CurrentSpecReport().Failed() {
228+
for ns := range activeNamespaces {
229+
helpers.DescribeAllClusterExtensions(ctx, ns)
230+
}
231+
}
232+
})
233+
234+
It("should install cluster extensions successfully in both singleNamespace and ownNamespace watch modes",
235+
func(ctx SpecContext) {
236+
scenarios := []struct {
237+
id string
238+
label string
239+
watchN func(string) string
240+
}{
241+
{
242+
id: "singlens",
243+
label: "singleNamespace watch mode",
244+
watchN: func(installNamespace string) string {
245+
return fmt.Sprintf("%s-watch", installNamespace)
246+
},
247+
},
248+
{
249+
id: "ownns",
250+
label: "ownNamespace watch mode",
251+
watchN: func(installNamespace string) string {
252+
return installNamespace
253+
},
254+
},
255+
}
256+
257+
for _, scenario := range scenarios {
258+
sc := scenario
259+
suffix := rand.String(4)
260+
installNamespace := fmt.Sprintf("olmv1-quay-bothns-%s-%s", sc.id, suffix)
261+
watchNamespace := sc.watchN(installNamespace)
262+
263+
activeNamespaces[installNamespace] = struct{}{}
264+
if watchNamespace != installNamespace {
265+
activeNamespaces[watchNamespace] = struct{}{}
266+
}
267+
268+
By(fmt.Sprintf("ensuring no ClusterExtension and CRD for quay-operator before %s scenario", sc.label))
269+
helpers.EnsureCleanupClusterExtension(context.Background(), "quay-operator", "quayregistries.quay.redhat.com")
270+
271+
By(fmt.Sprintf("creating namespace %s for %s tests", installNamespace, sc.label))
272+
installNS := &corev1.Namespace{
273+
ObjectMeta: metav1.ObjectMeta{
274+
Name: installNamespace,
275+
},
276+
}
277+
Expect(k8sClient.Create(ctx, installNS)).To(Succeed(), "failed to create install namespace %q", installNamespace)
278+
installNamespaceCopy := installNamespace
279+
DeferCleanup(func() {
280+
By(fmt.Sprintf("cleanup: deleting install namespace %s", installNamespaceCopy))
281+
_ = k8sClient.Delete(context.Background(), &corev1.Namespace{
282+
ObjectMeta: metav1.ObjectMeta{Name: installNamespaceCopy},
283+
}, client.PropagationPolicy(metav1.DeletePropagationForeground))
284+
})
285+
286+
var watchNSObj *corev1.Namespace
287+
if watchNamespace != installNamespace {
288+
By(fmt.Sprintf("creating namespace %s for watch namespace in %s scenario", watchNamespace, sc.label))
289+
watchNSObj = &corev1.Namespace{
290+
ObjectMeta: metav1.ObjectMeta{Name: watchNamespace},
291+
}
292+
Expect(k8sClient.Create(ctx, watchNSObj)).To(Succeed(), "failed to create watch namespace %q", watchNamespace)
293+
watchNamespaceCopy := watchNamespace
294+
DeferCleanup(func() {
295+
By(fmt.Sprintf("cleanup: deleting watch namespace %s", watchNamespaceCopy))
296+
_ = k8sClient.Delete(context.Background(), &corev1.Namespace{
297+
ObjectMeta: metav1.ObjectMeta{Name: watchNamespaceCopy},
298+
}, client.PropagationPolicy(metav1.DeletePropagationForeground))
299+
})
300+
}
301+
302+
saName := fmt.Sprintf("install-quay-bothns-%s-sa-%s", sc.id, suffix)
303+
By(fmt.Sprintf("creating ServiceAccount %s for %s scenario", saName, sc.label))
304+
sa := helpers.NewServiceAccount(saName, installNamespace)
305+
Expect(k8sClient.Create(ctx, sa)).To(Succeed(), "failed to create ServiceAccount %q", saName)
306+
helpers.ExpectServiceAccountExists(ctx, saName, installNamespace)
307+
DeferCleanup(func() {
308+
By(fmt.Sprintf("cleanup: deleting ServiceAccount %s in namespace %s", sa.Name, sa.Namespace))
309+
_ = k8sClient.Delete(context.Background(), sa, client.PropagationPolicy(metav1.DeletePropagationForeground))
310+
})
311+
312+
crbName := fmt.Sprintf("install-quay-bothns-%s-crb-%s", sc.id, suffix)
313+
By(fmt.Sprintf("creating ClusterRoleBinding %s for %s scenario", crbName, sc.label))
314+
crb := helpers.NewClusterRoleBinding(crbName, "cluster-admin", saName, installNamespace)
315+
Expect(k8sClient.Create(ctx, crb)).To(Succeed(), "failed to create ClusterRoleBinding %q", crbName)
316+
helpers.ExpectClusterRoleBindingExists(ctx, crbName)
317+
DeferCleanup(func() {
318+
By(fmt.Sprintf("cleanup: deleting ClusterRoleBinding %s", crb.Name))
319+
_ = k8sClient.Delete(context.Background(), crb, client.PropagationPolicy(metav1.DeletePropagationForeground))
320+
})
321+
322+
ceName := fmt.Sprintf("install-quay-bothns-%s-ce-%s", sc.id, suffix)
323+
By(fmt.Sprintf("creating ClusterExtension %s for %s scenario", ceName, sc.label))
324+
ce := helpers.NewClusterExtensionObject("quay-operator", "3.14.2", ceName, saName, installNamespace)
325+
ce.Spec.Config = &olmv1.ClusterExtensionConfig{
326+
ConfigType: olmv1.ClusterExtensionConfigTypeInline,
327+
Inline: &apiextensionsv1.JSON{
328+
Raw: []byte(fmt.Sprintf(`{"watchNamespace": "%s"}`, watchNamespace)),
329+
},
330+
}
331+
Expect(k8sClient.Create(ctx, ce)).To(Succeed(), "failed to create ClusterExtension %q", ceName)
332+
DeferCleanup(func() {
333+
By(fmt.Sprintf("cleanup: deleting ClusterExtension %s", ce.Name))
334+
_ = k8sClient.Delete(context.Background(), ce, client.PropagationPolicy(metav1.DeletePropagationForeground))
335+
})
336+
337+
By(fmt.Sprintf("waiting for the ClusterExtension %s to be installed for %s scenario", ceName, sc.label))
338+
helpers.ExpectClusterExtensionToBeInstalled(ctx, ceName)
339+
340+
By(fmt.Sprintf("cleaning up resources created for %s scenario to allow next scenario", sc.label))
341+
deletePolicy := metav1.DeletePropagationForeground
342+
Expect(k8sClient.Delete(ctx, ce, client.PropagationPolicy(deletePolicy))).To(Succeed(), "failed to delete ClusterExtension %q", ceName)
343+
helpers.EnsureCleanupClusterExtension(context.Background(), "quay-operator", "quayregistries.quay.redhat.com")
344+
345+
Expect(k8sClient.Delete(ctx, crb, client.PropagationPolicy(deletePolicy))).To(Succeed(), "failed to delete ClusterRoleBinding %q", crbName)
346+
Expect(k8sClient.Delete(ctx, sa, client.PropagationPolicy(deletePolicy))).To(Succeed(), "failed to delete ServiceAccount %q", saName)
347+
348+
if watchNSObj != nil {
349+
Expect(k8sClient.Delete(ctx, watchNSObj, client.PropagationPolicy(deletePolicy))).To(Succeed(), "failed to delete watch namespace %q", watchNamespace)
350+
}
351+
Expect(k8sClient.Delete(ctx, installNS, client.PropagationPolicy(deletePolicy))).To(Succeed(), "failed to delete install namespace %q", installNamespace)
352+
}
353+
})
354+
})
355+
211356
var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMOwnSingleNamespace][Skipped:Disconnected][Serial] OLMv1 operator installation support for ownNamespace watch mode with an operator that does not support ownNamespace installation mode", Ordered, Serial, func() {
212357
var (
213358
k8sClient client.Client

0 commit comments

Comments
 (0)