addressing review comment

This commit is contained in:
Murali Reddy committed 2018-08-14 20:16:04 +05:30
1 parent 6625e29071
commit a19d025677
1 file changed
+15 -11
+15 -11
View File
@@ -2,7 +2,6 @@ package npc
import ( import (
"fmt" "fmt"
"strconv"
apiv1 "k8s.io/api/core/v1" apiv1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1" networkingv1 "k8s.io/api/networking/v1"
@@ -52,11 +51,9 @@ func (ns *ns) analysePolicy(policy *networkingv1.NetworkPolicy) (
allSources := ingressRule.From == nil || len(ingressRule.From) == 0 allSources := ingressRule.From == nil || len(ingressRule.From) == 0
if !allPorts { if !allPorts {
for _, npProtocolPort := range ingressRule.Ports { if err = checkForNamedPorts(ingressRule.Ports); err != nil {
if _, err := strconv.Atoi(port(npProtocolPort.Port)); err != nil { return nil, nil, nil, nil, fmt.Errorf("named ports in network policies is not supported yet. "+
return nil, nil, nil, nil, fmt.Errorf("named ports in network policies is not supported yet. "+ "Rejecting network policy: %s from further processing. "+err.Error(), policy.Name)
"Rejecting network policy: %s with named port: %s from further processing ", policy.Name, port(npProtocolPort.Port))
}
} }
} }
if allSources { if allSources {
@@ -113,11 +110,9 @@ func (ns *ns) analysePolicy(policy *networkingv1.NetworkPolicy) (
allDestinations := egressRule.To == nil || len(egressRule.To) == 0 allDestinations := egressRule.To == nil || len(egressRule.To) == 0
if !allPorts { if !allPorts {
for _, npProtocolPort := range egressRule.Ports { if err = checkForNamedPorts(egressRule.Ports); err != nil {
if _, err := strconv.Atoi(port(npProtocolPort.Port)); err != nil { return nil, nil, nil, nil, fmt.Errorf("named ports in network policies is not supported yet. "+
return nil, nil, nil, nil, fmt.Errorf("named ports in network policies is not supported yet. "+ "Rejecting network policy: %s from further processing. "+err.Error(), policy.Name)
"Rejecting network policy: %s with named port: %s from further processing ", policy.Name, port(npProtocolPort.Port))
}
} }
} }
if allDestinations { if allDestinations {
@@ -212,3 +207,12 @@ func port(p *intstr.IntOrString) string {
return port return port
} }
func checkForNamedPorts(ports []networkingv1.NetworkPolicyPort) error {
for _, npProtocolPort := range ports {
if npProtocolPort.Port != nil && npProtocolPort.Port.Type == intstr.String {
return fmt.Errorf("named port %s in network policy", port(npProtocolPort.Port))
}
}
return nil
}