mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
fix error in findPortByName
using ContainerPort instead of HostPort
This commit is contained in:
parent
ea59172874
commit
f5446f2aa3
@ -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)
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user