mirror of https://github.com/k3s-io/k3s
Describe NetworkPolicyEgressRule.
parent
d735f660bc
commit
0cf5a2dedc
|
@ -3114,6 +3114,8 @@ func describeNetworkPolicySpec(nps networking.NetworkPolicySpec, w PrefixWriter)
|
|||
}
|
||||
w.Write(LEVEL_1, "Allowing ingress traffic:\n")
|
||||
printNetworkPolicySpecIngressFrom(nps.Ingress, " ", w)
|
||||
w.Write(LEVEL_1, "Allowing egress traffic:\n")
|
||||
printNetworkPolicySpecEgressTo(nps.Egress, " ", w)
|
||||
}
|
||||
|
||||
func printNetworkPolicySpecIngressFrom(npirs []networking.NetworkPolicyIngressRule, initialIndent string, w PrefixWriter) {
|
||||
|
@ -3157,6 +3159,47 @@ func printNetworkPolicySpecIngressFrom(npirs []networking.NetworkPolicyIngressRu
|
|||
}
|
||||
}
|
||||
|
||||
func printNetworkPolicySpecEgressTo(npers []networking.NetworkPolicyEgressRule, initialIndent string, w PrefixWriter) {
|
||||
if len(npers) == 0 {
|
||||
w.Write(LEVEL_0, "%s%s\n", initialIndent, "<none> (Selected pods are isolated for egress connectivity)")
|
||||
return
|
||||
}
|
||||
for i, nper := range npers {
|
||||
if len(nper.Ports) == 0 {
|
||||
w.Write(LEVEL_0, "%s%s\n", initialIndent, "From Port: <any> (traffic allowed to all ports)")
|
||||
} else {
|
||||
for _, port := range nper.Ports {
|
||||
var proto api.Protocol
|
||||
if port.Protocol != nil {
|
||||
proto = *port.Protocol
|
||||
} else {
|
||||
proto = api.ProtocolTCP
|
||||
}
|
||||
w.Write(LEVEL_0, "%s%s: %s/%s\n", initialIndent, "From Port", port.Port, proto)
|
||||
}
|
||||
}
|
||||
if len(nper.To) == 0 {
|
||||
w.Write(LEVEL_0, "%s%s\n", initialIndent, "To: <any> (traffic not restricted by source)")
|
||||
} else {
|
||||
for _, to := range nper.To {
|
||||
w.Write(LEVEL_0, "%s", initialIndent)
|
||||
if to.PodSelector != nil {
|
||||
w.Write(LEVEL_0, "%s: %s\n", "To Pod Selector", metav1.FormatLabelSelector(to.PodSelector))
|
||||
} else if to.NamespaceSelector != nil {
|
||||
w.Write(LEVEL_0, "%s: %s\n", "To Namespace Selector", metav1.FormatLabelSelector(to.NamespaceSelector))
|
||||
} else if to.IPBlock != nil {
|
||||
w.Write(LEVEL_0, "To IPBlock:\n")
|
||||
w.Write(LEVEL_0, "%s%sCIDR: %s\n", initialIndent, initialIndent, to.IPBlock.CIDR)
|
||||
w.Write(LEVEL_0, "%s%sExcept: %v\n", initialIndent, initialIndent, strings.Join(to.IPBlock.Except, ", "))
|
||||
}
|
||||
}
|
||||
}
|
||||
if i != len(npers)-1 {
|
||||
w.Write(LEVEL_0, "%s%s\n", initialIndent, "----------")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type StorageClassDescriber struct {
|
||||
clientset.Interface
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue