@@ -183,12 +183,14 @@ func (c *Controller) handleUpdateNp(key string) error {
183183 }
184184
185185 for _ , protocol := range protocolSet .List () {
186- defaultBlockExceptions , err := c .OVNNbClient .UpdateDefaultBlockExceptionsACLOps (npName , pgName , np .Namespace , ovnnb .ACLDirectionToLport , protocol )
187- if err != nil {
188- klog .Errorf ("failed to set default block exceptions for ingress acl: %v" , err )
189- return fmt .Errorf ("failed to set default block exceptions for ingress acl: %w" , err )
186+ if isNetworkPolicyEnforcementLax (np ) {
187+ defaultBlockExceptions , err := c .OVNNbClient .UpdateDefaultBlockExceptionsACLOps (npName , pgName , np .Namespace , ovnnb .ACLDirectionToLport , protocol )
188+ if err != nil {
189+ klog .Errorf ("failed to set default block exceptions for ingress acl: %v" , err )
190+ return fmt .Errorf ("failed to set default block exceptions for ingress acl: %w" , err )
191+ }
192+ ingressACLOps = append (ingressACLOps , defaultBlockExceptions ... )
190193 }
191- ingressACLOps = append (ingressACLOps , defaultBlockExceptions ... )
192194
193195 for idx , npr := range np .Spec .Ingress {
194196 // A single address set must contain addresses of the same type and the name must be unique within table, so IPv4 and IPv6 address set should be different
@@ -328,12 +330,14 @@ func (c *Controller) handleUpdateNp(key string) error {
328330 }
329331
330332 for _ , protocol := range protocolSet .List () {
331- defaultBlockExceptions , err := c .OVNNbClient .UpdateDefaultBlockExceptionsACLOps (npName , pgName , np .Namespace , ovnnb .ACLDirectionFromLport , protocol )
332- if err != nil {
333- klog .Errorf ("failed to set default block exceptions for ingress acl: %v" , err )
334- return fmt .Errorf ("failed to set default block exceptions for ingress acl: %w" , err )
333+ if isNetworkPolicyEnforcementLax (np ) {
334+ defaultBlockExceptions , err := c .OVNNbClient .UpdateDefaultBlockExceptionsACLOps (npName , pgName , np .Namespace , ovnnb .ACLDirectionFromLport , protocol )
335+ if err != nil {
336+ klog .Errorf ("failed to set default block exceptions for ingress acl: %v" , err )
337+ return fmt .Errorf ("failed to set default block exceptions for ingress acl: %w" , err )
338+ }
339+ egressACLOps = append (egressACLOps , defaultBlockExceptions ... )
335340 }
336- egressACLOps = append (egressACLOps , defaultBlockExceptions ... )
337341
338342 for idx , npr := range np .Spec .Egress {
339343 // A single address set must contain addresses of the same type and the name must be unique within table, so IPv4 and IPv6 address set should be different
@@ -808,3 +812,12 @@ func isNamespaceMatchNetworkPolicy(ns *corev1.Namespace, policy *netv1.NetworkPo
808812 }
809813 return false
810814}
815+
816+ func isNetworkPolicyEnforcementLax (policy * netv1.NetworkPolicy ) bool {
817+ // User provided a custom enforcement through annotations
818+ if value , ok := policy .Annotations [util .NetworkPolicyEnforcementAnnotation ]; ok {
819+ return value == "lax"
820+ }
821+
822+ return false
823+ }
0 commit comments