@@ -13,7 +13,7 @@ import (
1313 listerv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1alpha1"
1414 "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
1515 "github.com/stretchr/testify/assert"
16- v1 "k8s.io/api/core/v1"
16+ corev1 "k8s.io/api/core/v1"
1717 apiextensionsfake "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/fake"
1818 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1919 "k8s.io/apimachinery/pkg/runtime"
@@ -53,8 +53,7 @@ func init() {
5353 }
5454}
5555
56- func NewFakeCSVNamespaceLabelerPlugin (t * testing.T , options ... fakeClientOption ) (* csvNamespaceLabelerPlugin , context.CancelFunc ) {
57-
56+ func newFakeCSVNamespaceLabelerPlugin (t * testing.T , options ... fakeClientOption ) (* csvNamespaceLabelerPlugin , context.CancelFunc ) {
5857 resyncPeriod := 5 * time .Minute
5958 clientOptions := & fakeClientOptions {}
6059 for _ , applyOption := range options {
@@ -83,9 +82,9 @@ func NewFakeCSVNamespaceLabelerPlugin(t *testing.T, options ...fakeClientOption)
8382 operatorsInformerFactory .Start (stopCtx )
8483
8584 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 )
8786 defer func () {
88- cancel ()
87+ syncCancel ()
8988 }()
9089 if ok := cache .WaitForCacheSync (syncCtx .Done (), namespaceInformer .HasSynced ); ! ok {
9190 t .Fatalf ("failed to wait for namespace caches to sync" )
@@ -122,15 +121,15 @@ func NewCopiedCsvInNamespace(namespace string) *v1alpha1.ClusterServiceVersion {
122121 return csv
123122}
124123
125- func NewNamespace (name string ) * v1 .Namespace {
126- return & v1 .Namespace {
124+ func NewNamespace (name string ) * corev1 .Namespace {
125+ return & corev1 .Namespace {
127126 ObjectMeta : metav1.ObjectMeta {
128127 Name : name ,
129128 },
130129 }
131130}
132131
133- func NewLabeledNamespace (name string , labelValue string ) * v1 .Namespace {
132+ func NewLabeledNamespace (name string , labelValue string ) * corev1 .Namespace {
134133 ns := NewNamespace (name )
135134 ns .SetLabels (map [string ]string {
136135 NamespaceLabelSyncerLabelKey : labelValue ,
@@ -141,7 +140,7 @@ func NewLabeledNamespace(name string, labelValue string) *v1.Namespace {
141140func Test_SyncIgnoresCopiedCsvs (t * testing.T ) {
142141 // Sync ignores copied csvs
143142 namespace := "openshift-test"
144- plugin , shutdown := NewFakeCSVNamespaceLabelerPlugin (t , withK8sResources (NewNamespace (namespace )))
143+ plugin , shutdown := newFakeCSVNamespaceLabelerPlugin (t , withK8sResources (NewNamespace (namespace )))
145144 defer shutdown ()
146145
147146 assert .Nil (t , plugin .Sync (context .Background (), NewCopiedCsvInNamespace (namespace )))
@@ -154,7 +153,7 @@ func Test_SyncIgnoresCopiedCsvs(t *testing.T) {
154153func Test_SyncIgnoresNonOpenshiftNamespaces (t * testing.T ) {
155154 // Sync ignores non-openshift namespaces
156155 namespace := "test-namespace"
157- plugin , shutdown := NewFakeCSVNamespaceLabelerPlugin (t , withK8sResources (NewNamespace (namespace )))
156+ plugin , shutdown := newFakeCSVNamespaceLabelerPlugin (t , withK8sResources (NewNamespace (namespace )))
158157 defer shutdown ()
159158
160159 assert .Nil (t , plugin .Sync (context .Background (), NewCopiedCsvInNamespace (namespace )))
@@ -167,7 +166,7 @@ func Test_SyncIgnoresNonOpenshiftNamespaces(t *testing.T) {
167166func Test_SyncIgnoresPayloadOpenshiftNamespacesExceptOperators (t * testing.T ) {
168167 // Sync ignores payload openshift namespaces, except openshift-operators
169168 // 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" )))
171170 defer shutdown ()
172171
173172 assert .Nil (t , plugin .Sync (context .Background (), NewCsvInNamespace ("openshift-monitoring" )))
@@ -190,7 +189,7 @@ func Test_SyncIgnoresAlreadyLabeledNonPayloadOpenshiftNamespaces(t *testing.T) {
190189
191190 for _ , labelValue := range labelValues {
192191 func () {
193- plugin , shutdown := NewFakeCSVNamespaceLabelerPlugin (t , withK8sResources (NewLabeledNamespace (namespace , labelValue )))
192+ plugin , shutdown := newFakeCSVNamespaceLabelerPlugin (t , withK8sResources (NewLabeledNamespace (namespace , labelValue )))
194193 defer shutdown ()
195194
196195 assert .Nil (t , plugin .Sync (context .Background (), NewCsvInNamespace (namespace )))
@@ -206,7 +205,7 @@ func Test_SyncLabelsNonPayloadUnlabeledOpenshiftNamespaces(t *testing.T) {
206205 // Sync will label non-labeled non-payload openshift- namespaces
207206 namespace := "openshift-test"
208207
209- plugin , shutdown := NewFakeCSVNamespaceLabelerPlugin (t , withK8sResources (NewNamespace (namespace )))
208+ plugin , shutdown := newFakeCSVNamespaceLabelerPlugin (t , withK8sResources (NewNamespace (namespace )))
210209 defer shutdown ()
211210
212211 assert .Nil (t , plugin .Sync (context .Background (), NewCsvInNamespace (namespace )))
@@ -218,15 +217,15 @@ func Test_SyncLabelsNonPayloadUnlabeledOpenshiftNamespaces(t *testing.T) {
218217
219218func Test_SyncFailsIfEventResourceIsNotCSV (t * testing.T ) {
220219 // Sync fails if resource is not a csv\
221- plugin , shutdown := NewFakeCSVNamespaceLabelerPlugin (t )
220+ plugin , shutdown := newFakeCSVNamespaceLabelerPlugin (t )
222221 defer shutdown ()
223222
224- assert .Error (t , plugin .Sync (context .Background (), & v1 .ConfigMap {}))
223+ assert .Error (t , plugin .Sync (context .Background (), & corev1 .ConfigMap {}))
225224}
226225
227226func Test_SyncFailsIfNamespaceNotFound (t * testing.T ) {
228227 // Sync fails if the namespace is not found
229- plugin , shutdown := NewFakeCSVNamespaceLabelerPlugin (t )
228+ plugin , shutdown := newFakeCSVNamespaceLabelerPlugin (t )
230229 defer shutdown ()
231230
232231 assert .Error (t , plugin .Sync (context .Background (), NewCsvInNamespace ("openshift-test" )))
@@ -235,11 +234,11 @@ func Test_SyncFailsIfNamespaceNotFound(t *testing.T) {
235234func Test_SyncFailsIfCSVCannotBeUpdated (t * testing.T ) {
236235 // Sync fails if the namespace cannot be updated
237236 namespace := "openshift-test"
238- plugin , shutdown := NewFakeCSVNamespaceLabelerPlugin (t , withK8sResources (NewNamespace (namespace )))
237+ plugin , shutdown := newFakeCSVNamespaceLabelerPlugin (t , withK8sResources (NewNamespace (namespace )))
239238 defer shutdown ()
240239
241240 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" )
243242 }
244243 plugin .kubeClient .KubernetesInterface ().CoreV1 ().(* v1fake.FakeCoreV1 ).PrependReactor ("update" , "namespaces" , updateNsError )
245244 assert .Error (t , plugin .Sync (context .Background (), NewCsvInNamespace (namespace )))
@@ -251,7 +250,7 @@ func Test_SyncLabelsNamespaceWithCSV(t *testing.T) {
251250 // Sync should apply the label syncer label to the namespace
252251 namespace := NewNamespace ("openshift-test" )
253252 csv := NewCsvInNamespace (namespace .GetName ())
254- plugin , shutdown := NewFakeCSVNamespaceLabelerPlugin (t , withK8sResources (namespace ), withExtendedResources (csv ))
253+ plugin , shutdown := newFakeCSVNamespaceLabelerPlugin (t , withK8sResources (namespace ), withExtendedResources (csv ))
255254 defer shutdown ()
256255
257256 assert .NoError (t , plugin .Sync (context .Background (), namespace ))
@@ -266,7 +265,7 @@ func Test_SyncDoesNotLabelNamespaceWithoutCSVs(t *testing.T) {
266265 // that contains zero non-copied csvs
267266 // Sync should *NOT* apply the label syncer label to the namespace
268267 namespace := NewNamespace ("openshift-test" )
269- plugin , shutdown := NewFakeCSVNamespaceLabelerPlugin (t , withK8sResources (namespace ))
268+ plugin , shutdown := newFakeCSVNamespaceLabelerPlugin (t , withK8sResources (namespace ))
270269 defer shutdown ()
271270
272271 assert .NoError (t , plugin .Sync (context .Background (), namespace ))
@@ -282,7 +281,7 @@ func Test_SyncDoesNotLabelNamespacesWithCopiedCSVs(t *testing.T) {
282281 // Sync should *NOT* apply the label syncer label to the namespace
283282 namespace := NewNamespace ("openshift-test" )
284283 csv := NewCopiedCsvInNamespace (namespace .GetName ())
285- plugin , shutdown := NewFakeCSVNamespaceLabelerPlugin (t , withK8sResources (namespace ), withExtendedResources (csv ))
284+ plugin , shutdown := newFakeCSVNamespaceLabelerPlugin (t , withK8sResources (namespace ), withExtendedResources (csv ))
286285 defer shutdown ()
287286
288287 assert .NoError (t , plugin .Sync (context .Background (), namespace ))
0 commit comments