@@ -471,6 +471,48 @@ var _ = Describe("Test NetworkPolicy conversion", func() {
471
471
Expect (pol .Value .(* model.Policy ).OutboundRules [0 ]).To (Equal (model.Rule {Action : "allow" }))
472
472
})
473
473
474
+ It ("should parse a NetworkPolicy with an empty namespaceSelector" , func () {
475
+ np := extensions.NetworkPolicy {
476
+ ObjectMeta : metav1.ObjectMeta {
477
+ Name : "testPolicy" ,
478
+ Namespace : "default" ,
479
+ },
480
+ Spec : extensions.NetworkPolicySpec {
481
+ PodSelector : metav1.LabelSelector {
482
+ MatchLabels : map [string ]string {"label" : "value" },
483
+ },
484
+ Ingress : []extensions.NetworkPolicyIngressRule {
485
+ extensions.NetworkPolicyIngressRule {
486
+ From : []extensions.NetworkPolicyPeer {
487
+ extensions.NetworkPolicyPeer {
488
+ NamespaceSelector : & metav1.LabelSelector {
489
+ MatchLabels : map [string ]string {},
490
+ },
491
+ },
492
+ },
493
+ },
494
+ },
495
+ },
496
+ }
497
+
498
+ // Parse the policy.
499
+ pol , err := c .networkPolicyToPolicy (& np )
500
+ Expect (err ).NotTo (HaveOccurred ())
501
+
502
+ // Assert key fields are correct.
503
+ Expect (pol .Key .(model.PolicyKey ).Name ).To (Equal ("np.projectcalico.org/default.testPolicy" ))
504
+
505
+ // Assert value fields are correct.
506
+ Expect (int (* pol .Value .(* model.Policy ).Order )).To (Equal (1000 ))
507
+ Expect (pol .Value .(* model.Policy ).Selector ).To (Equal ("calico/k8s_ns == 'default' && label == 'value'" ))
508
+ Expect (len (pol .Value .(* model.Policy ).InboundRules )).To (Equal (1 ))
509
+ Expect (pol .Value .(* model.Policy ).InboundRules [0 ].SrcSelector ).To (Equal ("has(calico/k8s_ns)" ))
510
+
511
+ // OutboundRules should only have one rule and it should be allow.
512
+ Expect (len (pol .Value .(* model.Policy ).OutboundRules )).To (Equal (1 ))
513
+ Expect (pol .Value .(* model.Policy ).OutboundRules [0 ]).To (Equal (model.Rule {Action : "allow" }))
514
+ })
515
+
474
516
It ("should parse a NetworkPolicy with podSelector.MatchExpressions" , func () {
475
517
np := extensions.NetworkPolicy {
476
518
ObjectMeta : metav1.ObjectMeta {
0 commit comments