Switch field types to PodSelector and NamespaceSelector

This commit is contained in:
xiangpengzhao 2017-11-06 15:22:50 +08:00
parent bcdff4f174
commit c691be3acf
2 changed files with 12 additions and 12 deletions

View File

@ -3106,7 +3106,7 @@ func describeNetworkPolicy(networkPolicy *networking.NetworkPolicy) (string, err
func describeNetworkPolicySpec(nps networking.NetworkPolicySpec, w PrefixWriter) { func describeNetworkPolicySpec(nps networking.NetworkPolicySpec, w PrefixWriter) {
w.Write(LEVEL_0, "Spec:\n") w.Write(LEVEL_0, "Spec:\n")
w.Write(LEVEL_1, "Pod Selector: ") w.Write(LEVEL_1, "PodSelector: ")
if len(nps.PodSelector.MatchLabels) == 0 && len(nps.PodSelector.MatchExpressions) == 0 { if len(nps.PodSelector.MatchLabels) == 0 && len(nps.PodSelector.MatchExpressions) == 0 {
w.Write(LEVEL_2, "<none> (Allowing the specific traffic to all pods in this namespace)\n") w.Write(LEVEL_2, "<none> (Allowing the specific traffic to all pods in this namespace)\n")
} else { } else {
@ -3144,9 +3144,9 @@ func printNetworkPolicySpecIngressFrom(npirs []networking.NetworkPolicyIngressRu
for _, from := range npir.From { for _, from := range npir.From {
w.Write(LEVEL_0, "%s", initialIndent) w.Write(LEVEL_0, "%s", initialIndent)
if from.PodSelector != nil { if from.PodSelector != nil {
w.Write(LEVEL_0, "%s: %s\n", "From Pod Selector", metav1.FormatLabelSelector(from.PodSelector)) w.Write(LEVEL_0, "%s: %s\n", "From PodSelector", metav1.FormatLabelSelector(from.PodSelector))
} else if from.NamespaceSelector != nil { } else if from.NamespaceSelector != nil {
w.Write(LEVEL_0, "%s: %s\n", "From Namespace Selector", metav1.FormatLabelSelector(from.NamespaceSelector)) w.Write(LEVEL_0, "%s: %s\n", "From NamespaceSelector", metav1.FormatLabelSelector(from.NamespaceSelector))
} else if from.IPBlock != nil { } else if from.IPBlock != nil {
w.Write(LEVEL_0, "From IPBlock:\n") w.Write(LEVEL_0, "From IPBlock:\n")
w.Write(LEVEL_0, "%s%sCIDR: %s\n", initialIndent, initialIndent, from.IPBlock.CIDR) w.Write(LEVEL_0, "%s%sCIDR: %s\n", initialIndent, initialIndent, from.IPBlock.CIDR)
@ -3185,9 +3185,9 @@ func printNetworkPolicySpecEgressTo(npers []networking.NetworkPolicyEgressRule,
for _, to := range nper.To { for _, to := range nper.To {
w.Write(LEVEL_0, "%s", initialIndent) w.Write(LEVEL_0, "%s", initialIndent)
if to.PodSelector != nil { if to.PodSelector != nil {
w.Write(LEVEL_0, "%s: %s\n", "To Pod Selector", metav1.FormatLabelSelector(to.PodSelector)) w.Write(LEVEL_0, "%s: %s\n", "To PodSelector", metav1.FormatLabelSelector(to.PodSelector))
} else if to.NamespaceSelector != nil { } else if to.NamespaceSelector != nil {
w.Write(LEVEL_0, "%s: %s\n", "To Namespace Selector", metav1.FormatLabelSelector(to.NamespaceSelector)) w.Write(LEVEL_0, "%s: %s\n", "To NamespaceSelector", metav1.FormatLabelSelector(to.NamespaceSelector))
} else if to.IPBlock != nil { } else if to.IPBlock != nil {
w.Write(LEVEL_0, "To IPBlock:\n") 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%sCIDR: %s\n", initialIndent, initialIndent, to.IPBlock.CIDR)

View File

@ -1657,13 +1657,13 @@ Created on: 2017-06-04 21:45:56 -0700 PDT
Labels: <none> Labels: <none>
Annotations: <none> Annotations: <none>
Spec: Spec:
Pod Selector: foo in (bar1,bar2),foo2 notin (bar1,bar2),id1=app1,id2=app2 PodSelector: foo in (bar1,bar2),foo2 notin (bar1,bar2),id1=app1,id2=app2
Allowing ingress traffic: Allowing ingress traffic:
To Port: 80/TCP To Port: 80/TCP
To Port: 82/TCP To Port: 82/TCP
From Pod Selector: id=app2,id2=app3 From PodSelector: id=app2,id2=app3
From Namespace Selector: id=app2,id2=app3 From NamespaceSelector: id=app2,id2=app3
From Namespace Selector: foo in (bar1,bar2),id=app2,id2=app3 From NamespaceSelector: foo in (bar1,bar2),id=app2,id2=app3
From IPBlock: From IPBlock:
CIDR: 192.168.0.0/16 CIDR: 192.168.0.0/16
Except: 192.168.3.0/24, 192.168.4.0/24 Except: 192.168.3.0/24, 192.168.4.0/24
@ -1673,9 +1673,9 @@ Spec:
Allowing egress traffic: Allowing egress traffic:
To Port: 80/TCP To Port: 80/TCP
To Port: 82/TCP To Port: 82/TCP
To Pod Selector: id=app2,id2=app3 To PodSelector: id=app2,id2=app3
To Namespace Selector: id=app2,id2=app3 To NamespaceSelector: id=app2,id2=app3
To Namespace Selector: foo in (bar1,bar2),id=app2,id2=app3 To NamespaceSelector: foo in (bar1,bar2),id=app2,id2=app3
To IPBlock: To IPBlock:
CIDR: 192.168.0.0/16 CIDR: 192.168.0.0/16
Except: 192.168.3.0/24, 192.168.4.0/24 Except: 192.168.3.0/24, 192.168.4.0/24