@@ -349,7 +349,7 @@ func peerAndPortRule(npmNetPol *policies.NPMNetworkPolicy, direction policies.Di
349349 return err
350350 }
351351
352- err = checkForNamedPortType (portKind , npmLiteToggle )
352+ err = checkForNamedPortType (npmNetPol , portKind , npmLiteToggle , direction , & ports [ i ], "" )
353353 if err != nil {
354354 return err
355355 }
@@ -381,7 +381,7 @@ func directPeerAndPortAllowRule(npmNetPol *policies.NPMNetworkPolicy, direction
381381 return err
382382 }
383383
384- err = checkForNamedPortType (portKind , npmLiteToggle )
384+ err = checkForNamedPortType (npmNetPol , portKind , npmLiteToggle , direction , & ports [ i ], cidr )
385385 if err != nil {
386386 return err
387387 }
@@ -396,10 +396,6 @@ func directPeerAndPortAllowRule(npmNetPol *policies.NPMNetworkPolicy, direction
396396 }
397397
398398 // Handle ports
399- if portKind == namedPortType {
400- return fmt .Errorf ("named port not supported in policy %s (namespace: %s, direction: %s, cidr: %s, port: %v): %w" ,
401- npmNetPol .PolicyKey , npmNetPol .Namespace , direction , cidr , ports [i ].Port , ErrUnsupportedNamedPort )
402- }
403399 if portKind == numericPortType {
404400 portInfo , protocol := numericPortRule (& ports [i ])
405401 acl .DstPorts = portInfo
@@ -694,9 +690,10 @@ func TranslatePolicy(npObj *networkingv1.NetworkPolicy, npmLiteToggle bool) (*po
694690 return npmNetPol , nil
695691}
696692
697- func checkForNamedPortType (portKind netpolPortType , npmLiteToggle bool ) error {
693+ func checkForNamedPortType (npmNetPol * policies. NPMNetworkPolicy , portKind netpolPortType , npmLiteToggle bool , direction policies. Direction , port * networkingv1. NetworkPolicyPort , cidr string ) error {
698694 if npmLiteToggle && portKind == namedPortType {
699- return ErrUnsupportedNonCIDR
695+ return fmt .Errorf ("named port not supported in policy %s (namespace: %s, direction: %s, cidr: %s, port: %v, protocol: %v): %w" ,
696+ npmNetPol .PolicyKey , npmNetPol .Namespace , direction , cidr , port .Port , port .Protocol , ErrUnsupportedNamedPort )
700697 }
701698 return nil
702699}
@@ -717,7 +714,7 @@ func checkOnlyPortRuleExists(
717714 if err != nil {
718715 return err
719716 }
720- err = checkForNamedPortType (portKind , npmLiteToggle )
717+ err = checkForNamedPortType (npmNetPol , portKind , npmLiteToggle , direction , & ports [ i ], "" )
721718 if err != nil {
722719 return err
723720 }
0 commit comments