mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 02:09:56 +00:00
Service REST test: helper funcs for ports, too
This commit is contained in:
parent
5f65ba7d76
commit
b1fcbab801
@ -284,15 +284,12 @@ func makeService(name string, tweaks ...serviceTweak) *api.Service {
|
|||||||
Spec: api.ServiceSpec{
|
Spec: api.ServiceSpec{
|
||||||
Selector: map[string]string{"bar": "baz"},
|
Selector: map[string]string{"bar": "baz"},
|
||||||
SessionAffinity: api.ServiceAffinityNone,
|
SessionAffinity: api.ServiceAffinityNone,
|
||||||
Ports: []api.ServicePort{{
|
|
||||||
Port: 93,
|
|
||||||
Protocol: api.ProtocolTCP,
|
|
||||||
TargetPort: intstr.FromInt(76),
|
|
||||||
}},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
// Default to ClusterIP
|
// Default to ClusterIP
|
||||||
tweakTypeClusterIP(svc)
|
tweakTypeClusterIP(svc)
|
||||||
|
// Default to 1 port
|
||||||
|
tweakPorts(makeServicePort("", 93, intstr.FromInt(76), api.ProtocolTCP))(svc)
|
||||||
|
|
||||||
for _, tweak := range tweaks {
|
for _, tweak := range tweaks {
|
||||||
tweak(svc)
|
tweak(svc)
|
||||||
@ -327,12 +324,12 @@ func tweakPorts(ports ...api.ServicePort) serviceTweak {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeServicePort(name string, port int, tgtPort intstr.IntOrString) api.ServicePort {
|
func makeServicePort(name string, port int, tgtPort intstr.IntOrString, proto api.Protocol) api.ServicePort {
|
||||||
return api.ServicePort{
|
return api.ServicePort{
|
||||||
Name: name,
|
Name: name,
|
||||||
Port: int32(port),
|
Port: int32(port),
|
||||||
TargetPort: tgtPort,
|
TargetPort: tgtPort,
|
||||||
Protocol: api.ProtocolTCP,
|
Protocol: proto,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,6 +352,17 @@ func tweakIPFamilyPolicy(policy api.IPFamilyPolicyType) serviceTweak {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func tweakNodePorts(values ...int) serviceTweak {
|
||||||
|
return func(svc *api.Service) {
|
||||||
|
for i := range svc.Spec.Ports {
|
||||||
|
if i >= len(values) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
svc.Spec.Ports[i].NodePort = int32(values[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func releaseServiceNodePorts(t *testing.T, ctx context.Context, svcName string, rest *REST, registry ServiceStorage) {
|
func releaseServiceNodePorts(t *testing.T, ctx context.Context, svcName string, rest *REST, registry ServiceStorage) {
|
||||||
obj, err := registry.Get(ctx, svcName, &metav1.GetOptions{})
|
obj, err := registry.Get(ctx, svcName, &metav1.GetOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -541,21 +549,10 @@ func TestDryRunNodePort(t *testing.T) {
|
|||||||
// Test dry run create request with multi node port
|
// Test dry run create request with multi node port
|
||||||
svc = makeService("foo",
|
svc = makeService("foo",
|
||||||
tweakTypeNodePort,
|
tweakTypeNodePort,
|
||||||
func(s *api.Service) {
|
tweakPorts(
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
makeServicePort("port-tcp", 53, intstr.FromInt(6503), api.ProtocolTCP),
|
||||||
Name: "port-tcp",
|
makeServicePort("port-udp", 53, intstr.FromInt(6503), api.ProtocolUDP)),
|
||||||
Port: 53,
|
tweakNodePorts(30053, 30053))
|
||||||
NodePort: 30053,
|
|
||||||
TargetPort: intstr.FromInt(6503),
|
|
||||||
Protocol: api.ProtocolTCP,
|
|
||||||
}, {
|
|
||||||
Name: "port-udp",
|
|
||||||
Port: 53,
|
|
||||||
NodePort: 30053,
|
|
||||||
TargetPort: intstr.FromInt(6503),
|
|
||||||
Protocol: api.ProtocolUDP,
|
|
||||||
}}
|
|
||||||
})
|
|
||||||
expectNodePorts := collectServiceNodePorts(svc)
|
expectNodePorts := collectServiceNodePorts(svc)
|
||||||
obj, err = storage.Create(ctx, svc, rest.ValidateAllObjectFunc, &metav1.CreateOptions{DryRun: []string{metav1.DryRunAll}})
|
obj, err = storage.Create(ctx, svc, rest.ValidateAllObjectFunc, &metav1.CreateOptions{DryRun: []string{metav1.DryRunAll}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -583,19 +580,9 @@ func TestDryRunNodePort(t *testing.T) {
|
|||||||
// so PortAllocationOperation.AllocateNext() will be called multiple times.
|
// so PortAllocationOperation.AllocateNext() will be called multiple times.
|
||||||
svc = makeService("foo",
|
svc = makeService("foo",
|
||||||
tweakTypeNodePort,
|
tweakTypeNodePort,
|
||||||
func(s *api.Service) {
|
tweakPorts(
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
makeServicePort("port-a", 53, intstr.FromInt(6503), api.ProtocolTCP),
|
||||||
Name: "port-a",
|
makeServicePort("port-b", 54, intstr.FromInt(6504), api.ProtocolUDP)))
|
||||||
Port: 53,
|
|
||||||
Protocol: api.ProtocolTCP,
|
|
||||||
TargetPort: intstr.FromInt(6503),
|
|
||||||
}, {
|
|
||||||
Name: "port-b",
|
|
||||||
Port: 54,
|
|
||||||
Protocol: api.ProtocolTCP,
|
|
||||||
TargetPort: intstr.FromInt(6504),
|
|
||||||
}}
|
|
||||||
})
|
|
||||||
obj, err = storage.Create(ctx, svc, rest.ValidateAllObjectFunc, &metav1.CreateOptions{DryRun: []string{metav1.DryRunAll}})
|
obj, err = storage.Create(ctx, svc, rest.ValidateAllObjectFunc, &metav1.CreateOptions{DryRun: []string{metav1.DryRunAll}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected error: %v", err)
|
t.Fatalf("Unexpected error: %v", err)
|
||||||
@ -626,60 +613,28 @@ func TestServiceRegistryCreateMultiNodePortsService(t *testing.T) {
|
|||||||
}{{
|
}{{
|
||||||
svc: makeService("foo1",
|
svc: makeService("foo1",
|
||||||
tweakTypeNodePort,
|
tweakTypeNodePort,
|
||||||
func(s *api.Service) {
|
tweakPorts(
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
makeServicePort("port-tcp", 53, intstr.FromInt(6503), api.ProtocolTCP),
|
||||||
Name: "port-tcp",
|
makeServicePort("port-udp", 53, intstr.FromInt(6503), api.ProtocolUDP)),
|
||||||
Port: 53,
|
tweakNodePorts(30053, 30053)),
|
||||||
NodePort: 30053,
|
|
||||||
TargetPort: intstr.FromInt(6503),
|
|
||||||
Protocol: api.ProtocolTCP,
|
|
||||||
}, {
|
|
||||||
Name: "port-udp",
|
|
||||||
Port: 53,
|
|
||||||
NodePort: 30053,
|
|
||||||
TargetPort: intstr.FromInt(6503),
|
|
||||||
Protocol: api.ProtocolUDP,
|
|
||||||
}}
|
|
||||||
}),
|
|
||||||
name: "foo1",
|
name: "foo1",
|
||||||
expectNodePorts: []int{30053, 30053},
|
expectNodePorts: []int{30053, 30053},
|
||||||
}, {
|
}, {
|
||||||
svc: makeService("foo2",
|
svc: makeService("foo2",
|
||||||
tweakTypeNodePort,
|
tweakTypeNodePort,
|
||||||
func(s *api.Service) {
|
tweakPorts(
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
makeServicePort("port-tcp", 54, intstr.FromInt(6504), api.ProtocolTCP),
|
||||||
Name: "port-tcp",
|
makeServicePort("port-udp", 54, intstr.FromInt(6504), api.ProtocolUDP)),
|
||||||
Port: 54,
|
tweakNodePorts(30054, 30054)),
|
||||||
TargetPort: intstr.FromInt(6504),
|
|
||||||
Protocol: api.ProtocolTCP,
|
|
||||||
}, {
|
|
||||||
Name: "port-udp",
|
|
||||||
Port: 54,
|
|
||||||
NodePort: 30054,
|
|
||||||
TargetPort: intstr.FromInt(6504),
|
|
||||||
Protocol: api.ProtocolUDP,
|
|
||||||
}}
|
|
||||||
}),
|
|
||||||
name: "foo2",
|
name: "foo2",
|
||||||
expectNodePorts: []int{30054, 30054},
|
expectNodePorts: []int{30054, 30054},
|
||||||
}, {
|
}, {
|
||||||
svc: makeService("foo3",
|
svc: makeService("foo3",
|
||||||
tweakTypeNodePort,
|
tweakTypeNodePort,
|
||||||
func(s *api.Service) {
|
tweakPorts(
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
makeServicePort("port-tcp", 55, intstr.FromInt(6505), api.ProtocolTCP),
|
||||||
Name: "port-tcp",
|
makeServicePort("port-udp", 55, intstr.FromInt(6506), api.ProtocolUDP)),
|
||||||
Port: 55,
|
tweakNodePorts(30055, 30056)),
|
||||||
NodePort: 30055,
|
|
||||||
TargetPort: intstr.FromInt(6505),
|
|
||||||
Protocol: api.ProtocolTCP,
|
|
||||||
}, {
|
|
||||||
Name: "port-udp",
|
|
||||||
Port: 55,
|
|
||||||
NodePort: 30056,
|
|
||||||
TargetPort: intstr.FromInt(6506),
|
|
||||||
Protocol: api.ProtocolUDP,
|
|
||||||
}}
|
|
||||||
}),
|
|
||||||
name: "foo3",
|
name: "foo3",
|
||||||
expectNodePorts: []int{30055, 30056},
|
expectNodePorts: []int{30055, 30056},
|
||||||
}}
|
}}
|
||||||
@ -725,17 +680,10 @@ func TestServiceStorageValidatesCreate(t *testing.T) {
|
|||||||
defer server.Terminate(t)
|
defer server.Terminate(t)
|
||||||
failureCases := map[string]*api.Service{
|
failureCases := map[string]*api.Service{
|
||||||
"empty ID": makeService(""),
|
"empty ID": makeService(""),
|
||||||
"empty port": makeService("foo", func(s *api.Service) {
|
"empty port": makeService("foo", tweakPorts(
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
makeServicePort("p", 0, intstr.FromInt(80), api.ProtocolTCP))),
|
||||||
Protocol: api.ProtocolTCP,
|
"missing targetPort": makeService("foo", tweakPorts(
|
||||||
}}
|
makeServicePort("p", 80, intstr.IntOrString{}, api.ProtocolTCP))),
|
||||||
}),
|
|
||||||
"missing targetPort": makeService("foo", func(s *api.Service) {
|
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
|
||||||
Port: 6502,
|
|
||||||
Protocol: api.ProtocolTCP,
|
|
||||||
}}
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
ctx := genericapirequest.NewDefaultContext()
|
ctx := genericapirequest.NewDefaultContext()
|
||||||
for _, failureCase := range failureCases {
|
for _, failureCase := range failureCases {
|
||||||
@ -1154,20 +1102,11 @@ func TestServiceRegistryUpdateMultiPortExternalService(t *testing.T) {
|
|||||||
defer server.Terminate(t)
|
defer server.Terminate(t)
|
||||||
|
|
||||||
// Create external load balancer.
|
// Create external load balancer.
|
||||||
svc1 := makeService("foo", func(s *api.Service) {
|
svc1 := makeService("foo",
|
||||||
s.Spec.Type = api.ServiceTypeLoadBalancer
|
tweakTypeLoadBalancer,
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
tweakPorts(
|
||||||
Name: "p",
|
makeServicePort("p", 6502, intstr.FromInt(6502), api.ProtocolTCP),
|
||||||
Port: 6502,
|
makeServicePort("q", 8086, intstr.FromInt(8086), api.ProtocolTCP)))
|
||||||
Protocol: api.ProtocolTCP,
|
|
||||||
TargetPort: intstr.FromInt(6502),
|
|
||||||
}, {
|
|
||||||
Name: "q",
|
|
||||||
Port: 8086,
|
|
||||||
Protocol: api.ProtocolTCP,
|
|
||||||
TargetPort: intstr.FromInt(8086),
|
|
||||||
}}
|
|
||||||
})
|
|
||||||
obj, err := storage.Create(ctx, svc1, rest.ValidateAllObjectFunc, &metav1.CreateOptions{})
|
obj, err := storage.Create(ctx, svc1, rest.ValidateAllObjectFunc, &metav1.CreateOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected error: %v", err)
|
t.Fatalf("Unexpected error: %v", err)
|
||||||
@ -1271,16 +1210,14 @@ func TestServiceRegistryResourceLocation(t *testing.T) {
|
|||||||
storage, registry, server := NewTestRESTWithPods(t, endpoints, pods, singleStackIPv4)
|
storage, registry, server := NewTestRESTWithPods(t, endpoints, pods, singleStackIPv4)
|
||||||
defer server.Terminate(t)
|
defer server.Terminate(t)
|
||||||
for _, name := range []string{"foo", "bad"} {
|
for _, name := range []string{"foo", "bad"} {
|
||||||
_, err := registry.Create(ctx, makeService(name, func(s *api.Service) {
|
_, err := registry.Create(ctx, makeService(name,
|
||||||
s.Spec.Ports = []api.ServicePort{
|
tweakPorts(
|
||||||
// Service port 9393 should route to endpoint port "p", which is port 93
|
// Service port 9393 should route to endpoint port "p", which is port 93
|
||||||
{Name: "p", Port: 9393, TargetPort: intstr.FromString("p")},
|
makeServicePort("p", 9393, intstr.FromString("p"), api.ProtocolTCP),
|
||||||
|
|
||||||
// Service port 93 should route to unnamed endpoint port, which is port 80
|
// Service port 93 should route to unnamed endpoint port, which is port 80
|
||||||
// This is to test that the service port definition is used when determining resource location
|
// This is to test that the service port definition is used when determining resource location
|
||||||
{Name: "", Port: 93, TargetPort: intstr.FromInt(80)},
|
makeServicePort("", 93, intstr.FromInt(80), api.ProtocolTCP))),
|
||||||
}
|
rest.ValidateAllObjectFunc, &metav1.CreateOptions{})
|
||||||
}), rest.ValidateAllObjectFunc, &metav1.CreateOptions{})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error creating service: %v", err)
|
t.Fatalf("error creating service: %v", err)
|
||||||
}
|
}
|
||||||
@ -2011,86 +1948,47 @@ func TestInitNodePorts(t *testing.T) {
|
|||||||
expectSpecifiedNodePorts: []int{},
|
expectSpecifiedNodePorts: []int{},
|
||||||
}, {
|
}, {
|
||||||
name: "Service has one specified NodePort",
|
name: "Service has one specified NodePort",
|
||||||
service: makeService("foo", tweakTypeNodePort, func(s *api.Service) {
|
service: makeService("foo",
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
tweakTypeNodePort,
|
||||||
Name: "port-tcp",
|
tweakPorts(
|
||||||
Port: 53,
|
makeServicePort("port-tcp", 53, intstr.FromInt(6502), api.ProtocolTCP)),
|
||||||
TargetPort: intstr.FromInt(6502),
|
tweakNodePorts(30053)),
|
||||||
Protocol: api.ProtocolTCP,
|
|
||||||
NodePort: 30053,
|
|
||||||
}}
|
|
||||||
}),
|
|
||||||
expectSpecifiedNodePorts: []int{30053},
|
expectSpecifiedNodePorts: []int{30053},
|
||||||
}, {
|
}, {
|
||||||
name: "Service has two same ports with different protocols and specifies same NodePorts",
|
name: "Service has two same ports with different protocols and specifies same NodePorts",
|
||||||
service: makeService("foo", tweakTypeNodePort, func(s *api.Service) {
|
service: makeService("foo",
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
tweakTypeNodePort,
|
||||||
Name: "port-tcp",
|
tweakPorts(
|
||||||
Port: 53,
|
makeServicePort("port-tcp", 53, intstr.FromInt(6502), api.ProtocolTCP),
|
||||||
TargetPort: intstr.FromInt(6502),
|
makeServicePort("port-udp", 53, intstr.FromInt(6502), api.ProtocolUDP)),
|
||||||
Protocol: api.ProtocolTCP,
|
tweakNodePorts(30054, 30054)),
|
||||||
NodePort: 30054,
|
|
||||||
}, {
|
|
||||||
Name: "port-udp",
|
|
||||||
Port: 53,
|
|
||||||
TargetPort: intstr.FromInt(6502),
|
|
||||||
Protocol: api.ProtocolUDP,
|
|
||||||
NodePort: 30054,
|
|
||||||
}}
|
|
||||||
}),
|
|
||||||
expectSpecifiedNodePorts: []int{30054, 30054},
|
expectSpecifiedNodePorts: []int{30054, 30054},
|
||||||
}, {
|
}, {
|
||||||
name: "Service has two same ports with different protocols and specifies different NodePorts",
|
name: "Service has two same ports with different protocols and specifies different NodePorts",
|
||||||
service: makeService("foo", tweakTypeNodePort, func(s *api.Service) {
|
service: makeService("foo",
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
tweakTypeNodePort,
|
||||||
Name: "port-tcp",
|
tweakPorts(
|
||||||
Port: 53,
|
makeServicePort("port-tcp", 53, intstr.FromInt(6502), api.ProtocolTCP),
|
||||||
TargetPort: intstr.FromInt(6502),
|
makeServicePort("port-udp", 53, intstr.FromInt(6502), api.ProtocolUDP)),
|
||||||
Protocol: api.ProtocolTCP,
|
tweakNodePorts(30055, 30056)),
|
||||||
NodePort: 30055,
|
|
||||||
}, {
|
|
||||||
Name: "port-udp",
|
|
||||||
Port: 53,
|
|
||||||
TargetPort: intstr.FromInt(6502),
|
|
||||||
Protocol: api.ProtocolUDP,
|
|
||||||
NodePort: 30056,
|
|
||||||
}}
|
|
||||||
}),
|
|
||||||
expectSpecifiedNodePorts: []int{30055, 30056},
|
expectSpecifiedNodePorts: []int{30055, 30056},
|
||||||
}, {
|
}, {
|
||||||
name: "Service has two different ports with different protocols and specifies different NodePorts",
|
name: "Service has two different ports with different protocols and specifies different NodePorts",
|
||||||
service: makeService("foo", tweakTypeNodePort, func(s *api.Service) {
|
service: makeService("foo",
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
tweakTypeNodePort,
|
||||||
Name: "port-tcp",
|
tweakPorts(
|
||||||
Port: 53,
|
makeServicePort("port-tcp", 53, intstr.FromInt(6502), api.ProtocolTCP),
|
||||||
TargetPort: intstr.FromInt(6502),
|
makeServicePort("port-udp", 54, intstr.FromInt(6502), api.ProtocolUDP)),
|
||||||
Protocol: api.ProtocolTCP,
|
tweakNodePorts(30057, 30058)),
|
||||||
NodePort: 30057,
|
|
||||||
}, {
|
|
||||||
Name: "port-udp",
|
|
||||||
Port: 54,
|
|
||||||
TargetPort: intstr.FromInt(6502),
|
|
||||||
Protocol: api.ProtocolUDP,
|
|
||||||
NodePort: 30058,
|
|
||||||
}}
|
|
||||||
}),
|
|
||||||
expectSpecifiedNodePorts: []int{30057, 30058},
|
expectSpecifiedNodePorts: []int{30057, 30058},
|
||||||
}, {
|
}, {
|
||||||
name: "Service has two same ports with different protocols but only specifies one NodePort",
|
name: "Service has two same ports with different protocols but only specifies one NodePort",
|
||||||
service: makeService("foo", tweakTypeNodePort, func(s *api.Service) {
|
service: makeService("foo",
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
tweakTypeNodePort,
|
||||||
Name: "port-tcp",
|
tweakPorts(
|
||||||
Port: 53,
|
makeServicePort("port-tcp", 53, intstr.FromInt(6502), api.ProtocolTCP),
|
||||||
TargetPort: intstr.FromInt(6502),
|
makeServicePort("port-udp", 53, intstr.FromInt(6502), api.ProtocolUDP)),
|
||||||
Protocol: api.ProtocolTCP,
|
tweakNodePorts(30059)),
|
||||||
NodePort: 30059,
|
|
||||||
}, {
|
|
||||||
Name: "port-udp",
|
|
||||||
Port: 53,
|
|
||||||
TargetPort: intstr.FromInt(6502),
|
|
||||||
Protocol: api.ProtocolUDP,
|
|
||||||
}}
|
|
||||||
}),
|
|
||||||
expectSpecifiedNodePorts: []int{30059, 30059},
|
expectSpecifiedNodePorts: []int{30059, 30059},
|
||||||
}}
|
}}
|
||||||
|
|
||||||
@ -2132,139 +2030,81 @@ func TestUpdateNodePorts(t *testing.T) {
|
|||||||
expectSpecifiedNodePorts []int
|
expectSpecifiedNodePorts []int
|
||||||
}{{
|
}{{
|
||||||
name: "Old service and new service have the same NodePort",
|
name: "Old service and new service have the same NodePort",
|
||||||
oldService: makeService("foo", tweakTypeNodePort, func(s *api.Service) {
|
oldService: makeService("foo",
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
tweakTypeNodePort,
|
||||||
Port: 6502,
|
tweakPorts(
|
||||||
Protocol: api.ProtocolTCP,
|
makeServicePort("", 6502, intstr.FromInt(6502), api.ProtocolTCP)),
|
||||||
TargetPort: intstr.FromInt(6502),
|
tweakNodePorts(30053)),
|
||||||
NodePort: 30053,
|
newService: makeService("foo",
|
||||||
}}
|
tweakTypeNodePort,
|
||||||
}),
|
tweakPorts(
|
||||||
newService: makeService("foo", tweakTypeNodePort, func(s *api.Service) {
|
makeServicePort("", 6502, intstr.FromInt(6502), api.ProtocolTCP)),
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
tweakNodePorts(30053)),
|
||||||
Port: 6502,
|
|
||||||
Protocol: api.ProtocolTCP,
|
|
||||||
TargetPort: intstr.FromInt(6502),
|
|
||||||
NodePort: 30053,
|
|
||||||
}}
|
|
||||||
}),
|
|
||||||
expectSpecifiedNodePorts: []int{30053},
|
expectSpecifiedNodePorts: []int{30053},
|
||||||
}, {
|
}, {
|
||||||
name: "Old service has more NodePorts than new service has",
|
name: "Old service has more NodePorts than new service has",
|
||||||
oldService: makeService("foo", tweakTypeNodePort, func(s *api.Service) {
|
oldService: makeService("foo",
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
tweakTypeNodePort,
|
||||||
Name: "port-tcp",
|
tweakPorts(
|
||||||
Port: 53,
|
makeServicePort("port-tcp", 53, intstr.FromInt(6502), api.ProtocolTCP),
|
||||||
TargetPort: intstr.FromInt(6502),
|
makeServicePort("port-udp", 53, intstr.FromInt(6502), api.ProtocolUDP)),
|
||||||
Protocol: api.ProtocolTCP,
|
tweakNodePorts(30053, 30053)),
|
||||||
NodePort: 30053,
|
newService: makeService("foo",
|
||||||
}, {
|
tweakTypeNodePort,
|
||||||
Name: "port-udp",
|
tweakPorts(
|
||||||
Port: 53,
|
makeServicePort("port-tcp", 53, intstr.FromInt(6502), api.ProtocolTCP)),
|
||||||
TargetPort: intstr.FromInt(6502),
|
tweakNodePorts(30053)),
|
||||||
Protocol: api.ProtocolUDP,
|
|
||||||
NodePort: 30053,
|
|
||||||
}}
|
|
||||||
}),
|
|
||||||
newService: makeService("foo", tweakTypeNodePort, func(s *api.Service) {
|
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
|
||||||
Name: "port-tcp",
|
|
||||||
Port: 53,
|
|
||||||
TargetPort: intstr.FromInt(6502),
|
|
||||||
Protocol: api.ProtocolTCP,
|
|
||||||
NodePort: 30053,
|
|
||||||
}}
|
|
||||||
}),
|
|
||||||
expectSpecifiedNodePorts: []int{30053},
|
expectSpecifiedNodePorts: []int{30053},
|
||||||
}, {
|
}, {
|
||||||
name: "Change protocol of ServicePort without changing NodePort",
|
name: "Change protocol of ServicePort without changing NodePort",
|
||||||
oldService: makeService("foo", tweakTypeNodePort, func(s *api.Service) {
|
oldService: makeService("foo",
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
tweakTypeNodePort,
|
||||||
Name: "port-tcp",
|
tweakPorts(
|
||||||
Port: 53,
|
makeServicePort("port-tcp", 53, intstr.FromInt(6502), api.ProtocolTCP)),
|
||||||
TargetPort: intstr.FromInt(6502),
|
tweakNodePorts(30053)),
|
||||||
Protocol: api.ProtocolTCP,
|
newService: makeService("foo",
|
||||||
NodePort: 30053,
|
tweakTypeNodePort,
|
||||||
}}
|
tweakPorts(
|
||||||
}),
|
makeServicePort("port-udp", 53, intstr.FromInt(6502), api.ProtocolUDP)),
|
||||||
newService: makeService("foo", tweakTypeNodePort, func(s *api.Service) {
|
tweakNodePorts(30053)),
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
|
||||||
Name: "port-udp",
|
|
||||||
Port: 53,
|
|
||||||
TargetPort: intstr.FromInt(6502),
|
|
||||||
Protocol: api.ProtocolUDP,
|
|
||||||
NodePort: 30053,
|
|
||||||
}}
|
|
||||||
}),
|
|
||||||
expectSpecifiedNodePorts: []int{30053},
|
expectSpecifiedNodePorts: []int{30053},
|
||||||
}, {
|
}, {
|
||||||
name: "Should allocate NodePort when changing service type to NodePort",
|
name: "Should allocate NodePort when changing service type to NodePort",
|
||||||
oldService: makeService("foo", tweakTypeNodePort, func(s *api.Service) {
|
oldService: makeService("foo",
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
tweakTypeClusterIP,
|
||||||
Port: 6502,
|
tweakPorts(
|
||||||
Protocol: api.ProtocolTCP,
|
makeServicePort("", 6502, intstr.FromInt(6502), api.ProtocolUDP))),
|
||||||
TargetPort: intstr.FromInt(6502),
|
newService: makeService("foo",
|
||||||
}}
|
tweakTypeNodePort,
|
||||||
}),
|
tweakPorts(
|
||||||
newService: makeService("foo", tweakTypeNodePort, func(s *api.Service) {
|
makeServicePort("", 6502, intstr.FromInt(6502), api.ProtocolUDP))),
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
|
||||||
Port: 6502,
|
|
||||||
Protocol: api.ProtocolTCP,
|
|
||||||
TargetPort: intstr.FromInt(6502),
|
|
||||||
}}
|
|
||||||
}),
|
|
||||||
expectSpecifiedNodePorts: []int{},
|
expectSpecifiedNodePorts: []int{},
|
||||||
}, {
|
}, {
|
||||||
name: "Add new ServicePort with a different protocol without changing port numbers",
|
name: "Add new ServicePort with a different protocol without changing port numbers",
|
||||||
oldService: makeService("foo", tweakTypeNodePort, func(s *api.Service) {
|
oldService: makeService("foo",
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
tweakTypeNodePort,
|
||||||
Name: "port-tcp",
|
tweakPorts(
|
||||||
Port: 53,
|
makeServicePort("port-tcp", 53, intstr.FromInt(6502), api.ProtocolTCP)),
|
||||||
TargetPort: intstr.FromInt(6502),
|
tweakNodePorts(30053)),
|
||||||
Protocol: api.ProtocolTCP,
|
newService: makeService("foo",
|
||||||
NodePort: 30053,
|
tweakTypeNodePort,
|
||||||
}}
|
tweakPorts(
|
||||||
}),
|
makeServicePort("port-tcp", 53, intstr.FromInt(6502), api.ProtocolTCP),
|
||||||
newService: makeService("foo", tweakTypeNodePort, func(s *api.Service) {
|
makeServicePort("port-udp", 53, intstr.FromInt(6502), api.ProtocolUDP)),
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
tweakNodePorts(30053, 30053)),
|
||||||
Name: "port-tcp",
|
|
||||||
Port: 53,
|
|
||||||
TargetPort: intstr.FromInt(6502),
|
|
||||||
Protocol: api.ProtocolTCP,
|
|
||||||
NodePort: 30053,
|
|
||||||
}, {
|
|
||||||
Name: "port-udp",
|
|
||||||
Port: 53,
|
|
||||||
TargetPort: intstr.FromInt(6502),
|
|
||||||
Protocol: api.ProtocolUDP,
|
|
||||||
NodePort: 30053,
|
|
||||||
}}
|
|
||||||
}),
|
|
||||||
expectSpecifiedNodePorts: []int{30053, 30053},
|
expectSpecifiedNodePorts: []int{30053, 30053},
|
||||||
}, {
|
}, {
|
||||||
name: "Change service type from ClusterIP to NodePort with same NodePort number but different protocols",
|
name: "Change service type from ClusterIP to NodePort with same NodePort number but different protocols",
|
||||||
oldService: makeService("foo", tweakTypeNodePort, func(s *api.Service) {
|
oldService: makeService("foo",
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
tweakTypeClusterIP,
|
||||||
Port: 53,
|
tweakPorts(
|
||||||
Protocol: api.ProtocolTCP,
|
makeServicePort("", 53, intstr.FromInt(6502), api.ProtocolTCP))),
|
||||||
TargetPort: intstr.FromInt(6502),
|
newService: makeService("foo",
|
||||||
}}
|
tweakTypeNodePort,
|
||||||
}),
|
tweakPorts(
|
||||||
newService: makeService("foo", tweakTypeNodePort, func(s *api.Service) {
|
makeServicePort("port-tcp", 53, intstr.FromInt(6502), api.ProtocolTCP),
|
||||||
s.Spec.Ports = []api.ServicePort{{
|
makeServicePort("port-udp", 53, intstr.FromInt(6502), api.ProtocolUDP)),
|
||||||
Name: "port-tcp",
|
tweakNodePorts(30053, 30053)),
|
||||||
Port: 53,
|
|
||||||
TargetPort: intstr.FromInt(6502),
|
|
||||||
Protocol: api.ProtocolTCP,
|
|
||||||
NodePort: 30053,
|
|
||||||
}, {
|
|
||||||
Name: "port-udp",
|
|
||||||
Port: 53,
|
|
||||||
TargetPort: intstr.FromInt(6502),
|
|
||||||
Protocol: api.ProtocolUDP,
|
|
||||||
NodePort: 30053,
|
|
||||||
}}
|
|
||||||
}),
|
|
||||||
expectSpecifiedNodePorts: []int{30053, 30053},
|
expectSpecifiedNodePorts: []int{30053, 30053},
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user