mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-06 03:33:26 +00:00
update network policy describe
This commit is contained in:
@@ -3272,15 +3272,18 @@ func printNetworkPolicySpecIngressFrom(npirs []networking.NetworkPolicyIngressRu
|
|||||||
w.Write(LEVEL_0, "%s%s\n", initialIndent, "From: <any> (traffic not restricted by source)")
|
w.Write(LEVEL_0, "%s%s\n", initialIndent, "From: <any> (traffic not restricted by source)")
|
||||||
} else {
|
} else {
|
||||||
for _, from := range npir.From {
|
for _, from := range npir.From {
|
||||||
w.Write(LEVEL_0, "%s", initialIndent)
|
w.Write(LEVEL_0, "%s%s\n", initialIndent, "From:")
|
||||||
if from.PodSelector != nil {
|
if from.PodSelector != nil && from.NamespaceSelector != nil {
|
||||||
w.Write(LEVEL_0, "%s: %s\n", "From PodSelector", metav1.FormatLabelSelector(from.PodSelector))
|
w.Write(LEVEL_1, "%s%s: %s\n", initialIndent, "NamespaceSelector", metav1.FormatLabelSelector(from.NamespaceSelector))
|
||||||
|
w.Write(LEVEL_1, "%s%s: %s\n", initialIndent, "PodSelector", metav1.FormatLabelSelector(from.PodSelector))
|
||||||
|
} else if from.PodSelector != nil {
|
||||||
|
w.Write(LEVEL_1, "%s%s: %s\n", initialIndent, "PodSelector", metav1.FormatLabelSelector(from.PodSelector))
|
||||||
} else if from.NamespaceSelector != nil {
|
} else if from.NamespaceSelector != nil {
|
||||||
w.Write(LEVEL_0, "%s: %s\n", "From NamespaceSelector", metav1.FormatLabelSelector(from.NamespaceSelector))
|
w.Write(LEVEL_1, "%s%s: %s\n", initialIndent, "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_1, "%sIPBlock:\n", initialIndent)
|
||||||
w.Write(LEVEL_0, "%s%sCIDR: %s\n", initialIndent, initialIndent, from.IPBlock.CIDR)
|
w.Write(LEVEL_2, "%sCIDR: %s\n", initialIndent, from.IPBlock.CIDR)
|
||||||
w.Write(LEVEL_0, "%s%sExcept: %v\n", initialIndent, initialIndent, strings.Join(from.IPBlock.Except, ", "))
|
w.Write(LEVEL_2, "%sExcept: %v\n", initialIndent, strings.Join(from.IPBlock.Except, ", "))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3313,15 +3316,18 @@ func printNetworkPolicySpecEgressTo(npers []networking.NetworkPolicyEgressRule,
|
|||||||
w.Write(LEVEL_0, "%s%s\n", initialIndent, "To: <any> (traffic not restricted by source)")
|
w.Write(LEVEL_0, "%s%s\n", initialIndent, "To: <any> (traffic not restricted by source)")
|
||||||
} else {
|
} else {
|
||||||
for _, to := range nper.To {
|
for _, to := range nper.To {
|
||||||
w.Write(LEVEL_0, "%s", initialIndent)
|
w.Write(LEVEL_0, "%s%s\n", initialIndent, "To:")
|
||||||
if to.PodSelector != nil {
|
if to.PodSelector != nil && to.NamespaceSelector != nil {
|
||||||
w.Write(LEVEL_0, "%s: %s\n", "To PodSelector", metav1.FormatLabelSelector(to.PodSelector))
|
w.Write(LEVEL_1, "%s%s: %s\n", initialIndent, "NamespaceSelector", metav1.FormatLabelSelector(to.NamespaceSelector))
|
||||||
|
w.Write(LEVEL_1, "%s%s: %s\n", initialIndent, "PodSelector", metav1.FormatLabelSelector(to.PodSelector))
|
||||||
|
} else if to.PodSelector != nil {
|
||||||
|
w.Write(LEVEL_1, "%s%s: %s\n", initialIndent, "PodSelector", metav1.FormatLabelSelector(to.PodSelector))
|
||||||
} else if to.NamespaceSelector != nil {
|
} else if to.NamespaceSelector != nil {
|
||||||
w.Write(LEVEL_0, "%s: %s\n", "To NamespaceSelector", metav1.FormatLabelSelector(to.NamespaceSelector))
|
w.Write(LEVEL_1, "%s%s: %s\n", initialIndent, "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_1, "%sIPBlock:\n", initialIndent)
|
||||||
w.Write(LEVEL_0, "%s%sCIDR: %s\n", initialIndent, initialIndent, to.IPBlock.CIDR)
|
w.Write(LEVEL_2, "%sCIDR: %s\n", initialIndent, to.IPBlock.CIDR)
|
||||||
w.Write(LEVEL_0, "%s%sExcept: %v\n", initialIndent, initialIndent, strings.Join(to.IPBlock.Except, ", "))
|
w.Write(LEVEL_2, "%sExcept: %v\n", initialIndent, strings.Join(to.IPBlock.Except, ", "))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2275,10 +2275,17 @@ Spec:
|
|||||||
Allowing ingress traffic:
|
Allowing ingress traffic:
|
||||||
To Port: 80/TCP
|
To Port: 80/TCP
|
||||||
To Port: 82/TCP
|
To Port: 82/TCP
|
||||||
From PodSelector: id=app2,id2=app3
|
From:
|
||||||
From NamespaceSelector: id=app2,id2=app3
|
NamespaceSelector: id=ns1,id2=ns2
|
||||||
From NamespaceSelector: foo in (bar1,bar2),id=app2,id2=app3
|
PodSelector: id=pod1,id2=pod2
|
||||||
From IPBlock:
|
From:
|
||||||
|
PodSelector: id=app2,id2=app3
|
||||||
|
From:
|
||||||
|
NamespaceSelector: id=app2,id2=app3
|
||||||
|
From:
|
||||||
|
NamespaceSelector: foo in (bar1,bar2),id=app2,id2=app3
|
||||||
|
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
|
||||||
----------
|
----------
|
||||||
@@ -2287,10 +2294,17 @@ Spec:
|
|||||||
Allowing egress traffic:
|
Allowing egress traffic:
|
||||||
To Port: 80/TCP
|
To Port: 80/TCP
|
||||||
To Port: 82/TCP
|
To Port: 82/TCP
|
||||||
To PodSelector: id=app2,id2=app3
|
To:
|
||||||
To NamespaceSelector: id=app2,id2=app3
|
NamespaceSelector: id=ns1,id2=ns2
|
||||||
To NamespaceSelector: foo in (bar1,bar2),id=app2,id2=app3
|
PodSelector: id=pod1,id2=pod2
|
||||||
To IPBlock:
|
To:
|
||||||
|
PodSelector: id=app2,id2=app3
|
||||||
|
To:
|
||||||
|
NamespaceSelector: id=app2,id2=app3
|
||||||
|
To:
|
||||||
|
NamespaceSelector: foo in (bar1,bar2),id=app2,id2=app3
|
||||||
|
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
|
||||||
----------
|
----------
|
||||||
@@ -2327,6 +2341,20 @@ Spec:
|
|||||||
{Port: &port82, Protocol: &protoTCP},
|
{Port: &port82, Protocol: &protoTCP},
|
||||||
},
|
},
|
||||||
From: []networking.NetworkPolicyPeer{
|
From: []networking.NetworkPolicyPeer{
|
||||||
|
{
|
||||||
|
PodSelector: &metav1.LabelSelector{
|
||||||
|
MatchLabels: map[string]string{
|
||||||
|
"id": "pod1",
|
||||||
|
"id2": "pod2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
NamespaceSelector: &metav1.LabelSelector{
|
||||||
|
MatchLabels: map[string]string{
|
||||||
|
"id": "ns1",
|
||||||
|
"id2": "ns2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
PodSelector: &metav1.LabelSelector{
|
PodSelector: &metav1.LabelSelector{
|
||||||
MatchLabels: map[string]string{
|
MatchLabels: map[string]string{
|
||||||
@@ -2371,6 +2399,20 @@ Spec:
|
|||||||
{Port: &port82, Protocol: &protoTCP},
|
{Port: &port82, Protocol: &protoTCP},
|
||||||
},
|
},
|
||||||
To: []networking.NetworkPolicyPeer{
|
To: []networking.NetworkPolicyPeer{
|
||||||
|
{
|
||||||
|
PodSelector: &metav1.LabelSelector{
|
||||||
|
MatchLabels: map[string]string{
|
||||||
|
"id": "pod1",
|
||||||
|
"id2": "pod2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
NamespaceSelector: &metav1.LabelSelector{
|
||||||
|
MatchLabels: map[string]string{
|
||||||
|
"id": "ns1",
|
||||||
|
"id2": "ns2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
PodSelector: &metav1.LabelSelector{
|
PodSelector: &metav1.LabelSelector{
|
||||||
MatchLabels: map[string]string{
|
MatchLabels: map[string]string{
|
||||||
|
Reference in New Issue
Block a user