weave-npc doesn't handle named ports
Support for names ports in enhancement, but with this PR just adding more graceful failure. Fixes #3032
This commit is contained in:
1 parent
55354900da
commit
d5e864736b
1 file changed
+16
@@ -1,7 +1,9 @@
|
|||||||
package npc
|
package npc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"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"
|
||||||
@@ -50,6 +52,13 @@ func (ns *ns) analysePolicy(policy *networkingv1.NetworkPolicy) (
|
|||||||
// If From is empty or missing, this rule matches all sources
|
// If From is empty or missing, this rule matches all sources
|
||||||
allSources := ingressRule.From == nil || len(ingressRule.From) == 0
|
allSources := ingressRule.From == nil || len(ingressRule.From) == 0
|
||||||
|
|
||||||
|
if !allPorts {
|
||||||
|
for _, npProtocolPort := range ingressRule.Ports {
|
||||||
|
if _, err := strconv.Atoi(port(npProtocolPort.Port)); err != nil {
|
||||||
|
return nil, nil, nil, nil, errors.New("named ports in network policies in not support yet. Rejecting network policy from further processing")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if allSources {
|
if allSources {
|
||||||
if allPorts {
|
if allPorts {
|
||||||
rule := newRuleSpec(policyTypeIngress, nil, nil, targetSelector, nil)
|
rule := newRuleSpec(policyTypeIngress, nil, nil, targetSelector, nil)
|
||||||
@@ -103,6 +112,13 @@ func (ns *ns) analysePolicy(policy *networkingv1.NetworkPolicy) (
|
|||||||
// If To is empty or missing, this rule matches all destinations
|
// If To is empty or missing, this rule matches all destinations
|
||||||
allDestinations := egressRule.To == nil || len(egressRule.To) == 0
|
allDestinations := egressRule.To == nil || len(egressRule.To) == 0
|
||||||
|
|
||||||
|
if !allPorts {
|
||||||
|
for _, npProtocolPort := range egressRule.Ports {
|
||||||
|
if _, err := strconv.Atoi(port(npProtocolPort.Port)); err != nil {
|
||||||
|
return nil, nil, nil, nil, errors.New("named ports in network policies in not support yet. Rejecting network policy from further processing")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if allDestinations {
|
if allDestinations {
|
||||||
if allPorts {
|
if allPorts {
|
||||||
rule := newRuleSpec(policyTypeEgress, nil, targetSelector, nil, nil)
|
rule := newRuleSpec(policyTypeEgress, nil, targetSelector, nil, nil)
|
||||||
|
|||||||
Reference in new issue
Block a user