@@ -1086,6 +1086,15 @@ func (npc *NetworkPolicyController) getEgressNetworkPolicyEnabledPods(nodeIp str
10861086 return & nodePods , nil
10871087}
10881088
1089+ func (npc * NetworkPolicyController ) checkForNamedPorts (ports * []networking.NetworkPolicyPort ) error {
1090+ for _ , npProtocolPort := range * ports {
1091+ if npProtocolPort .Port != nil && npProtocolPort .Port .Type == intstr .String {
1092+ return fmt .Errorf ("named port %s in network policy" , npProtocolPort .Port .String ())
1093+ }
1094+ }
1095+ return nil
1096+ }
1097+
10891098func (npc * NetworkPolicyController ) buildNetworkPoliciesInfo () (* []networkPolicyInfo , error ) {
10901099
10911100 NetworkPolicies := make ([]networkPolicyInfo , 0 )
@@ -1157,6 +1166,7 @@ func (npc *NetworkPolicyController) buildNetworkPoliciesInfo() (*[]networkPolicy
11571166 newPolicy .egressRules = make ([]egressRule , 0 )
11581167 }
11591168
1169+ var skipPolicy bool
11601170 for _ , specIngressRule := range policy .Spec .Ingress {
11611171 ingressRule := ingressRule {}
11621172
@@ -1167,6 +1177,11 @@ func (npc *NetworkPolicyController) buildNetworkPoliciesInfo() (*[]networkPolicy
11671177 ingressRule .matchAllPorts = true
11681178 } else {
11691179 ingressRule .matchAllPorts = false
1180+ if npc .checkForNamedPorts (& specIngressRule .Ports ) != nil {
1181+ glog .Errorf ("Found a network policy: %s/%s with named port. Skipping processing network policy as its unspported yet." , policy .Namespace , policy .Name )
1182+ skipPolicy = true
1183+ continue
1184+ }
11701185 for _ , port := range specIngressRule .Ports {
11711186 protocolAndPort := newProtocolAndPort (string (* port .Protocol ), port .Port )
11721187 ingressRule .ports = append (ingressRule .ports , protocolAndPort )
@@ -1211,6 +1226,11 @@ func (npc *NetworkPolicyController) buildNetworkPoliciesInfo() (*[]networkPolicy
12111226 egressRule .matchAllPorts = true
12121227 } else {
12131228 egressRule .matchAllPorts = false
1229+ if npc .checkForNamedPorts (& specEgressRule .Ports ) != nil {
1230+ glog .Errorf ("Found a network policy: %s/%s with named port. Skipping processing network policy as its unspported yet." , policy .Namespace , policy .Name )
1231+ skipPolicy = true
1232+ continue
1233+ }
12141234 for _ , port := range specEgressRule .Ports {
12151235 protocolAndPort := newProtocolAndPort (string (* port .Protocol ), port .Port )
12161236 egressRule .ports = append (egressRule .ports , protocolAndPort )
@@ -1244,7 +1264,9 @@ func (npc *NetworkPolicyController) buildNetworkPoliciesInfo() (*[]networkPolicy
12441264
12451265 newPolicy .egressRules = append (newPolicy .egressRules , egressRule )
12461266 }
1247- NetworkPolicies = append (NetworkPolicies , newPolicy )
1267+ if ! skipPolicy {
1268+ NetworkPolicies = append (NetworkPolicies , newPolicy )
1269+ }
12481270 }
12491271
12501272 return & NetworkPolicies , nil
0 commit comments