@@ -12,6 +12,7 @@ import (
12
12
"github.com/sirupsen/logrus"
13
13
"github.com/stretchr/testify/require"
14
14
corev1 "k8s.io/api/core/v1"
15
+ networkingv1 "k8s.io/api/networking/v1"
15
16
rbacv1 "k8s.io/api/rbac/v1"
16
17
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
17
18
"k8s.io/apimachinery/pkg/api/meta"
@@ -83,6 +84,7 @@ func fakeReconcilerFactory(t *testing.T, stopc <-chan struct{}, options ...fakeR
83
84
serviceInformer := informerFactory .Core ().V1 ().Services ()
84
85
podInformer := informerFactory .Core ().V1 ().Pods ()
85
86
configMapInformer := informerFactory .Core ().V1 ().ConfigMaps ()
87
+ networkPolicyInformer := informerFactory .Networking ().V1 ().NetworkPolicies ()
86
88
87
89
registryInformers := []cache.SharedIndexInformer {
88
90
roleInformer .Informer (),
@@ -91,6 +93,7 @@ func fakeReconcilerFactory(t *testing.T, stopc <-chan struct{}, options ...fakeR
91
93
serviceInformer .Informer (),
92
94
podInformer .Informer (),
93
95
configMapInformer .Informer (),
96
+ networkPolicyInformer .Informer (),
94
97
}
95
98
96
99
lister := operatorlister .NewLister ()
@@ -100,6 +103,7 @@ func fakeReconcilerFactory(t *testing.T, stopc <-chan struct{}, options ...fakeR
100
103
lister .CoreV1 ().RegisterServiceLister (testNamespace , serviceInformer .Lister ())
101
104
lister .CoreV1 ().RegisterPodLister (testNamespace , podInformer .Lister ())
102
105
lister .CoreV1 ().RegisterConfigMapLister (testNamespace , configMapInformer .Lister ())
106
+ lister .NetworkingV1 ().RegisterNetworkPolicyLister (testNamespace , networkPolicyInformer .Lister ())
103
107
104
108
rec := & registryReconcilerFactory {
105
109
now : config .now ,
@@ -195,6 +199,7 @@ func objectsForCatalogSource(t *testing.T, catsrc *v1alpha1.CatalogSource) []run
195
199
switch catsrc .Spec .SourceType {
196
200
case v1alpha1 .SourceTypeInternal , v1alpha1 .SourceTypeConfigmap :
197
201
decorated := configMapCatalogSourceDecorator {catsrc , runAsUser }
202
+ np := decorated .NetworkPolicy ()
198
203
service , err := decorated .Service ()
199
204
if err != nil {
200
205
t .Fatal (err )
@@ -205,13 +210,15 @@ func objectsForCatalogSource(t *testing.T, catsrc *v1alpha1.CatalogSource) []run
205
210
t .Fatal (err )
206
211
}
207
212
objs = append (objs ,
213
+ np ,
208
214
pod ,
209
215
service ,
210
216
serviceAccount ,
211
217
)
212
218
case v1alpha1 .SourceTypeGrpc :
213
219
if catsrc .Spec .Image != "" {
214
220
decorated := grpcCatalogSourceDecorator {CatalogSource : catsrc , createPodAsUser : runAsUser , opmImage : "" }
221
+ np := decorated .NetworkPolicy ()
215
222
serviceAccount := decorated .ServiceAccount ()
216
223
service , err := decorated .Service ()
217
224
if err != nil {
@@ -222,6 +229,7 @@ func objectsForCatalogSource(t *testing.T, catsrc *v1alpha1.CatalogSource) []run
222
229
t .Fatal (err )
223
230
}
224
231
objs = append (objs ,
232
+ np ,
225
233
pod ,
226
234
service ,
227
235
serviceAccount ,
@@ -342,6 +350,24 @@ func TestConfigMapRegistryReconciler(t *testing.T) {
342
350
},
343
351
},
344
352
},
353
+ {
354
+ testName : "ExistingRegistry/BadNetworkPolicy" ,
355
+ in : in {
356
+ cluster : cluster {
357
+ k8sObjs : append (setLabel (objectsForCatalogSource (t , validCatalogSource ), & networkingv1.NetworkPolicy {}, CatalogSourceLabelKey , "wrongValue" ), validConfigMap ),
358
+ },
359
+ catsrc : validCatalogSource ,
360
+ },
361
+ out : out {
362
+ status : & v1alpha1.RegistryServiceStatus {
363
+ CreatedAt : now (),
364
+ Protocol : "grpc" ,
365
+ ServiceName : "cool-catalog" ,
366
+ ServiceNamespace : testNamespace ,
367
+ Port : "50051" ,
368
+ },
369
+ },
370
+ },
345
371
{
346
372
testName : "ExistingRegistry/BadServiceAccount" ,
347
373
in : in {
@@ -504,6 +530,11 @@ func TestConfigMapRegistryReconciler(t *testing.T) {
504
530
require .Equal (t , pod .GetLabels (), outPod .GetLabels ())
505
531
require .Equal (t , pod .Spec , outPod .Spec )
506
532
533
+ np := decorated .NetworkPolicy ()
534
+ outNp , err := client .KubernetesInterface ().NetworkingV1 ().NetworkPolicies (np .GetNamespace ()).Get (context .TODO (), np .GetName (), metav1.GetOptions {})
535
+ require .NoError (t , err )
536
+ require .Equal (t , np , outNp )
537
+
507
538
service , err := decorated .Service ()
508
539
require .NoError (t , err )
509
540
outService , err := client .KubernetesInterface ().CoreV1 ().Services (service .GetNamespace ()).Get (context .TODO (), service .GetName (), metav1.GetOptions {})
0 commit comments