Change the service port defaulting to be more sane.

This commit is contained in:
Brendan Burns
2015-02-26 11:37:50 -08:00
parent 6f85bd0c66
commit f8dd4fcac5
2 changed files with 92 additions and 26 deletions

View File

@@ -80,6 +80,11 @@ func TestFindPort(t *testing.T) {
ContainerPort: 8000,
HostPort: 9000,
},
{
Name: "default",
ContainerPort: 8100,
HostPort: 9200,
},
},
},
},
@@ -96,6 +101,37 @@ func TestFindPort(t *testing.T) {
},
}
singlePortPod := api.Pod{
Spec: api.PodSpec{
Containers: []api.Container{
{
Ports: []api.ContainerPort{
{
ContainerPort: 8300,
},
},
},
},
},
}
noDefaultPod := api.Pod{
Spec: api.PodSpec{
Containers: []api.Container{
{
Ports: []api.ContainerPort{
{
Name: "foo",
ContainerPort: 8300,
},
},
},
},
},
}
servicePort := 999
tests := []struct {
pod api.Pod
portName util.IntOrString
@@ -133,33 +169,51 @@ func TestFindPort(t *testing.T) {
0,
true,
},
{
pod,
util.IntOrString{Kind: util.IntstrString, StrVal: ""},
8080,
false,
},
{
pod,
util.IntOrString{Kind: util.IntstrInt, IntVal: 0},
8080,
false,
},
{
emptyPortsPod,
util.IntOrString{Kind: util.IntstrString, StrVal: ""},
util.IntOrString{Kind: util.IntstrString, StrVal: "foo"},
0,
true,
},
{
emptyPortsPod,
util.IntOrString{Kind: util.IntstrString, StrVal: ""},
servicePort,
false,
},
{
emptyPortsPod,
util.IntOrString{Kind: util.IntstrInt, IntVal: 0},
0,
true,
servicePort,
false,
},
{
singlePortPod,
util.IntOrString{Kind: util.IntstrString, StrVal: ""},
8300,
false,
},
{
singlePortPod,
util.IntOrString{Kind: util.IntstrInt, IntVal: 0},
8300,
false,
},
{
noDefaultPod,
util.IntOrString{Kind: util.IntstrString, StrVal: ""},
8300,
false,
},
{
noDefaultPod,
util.IntOrString{Kind: util.IntstrInt, IntVal: 0},
8300,
false,
},
}
for _, test := range tests {
port, err := findPort(&test.pod, test.portName)
port, err := findPort(&test.pod, &api.Service{Spec: api.ServiceSpec{Port: servicePort, ContainerPort: test.portName}})
if port != test.wport {
t.Errorf("Expected port %d, Got %d", test.wport, port)
}