mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 01:06:27 +00:00
Fix wrong format and output.
This commit is contained in:
parent
3921ac9dd1
commit
bcdff4f174
@ -3116,7 +3116,7 @@ func describeNetworkPolicySpec(nps networking.NetworkPolicySpec, w PrefixWriter)
|
|||||||
printNetworkPolicySpecIngressFrom(nps.Ingress, " ", w)
|
printNetworkPolicySpecIngressFrom(nps.Ingress, " ", w)
|
||||||
w.Write(LEVEL_1, "Allowing egress traffic:\n")
|
w.Write(LEVEL_1, "Allowing egress traffic:\n")
|
||||||
printNetworkPolicySpecEgressTo(nps.Egress, " ", w)
|
printNetworkPolicySpecEgressTo(nps.Egress, " ", w)
|
||||||
w.Write(LEVEL_1, "Policy Types: %v\n", nps.PolicyTypes)
|
w.Write(LEVEL_1, "Policy Types: %v\n", policyTypesToString(nps.PolicyTypes))
|
||||||
}
|
}
|
||||||
|
|
||||||
func printNetworkPolicySpecIngressFrom(npirs []networking.NetworkPolicyIngressRule, initialIndent string, w PrefixWriter) {
|
func printNetworkPolicySpecIngressFrom(npirs []networking.NetworkPolicyIngressRule, initialIndent string, w PrefixWriter) {
|
||||||
@ -3167,7 +3167,7 @@ func printNetworkPolicySpecEgressTo(npers []networking.NetworkPolicyEgressRule,
|
|||||||
}
|
}
|
||||||
for i, nper := range npers {
|
for i, nper := range npers {
|
||||||
if len(nper.Ports) == 0 {
|
if len(nper.Ports) == 0 {
|
||||||
w.Write(LEVEL_0, "%s%s\n", initialIndent, "From Port: <any> (traffic allowed to all ports)")
|
w.Write(LEVEL_0, "%s%s\n", initialIndent, "To Port: <any> (traffic allowed to all ports)")
|
||||||
} else {
|
} else {
|
||||||
for _, port := range nper.Ports {
|
for _, port := range nper.Ports {
|
||||||
var proto api.Protocol
|
var proto api.Protocol
|
||||||
@ -3176,7 +3176,7 @@ func printNetworkPolicySpecEgressTo(npers []networking.NetworkPolicyEgressRule,
|
|||||||
} else {
|
} else {
|
||||||
proto = api.ProtocolTCP
|
proto = api.ProtocolTCP
|
||||||
}
|
}
|
||||||
w.Write(LEVEL_0, "%s%s: %s/%s\n", initialIndent, "From Port", port.Port, proto)
|
w.Write(LEVEL_0, "%s%s: %s/%s\n", initialIndent, "To Port", port.Port, proto)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(nper.To) == 0 {
|
if len(nper.To) == 0 {
|
||||||
@ -3381,13 +3381,6 @@ func describePodSecurityPolicy(psp *extensions.PodSecurityPolicy) (string, error
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func stringOrAll(s string) string {
|
|
||||||
if len(s) > 0 {
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
return "*"
|
|
||||||
}
|
|
||||||
|
|
||||||
func stringOrNone(s string) string {
|
func stringOrNone(s string) string {
|
||||||
if len(s) > 0 {
|
if len(s) > 0 {
|
||||||
return s
|
return s
|
||||||
@ -3451,6 +3444,18 @@ func capsToString(caps []api.Capability) string {
|
|||||||
return stringOrNone(formattedString)
|
return stringOrNone(formattedString)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func policyTypesToString(pts []networking.PolicyType) string {
|
||||||
|
formattedString := ""
|
||||||
|
if pts != nil {
|
||||||
|
strPts := []string{}
|
||||||
|
for _, p := range pts {
|
||||||
|
strPts = append(strPts, string(p))
|
||||||
|
}
|
||||||
|
formattedString = strings.Join(strPts, ", ")
|
||||||
|
}
|
||||||
|
return stringOrNone(formattedString)
|
||||||
|
}
|
||||||
|
|
||||||
// newErrNoDescriber creates a new ErrNoDescriber with the names of the provided types.
|
// newErrNoDescriber creates a new ErrNoDescriber with the names of the provided types.
|
||||||
func newErrNoDescriber(types ...reflect.Type) error {
|
func newErrNoDescriber(types ...reflect.Type) error {
|
||||||
names := make([]string, 0, len(types))
|
names := make([]string, 0, len(types))
|
||||||
|
@ -1671,8 +1671,8 @@ Spec:
|
|||||||
To Port: <any> (traffic allowed to all ports)
|
To Port: <any> (traffic allowed to all ports)
|
||||||
From: <any> (traffic not restricted by source)
|
From: <any> (traffic not restricted by source)
|
||||||
Allowing egress traffic:
|
Allowing egress traffic:
|
||||||
From Port: 80/TCP
|
To Port: 80/TCP
|
||||||
From Port: 82/TCP
|
To Port: 82/TCP
|
||||||
To Pod Selector: id=app2,id2=app3
|
To Pod Selector: id=app2,id2=app3
|
||||||
To Namespace Selector: id=app2,id2=app3
|
To Namespace Selector: id=app2,id2=app3
|
||||||
To Namespace Selector: foo in (bar1,bar2),id=app2,id2=app3
|
To Namespace Selector: foo in (bar1,bar2),id=app2,id2=app3
|
||||||
@ -1680,9 +1680,9 @@ Spec:
|
|||||||
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
|
||||||
----------
|
----------
|
||||||
From Port: <any> (traffic allowed to all ports)
|
To Port: <any> (traffic allowed to all ports)
|
||||||
To: <any> (traffic not restricted by source)
|
To: <any> (traffic not restricted by source)
|
||||||
Policy Types: [Ingress Egress]
|
Policy Types: Ingress, Egress
|
||||||
`
|
`
|
||||||
|
|
||||||
port80 := intstr.FromInt(80)
|
port80 := intstr.FromInt(80)
|
||||||
|
Loading…
Reference in New Issue
Block a user