@@ -3,12 +3,14 @@ package e2e
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "os"
6
7
"time"
7
8
8
9
. "github.com/onsi/ginkgo/v2"
9
10
. "github.com/onsi/gomega"
10
11
"github.com/onsi/gomega/format"
11
12
gomegatypes "github.com/onsi/gomega/types"
13
+ "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
12
14
corev1 "k8s.io/api/core/v1"
13
15
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
14
16
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -74,6 +76,7 @@ var _ = Describe("Operator API", func() {
74
76
It ("should surface components in its status" , func () {
75
77
o := & operatorsv1.Operator {}
76
78
o .SetName (genName ("o-" ))
79
+ By (fmt .Sprintf ("Creating an Operator resource %s" , o .GetName ()))
77
80
78
81
Consistently (o ).ShouldNot (ContainCopiedCSVReferences ())
79
82
@@ -83,6 +86,10 @@ var _ = Describe("Operator API", func() {
83
86
84
87
defer func () {
85
88
Eventually (func () error {
89
+ if env := os .Getenv ("SKIP_CLEANUP" ); env != "" {
90
+ fmt .Printf ("Skipping cleanup of operator %s...\n " , o .GetName ())
91
+ return nil
92
+ }
86
93
err := client .Delete (clientCtx , o )
87
94
if apierrors .IsNotFound (err ) {
88
95
return nil
@@ -116,18 +123,22 @@ var _ = Describe("Operator API", func() {
116
123
}))
117
124
defer w .Stop ()
118
125
119
- // Create namespaces ns-a and ns-b
120
126
nsA := & corev1.Namespace {}
121
127
nsA .SetName (genName ("ns-a-" ))
122
128
nsB := & corev1.Namespace {}
123
129
nsB .SetName (genName ("ns-b-" ))
130
+ By (fmt .Sprintf ("Create namespaces ns-a: (%s) and ns-b: (%s)" , nsA .GetName (), nsB .GetName ()))
124
131
125
132
for _ , ns := range []* corev1.Namespace {nsA , nsB } {
126
133
Eventually (func () error {
127
134
return client .Create (clientCtx , ns )
128
135
}).Should (Succeed ())
129
136
130
137
defer func (n * corev1.Namespace ) {
138
+ if env := os .Getenv ("SKIP_CLEANUP" ); env != "" {
139
+ fmt .Printf ("Skipping cleanup of namespace %s...\n " , n .GetName ())
140
+ return
141
+ }
131
142
Eventually (func () error {
132
143
err := client .Delete (clientCtx , n )
133
144
if apierrors .IsNotFound (err ) {
@@ -138,31 +149,38 @@ var _ = Describe("Operator API", func() {
138
149
}(ns )
139
150
}
140
151
141
- // Label ns-a with o's component label
152
+ By ( fmt . Sprintf ( " Label ns-a (%s) with o's (%s) component label (%s)" , nsA . GetName (), o . GetName (), expectedKey ))
142
153
setComponentLabel := func (m metav1.Object ) error {
143
- m .SetLabels (map [string ]string {expectedKey : "" })
154
+ m .SetLabels (map [string ]string {
155
+ install .OLMManagedLabelKey : install .OLMManagedLabelValue ,
156
+ expectedKey : "" ,
157
+ })
144
158
return nil
145
159
}
146
160
Eventually (Apply (nsA , setComponentLabel )).Should (Succeed ())
147
161
148
- // Ensure o's status.components.refs field eventually contains a reference to ns-a
162
+ By ( " Ensure o's status.components.refs field eventually contains a reference to ns-a" )
149
163
By ("eventually listing a single component reference" )
150
164
componentRefEventuallyExists (w , true , getReference (scheme , nsA ))
151
165
152
- // Create ServiceAccounts sa-a and sa-b in namespaces ns-a and ns-b respectively
153
166
saA := & corev1.ServiceAccount {}
154
167
saA .SetName (genName ("sa-a-" ))
155
168
saA .SetNamespace (nsA .GetName ())
156
169
saB := & corev1.ServiceAccount {}
157
170
saB .SetName (genName ("sa-b-" ))
158
171
saB .SetNamespace (nsB .GetName ())
172
+ By (fmt .Sprintf ("Create ServiceAccounts sa-a (%s/%s) and sa-b (%s/%s) in namespaces ns-a and ns-b respectively" , saA .GetNamespace (), saA .GetName (), saB .GetNamespace (), saB .GetName ()))
159
173
160
174
for _ , sa := range []* corev1.ServiceAccount {saA , saB } {
161
175
Eventually (func () error {
162
176
return client .Create (clientCtx , sa )
163
177
}).Should (Succeed ())
164
178
defer func (sa * corev1.ServiceAccount ) {
165
179
Eventually (func () error {
180
+ if env := os .Getenv ("SKIP_CLEANUP" ); env != "" {
181
+ fmt .Printf ("Skipping cleanup of serviceaccount %s/%s...\n " , sa .GetNamespace (), sa .GetName ())
182
+ return nil
183
+ }
166
184
err := client .Delete (clientCtx , sa )
167
185
if apierrors .IsNotFound (err ) {
168
186
return nil
@@ -172,26 +190,26 @@ var _ = Describe("Operator API", func() {
172
190
}(sa )
173
191
}
174
192
175
- // Label sa-a and sa-b with o's component label
193
+ By ( " Label sa-a and sa-b with o's component label" )
176
194
Eventually (Apply (saA , setComponentLabel )).Should (Succeed ())
177
195
Eventually (Apply (saB , setComponentLabel )).Should (Succeed ())
178
196
179
- // Ensure o's status.components.refs field eventually contains references to sa-a and sa-b
197
+ By ( " Ensure o's status.components.refs field eventually contains references to sa-a and sa-b" )
180
198
By ("eventually listing multiple component references" )
181
199
componentRefEventuallyExists (w , true , getReference (scheme , saA ))
182
200
componentRefEventuallyExists (w , true , getReference (scheme , saB ))
183
201
184
- // Remove the component label from sa-b
202
+ By ( " Remove the component label from sa-b" )
185
203
Eventually (Apply (saB , func (m metav1.Object ) error {
186
204
m .SetLabels (nil )
187
205
return nil
188
206
})).Should (Succeed ())
189
207
190
- // Ensure the reference to sa-b is eventually removed from o's status.components.refs field
208
+ By ( " Ensure the reference to sa-b is eventually removed from o's status.components.refs field" )
191
209
By ("removing a component's reference when it no longer bears the component label" )
192
210
componentRefEventuallyExists (w , false , getReference (scheme , saB ))
193
211
194
- // Delete o
212
+ By ( " Delete o" )
195
213
Eventually (func () error {
196
214
err := client .Delete (clientCtx , o )
197
215
if err != nil && ! apierrors .IsNotFound (err ) {
@@ -200,13 +218,13 @@ var _ = Describe("Operator API", func() {
200
218
return nil
201
219
}).Should (Succeed ())
202
220
203
- // Ensure that o is eventually recreated (because some of its components still exist).
221
+ By ( " Ensure that o is eventually recreated (because some of its components still exist)." )
204
222
By ("recreating the Operator when any components still exist" )
205
223
Eventually (func () error {
206
224
return client .Get (clientCtx , types.NamespacedName {Name : o .GetName ()}, o )
207
225
}).Should (Succeed ())
208
226
209
- // Delete ns-a
227
+ By ( " Delete ns-a" )
210
228
Eventually (func () error {
211
229
err := client .Delete (clientCtx , nsA )
212
230
if apierrors .IsNotFound (err ) {
@@ -215,11 +233,11 @@ var _ = Describe("Operator API", func() {
215
233
return err
216
234
}).Should (Succeed ())
217
235
218
- // Ensure the reference to ns-a is eventually removed from o's status.components.refs field
236
+ By ( " Ensure the reference to ns-a is eventually removed from o's status.components.refs field" )
219
237
By ("removing a component's reference when it no longer exists" )
220
238
componentRefEventuallyExists (w , false , getReference (scheme , nsA ))
221
239
222
- // Delete o
240
+ By ( " Delete o" )
223
241
Eventually (func () error {
224
242
err := client .Delete (clientCtx , o )
225
243
if apierrors .IsNotFound (err ) {
@@ -228,7 +246,7 @@ var _ = Describe("Operator API", func() {
228
246
return err
229
247
}).Should (Succeed ())
230
248
231
- // Ensure that o is consistently not found
249
+ By ( " Ensure that o is consistently not found" )
232
250
By ("verifying the Operator is permanently deleted if it has no components" )
233
251
Consistently (func () error {
234
252
err := client .Get (clientCtx , types.NamespacedName {Name : o .GetName ()}, o )
0 commit comments