mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
test/integration: add helper function serviceHasNodePorts for service load balancer tests
Signed-off-by: Andrew Sy Kim <kim.andrewsy@gmail.com>
This commit is contained in:
parent
c1285ac83b
commit
a5aba23813
@ -70,14 +70,7 @@ func Test_ServiceLoadBalancerDisableAllocateNodePorts(t *testing.T) {
|
||||
t.Fatalf("Error creating test service: %v", err)
|
||||
}
|
||||
|
||||
foundNodePorts := false
|
||||
for _, port := range service.Spec.Ports {
|
||||
if port.NodePort > 0 {
|
||||
foundNodePorts = true
|
||||
}
|
||||
}
|
||||
|
||||
if foundNodePorts {
|
||||
if serviceHasNodePorts(service) {
|
||||
t.Error("found node ports when none was expected")
|
||||
}
|
||||
}
|
||||
@ -121,14 +114,7 @@ func Test_ServiceLoadBalancerEnableThenDisableAllocatedNodePorts(t *testing.T) {
|
||||
t.Fatalf("Error creating test service: %v", err)
|
||||
}
|
||||
|
||||
foundNodePorts := false
|
||||
for _, port := range service.Spec.Ports {
|
||||
if port.NodePort > 0 {
|
||||
foundNodePorts = true
|
||||
}
|
||||
}
|
||||
|
||||
if !foundNodePorts {
|
||||
if !serviceHasNodePorts(service) {
|
||||
t.Error("expected node ports but found none")
|
||||
}
|
||||
|
||||
@ -138,14 +124,17 @@ func Test_ServiceLoadBalancerEnableThenDisableAllocatedNodePorts(t *testing.T) {
|
||||
t.Fatalf("Error updating test service: %v", err)
|
||||
}
|
||||
|
||||
foundNodePorts = false
|
||||
for _, port := range service.Spec.Ports {
|
||||
if port.NodePort > 0 {
|
||||
foundNodePorts = true
|
||||
}
|
||||
}
|
||||
|
||||
if !foundNodePorts {
|
||||
if !serviceHasNodePorts(service) {
|
||||
t.Error("node ports were unexpectedly deallocated")
|
||||
}
|
||||
}
|
||||
|
||||
func serviceHasNodePorts(svc *corev1.Service) bool {
|
||||
for _, port := range svc.Spec.Ports {
|
||||
if port.NodePort > 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user