Skip to content

Commit 0174327

Browse files
UPSTREAM: <carry>: Migrate single/own namespace tests
This commit migrates the OLMv1 single and own namespace watch mode tests from openshift/origin/test/extended/olm/olmv1-singleownnamespace.go to this repository. This is part of the effort to move component-specific tests into their respective downstream locations. Assisted-by: Gemini
1 parent f9bf348 commit 0174327

File tree

2 files changed

+342
-0
lines changed

2 files changed

+342
-0
lines changed

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

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

0 commit comments

Comments
 (0)