@@ -13,7 +13,7 @@ import (
13
13
listerv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1alpha1"
14
14
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
15
15
"github.com/stretchr/testify/assert"
16
- v1 "k8s.io/api/core/v1"
16
+ corev1 "k8s.io/api/core/v1"
17
17
apiextensionsfake "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/fake"
18
18
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
19
19
"k8s.io/apimachinery/pkg/runtime"
@@ -53,8 +53,7 @@ func init() {
53
53
}
54
54
}
55
55
56
- func NewFakeCSVNamespaceLabelerPlugin (t * testing.T , options ... fakeClientOption ) (* csvNamespaceLabelerPlugin , context.CancelFunc ) {
57
-
56
+ func newFakeCSVNamespaceLabelerPlugin (t * testing.T , options ... fakeClientOption ) (* csvNamespaceLabelerPlugin , context.CancelFunc ) {
58
57
resyncPeriod := 5 * time .Minute
59
58
clientOptions := & fakeClientOptions {}
60
59
for _ , applyOption := range options {
@@ -83,9 +82,9 @@ func NewFakeCSVNamespaceLabelerPlugin(t *testing.T, options ...fakeClientOption)
83
82
operatorsInformerFactory .Start (stopCtx )
84
83
85
84
t .Log ("waiting for informers to sync" )
86
- syncCtx , cancel := context .WithTimeout (ctx , 10 * time .Second )
85
+ syncCtx , syncCancel := context .WithTimeout (ctx , 10 * time .Second )
87
86
defer func () {
88
- cancel ()
87
+ syncCancel ()
89
88
}()
90
89
if ok := cache .WaitForCacheSync (syncCtx .Done (), namespaceInformer .HasSynced ); ! ok {
91
90
t .Fatalf ("failed to wait for namespace caches to sync" )
@@ -122,15 +121,15 @@ func NewCopiedCsvInNamespace(namespace string) *v1alpha1.ClusterServiceVersion {
122
121
return csv
123
122
}
124
123
125
- func NewNamespace (name string ) * v1 .Namespace {
126
- return & v1 .Namespace {
124
+ func NewNamespace (name string ) * corev1 .Namespace {
125
+ return & corev1 .Namespace {
127
126
ObjectMeta : metav1.ObjectMeta {
128
127
Name : name ,
129
128
},
130
129
}
131
130
}
132
131
133
- func NewLabeledNamespace (name string , labelValue string ) * v1 .Namespace {
132
+ func NewLabeledNamespace (name string , labelValue string ) * corev1 .Namespace {
134
133
ns := NewNamespace (name )
135
134
ns .SetLabels (map [string ]string {
136
135
NamespaceLabelSyncerLabelKey : labelValue ,
@@ -141,7 +140,7 @@ func NewLabeledNamespace(name string, labelValue string) *v1.Namespace {
141
140
func Test_SyncIgnoresCopiedCsvs (t * testing.T ) {
142
141
// Sync ignores copied csvs
143
142
namespace := "openshift-test"
144
- plugin , shutdown := NewFakeCSVNamespaceLabelerPlugin (t , withK8sResources (NewNamespace (namespace )))
143
+ plugin , shutdown := newFakeCSVNamespaceLabelerPlugin (t , withK8sResources (NewNamespace (namespace )))
145
144
defer shutdown ()
146
145
147
146
assert .Nil (t , plugin .Sync (context .Background (), NewCopiedCsvInNamespace (namespace )))
@@ -154,7 +153,7 @@ func Test_SyncIgnoresCopiedCsvs(t *testing.T) {
154
153
func Test_SyncIgnoresNonOpenshiftNamespaces (t * testing.T ) {
155
154
// Sync ignores non-openshift namespaces
156
155
namespace := "test-namespace"
157
- plugin , shutdown := NewFakeCSVNamespaceLabelerPlugin (t , withK8sResources (NewNamespace (namespace )))
156
+ plugin , shutdown := newFakeCSVNamespaceLabelerPlugin (t , withK8sResources (NewNamespace (namespace )))
158
157
defer shutdown ()
159
158
160
159
assert .Nil (t , plugin .Sync (context .Background (), NewCopiedCsvInNamespace (namespace )))
@@ -167,7 +166,7 @@ func Test_SyncIgnoresNonOpenshiftNamespaces(t *testing.T) {
167
166
func Test_SyncIgnoresPayloadOpenshiftNamespacesExceptOperators (t * testing.T ) {
168
167
// Sync ignores payload openshift namespaces, except openshift-operators
169
168
// openshift-monitoring sync -> no label
170
- plugin , shutdown := NewFakeCSVNamespaceLabelerPlugin (t , withK8sResources (NewNamespace ("openshift-monitoring" ), NewNamespace ("openshift-operators" )))
169
+ plugin , shutdown := newFakeCSVNamespaceLabelerPlugin (t , withK8sResources (NewNamespace ("openshift-monitoring" ), NewNamespace ("openshift-operators" )))
171
170
defer shutdown ()
172
171
173
172
assert .Nil (t , plugin .Sync (context .Background (), NewCsvInNamespace ("openshift-monitoring" )))
@@ -190,7 +189,7 @@ func Test_SyncIgnoresAlreadyLabeledNonPayloadOpenshiftNamespaces(t *testing.T) {
190
189
191
190
for _ , labelValue := range labelValues {
192
191
func () {
193
- plugin , shutdown := NewFakeCSVNamespaceLabelerPlugin (t , withK8sResources (NewLabeledNamespace (namespace , labelValue )))
192
+ plugin , shutdown := newFakeCSVNamespaceLabelerPlugin (t , withK8sResources (NewLabeledNamespace (namespace , labelValue )))
194
193
defer shutdown ()
195
194
196
195
assert .Nil (t , plugin .Sync (context .Background (), NewCsvInNamespace (namespace )))
@@ -206,7 +205,7 @@ func Test_SyncLabelsNonPayloadUnlabeledOpenshiftNamespaces(t *testing.T) {
206
205
// Sync will label non-labeled non-payload openshift- namespaces
207
206
namespace := "openshift-test"
208
207
209
- plugin , shutdown := NewFakeCSVNamespaceLabelerPlugin (t , withK8sResources (NewNamespace (namespace )))
208
+ plugin , shutdown := newFakeCSVNamespaceLabelerPlugin (t , withK8sResources (NewNamespace (namespace )))
210
209
defer shutdown ()
211
210
212
211
assert .Nil (t , plugin .Sync (context .Background (), NewCsvInNamespace (namespace )))
@@ -218,15 +217,15 @@ func Test_SyncLabelsNonPayloadUnlabeledOpenshiftNamespaces(t *testing.T) {
218
217
219
218
func Test_SyncFailsIfEventResourceIsNotCSV (t * testing.T ) {
220
219
// Sync fails if resource is not a csv\
221
- plugin , shutdown := NewFakeCSVNamespaceLabelerPlugin (t )
220
+ plugin , shutdown := newFakeCSVNamespaceLabelerPlugin (t )
222
221
defer shutdown ()
223
222
224
- assert .Error (t , plugin .Sync (context .Background (), & v1 .ConfigMap {}))
223
+ assert .Error (t , plugin .Sync (context .Background (), & corev1 .ConfigMap {}))
225
224
}
226
225
227
226
func Test_SyncFailsIfNamespaceNotFound (t * testing.T ) {
228
227
// Sync fails if the namespace is not found
229
- plugin , shutdown := NewFakeCSVNamespaceLabelerPlugin (t )
228
+ plugin , shutdown := newFakeCSVNamespaceLabelerPlugin (t )
230
229
defer shutdown ()
231
230
232
231
assert .Error (t , plugin .Sync (context .Background (), NewCsvInNamespace ("openshift-test" )))
@@ -235,11 +234,11 @@ func Test_SyncFailsIfNamespaceNotFound(t *testing.T) {
235
234
func Test_SyncFailsIfCSVCannotBeUpdated (t * testing.T ) {
236
235
// Sync fails if the namespace cannot be updated
237
236
namespace := "openshift-test"
238
- plugin , shutdown := NewFakeCSVNamespaceLabelerPlugin (t , withK8sResources (NewNamespace (namespace )))
237
+ plugin , shutdown := newFakeCSVNamespaceLabelerPlugin (t , withK8sResources (NewNamespace (namespace )))
239
238
defer shutdown ()
240
239
241
240
updateNsError := func (action clienttesting.Action ) (handled bool , ret runtime.Object , err error ) {
242
- return true , & v1 .Namespace {}, errors .New ("error updating namespace" )
241
+ return true , & corev1 .Namespace {}, errors .New ("error updating namespace" )
243
242
}
244
243
plugin .kubeClient .KubernetesInterface ().CoreV1 ().(* v1fake.FakeCoreV1 ).PrependReactor ("update" , "namespaces" , updateNsError )
245
244
assert .Error (t , plugin .Sync (context .Background (), NewCsvInNamespace (namespace )))
@@ -251,7 +250,7 @@ func Test_SyncLabelsNamespaceWithCSV(t *testing.T) {
251
250
// Sync should apply the label syncer label to the namespace
252
251
namespace := NewNamespace ("openshift-test" )
253
252
csv := NewCsvInNamespace (namespace .GetName ())
254
- plugin , shutdown := NewFakeCSVNamespaceLabelerPlugin (t , withK8sResources (namespace ), withExtendedResources (csv ))
253
+ plugin , shutdown := newFakeCSVNamespaceLabelerPlugin (t , withK8sResources (namespace ), withExtendedResources (csv ))
255
254
defer shutdown ()
256
255
257
256
assert .NoError (t , plugin .Sync (context .Background (), namespace ))
@@ -266,7 +265,7 @@ func Test_SyncDoesNotLabelNamespaceWithoutCSVs(t *testing.T) {
266
265
// that contains zero non-copied csvs
267
266
// Sync should *NOT* apply the label syncer label to the namespace
268
267
namespace := NewNamespace ("openshift-test" )
269
- plugin , shutdown := NewFakeCSVNamespaceLabelerPlugin (t , withK8sResources (namespace ))
268
+ plugin , shutdown := newFakeCSVNamespaceLabelerPlugin (t , withK8sResources (namespace ))
270
269
defer shutdown ()
271
270
272
271
assert .NoError (t , plugin .Sync (context .Background (), namespace ))
@@ -282,7 +281,7 @@ func Test_SyncDoesNotLabelNamespacesWithCopiedCSVs(t *testing.T) {
282
281
// Sync should *NOT* apply the label syncer label to the namespace
283
282
namespace := NewNamespace ("openshift-test" )
284
283
csv := NewCopiedCsvInNamespace (namespace .GetName ())
285
- plugin , shutdown := NewFakeCSVNamespaceLabelerPlugin (t , withK8sResources (namespace ), withExtendedResources (csv ))
284
+ plugin , shutdown := newFakeCSVNamespaceLabelerPlugin (t , withK8sResources (namespace ), withExtendedResources (csv ))
286
285
defer shutdown ()
287
286
288
287
assert .NoError (t , plugin .Sync (context .Background (), namespace ))
0 commit comments