Fixup port printing.

This commit is contained in:
Brendan Burns
2015-06-19 15:10:22 -07:00
parent 3a598eba0e
commit f0ff1927f1
2 changed files with 27 additions and 5 deletions

View File

@@ -127,7 +127,7 @@ func printObjectSpecificMessage(obj runtime.Object, out io.Writer) {
you will also need to explicitly open a Firewall rule for the service port(s) (%s) to serve traffic.
See https://github.com/GoogleCloudPlatform/kubernetes/tree/master/docs/services-firewalls.md for more details.
`, makePortsString(obj.Spec.Ports))
`, makePortsString(obj.Spec.Ports, false))
out.Write([]byte(msg))
}
if obj.Spec.Type == api.ServiceTypeNodePort {
@@ -137,16 +137,22 @@ func printObjectSpecificMessage(obj runtime.Object, out io.Writer) {
firewall rules for the service port(s) (%s) to serve traffic.
See https://github.com/GoogleCloudPlatform/kubernetes/tree/master/docs/services-firewalls.md for more details.
`, makePortsString(obj.Spec.Ports))
`, makePortsString(obj.Spec.Ports, true))
out.Write([]byte(msg))
}
}
}
func makePortsString(ports []api.ServicePort) string {
func makePortsString(ports []api.ServicePort, useNodePort bool) string {
pieces := make([]string, len(ports))
for ix := range ports {
pieces[ix] = fmt.Sprintf("%s:%d", strings.ToLower(string(ports[ix].Protocol)), ports[ix].NodePort)
var port int
if useNodePort {
port = ports[ix].NodePort
} else {
port = ports[ix].Port
}
pieces[ix] = fmt.Sprintf("%s:%d", strings.ToLower(string(ports[ix].Protocol)), port)
}
return strings.Join(pieces, ",")
}