Skip to content

Commit 80bdf3d

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

File tree

2 files changed

+156
-0
lines changed

2 files changed

+156
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,16 @@
441441
"lifecycle": "blocking",
442442
"environmentSelector": {}
443443
},
444+
{
445+
"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",
446+
"labels": {},
447+
"resources": {
448+
"isolation": {}
449+
},
450+
"source": "openshift:payload:olmv1",
451+
"lifecycle": "blocking",
452+
"environmentSelector": {}
453+
},
444454
{
445455
"name": "[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 should fail to install a cluster extension successfully",
446456
"originalName": "[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",

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

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,152 @@ var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMOwnSingleNamespace][Skipped:D
208208
})
209209
})
210210

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

0 commit comments

Comments
 (0)