fix error in findPortByName

using ContainerPort instead of HostPort
This commit is contained in:
xiejunan 2015-08-14 10:06:59 +08:00
parent ea59172874
commit f5446f2aa3
2 changed files with 7 additions and 7 deletions

View File

@ -255,7 +255,7 @@ func extractPort(param util.IntOrString, container api.Container) (int, error) {
func findPortByName(container api.Container, portName string) (int, error) {
for _, port := range container.Ports {
if port.Name == portName {
return port.HostPort, nil
return port.ContainerPort, nil
}
}
return 0, fmt.Errorf("port %s not found", portName)

View File

@ -48,12 +48,12 @@ func TestFindPortByName(t *testing.T) {
container := api.Container{
Ports: []api.ContainerPort{
{
Name: "foo",
HostPort: 8080,
Name: "foo",
ContainerPort: 8080,
},
{
Name: "bar",
HostPort: 9000,
Name: "bar",
ContainerPort: 9000,
},
},
}
@ -85,7 +85,7 @@ func TestGetURLParts(t *testing.T) {
for _, test := range testCases {
state := api.PodStatus{PodIP: "127.0.0.1"}
container := api.Container{
Ports: []api.ContainerPort{{Name: "found", HostPort: 93}},
Ports: []api.ContainerPort{{Name: "found", ContainerPort: 93}},
LivenessProbe: &api.Probe{
Handler: api.Handler{
HTTPGet: test.probe,
@ -138,7 +138,7 @@ func TestGetTCPAddrParts(t *testing.T) {
for _, test := range testCases {
host := "1.2.3.4"
container := api.Container{
Ports: []api.ContainerPort{{Name: "found", HostPort: 93}},
Ports: []api.ContainerPort{{Name: "found", ContainerPort: 93}},
LivenessProbe: &api.Probe{
Handler: api.Handler{
TCPSocket: test.probe,