mirror of https://github.com/k3s-io/k3s
Fix wrong format and output.
parent
3921ac9dd1
commit
bcdff4f174
|
@ -3116,7 +3116,7 @@ func describeNetworkPolicySpec(nps networking.NetworkPolicySpec, w PrefixWriter)
|
|||
printNetworkPolicySpecIngressFrom(nps.Ingress, " ", w)
|
||||
w.Write(LEVEL_1, "Allowing egress traffic:\n")
|
||||
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) {
|
||||
|
@ -3167,7 +3167,7 @@ func printNetworkPolicySpecEgressTo(npers []networking.NetworkPolicyEgressRule,
|
|||
}
|
||||
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)")
|
||||
w.Write(LEVEL_0, "%s%s\n", initialIndent, "To Port: <any> (traffic allowed to all ports)")
|
||||
} else {
|
||||
for _, port := range nper.Ports {
|
||||
var proto api.Protocol
|
||||
|
@ -3176,7 +3176,7 @@ func printNetworkPolicySpecEgressTo(npers []networking.NetworkPolicyEgressRule,
|
|||
} else {
|
||||
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 {
|
||||
|
@ -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 {
|
||||
if len(s) > 0 {
|
||||
return s
|
||||
|
@ -3451,6 +3444,18 @@ func capsToString(caps []api.Capability) string {
|
|||
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.
|
||||
func newErrNoDescriber(types ...reflect.Type) error {
|
||||
names := make([]string, 0, len(types))
|
||||
|
|
|
@ -1671,8 +1671,8 @@ Spec:
|
|||
To Port: <any> (traffic allowed to all ports)
|
||||
From: <any> (traffic not restricted by source)
|
||||
Allowing egress traffic:
|
||||
From Port: 80/TCP
|
||||
From Port: 82/TCP
|
||||
To Port: 80/TCP
|
||||
To Port: 82/TCP
|
||||
To Pod Selector: id=app2,id2=app3
|
||||
To Namespace Selector: 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
|
||||
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)
|
||||
Policy Types: [Ingress Egress]
|
||||
Policy Types: Ingress, Egress
|
||||
`
|
||||
|
||||
port80 := intstr.FromInt(80)
|
||||
|
|
Loading…
Reference in New Issue