Merge pull request #94488 from liggitt/deflake-port-allocation

Deflake TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation
This commit is contained in:
Kubernetes Prow Robot 2020-09-03 18:57:42 -07:00 committed by GitHub
commit 608c0265a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 10 deletions

View File

@ -32,7 +32,6 @@ go_test(
"//staging/src/k8s.io/apimachinery/pkg/util/diff:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/net:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/rand:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/registry/generic:go_default_library",

View File

@ -31,7 +31,6 @@ import (
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/intstr"
utilnet "k8s.io/apimachinery/pkg/util/net"
"k8s.io/apimachinery/pkg/util/rand"
"k8s.io/apimachinery/pkg/watch"
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
@ -173,10 +172,6 @@ func (s *serviceStorage) StorageVersion() runtime.GroupVersioner {
panic("not implemented")
}
func generateRandomNodePort() int32 {
return int32(rand.IntnRange(30001, 30999))
}
func NewTestREST(t *testing.T, endpoints *api.EndpointsList, ipFamilies []api.IPFamily) (*REST, *serviceStorage, *etcd3testing.EtcdTestServer) {
return NewTestRESTWithPods(t, endpoints, nil, ipFamilies)
}
@ -2192,7 +2187,6 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortAllocation(t *testing.
// Validate using the user specified nodePort when ExternalTrafficPolicy is set to Local
// and type is LoadBalancer.
func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation(t *testing.T) {
randomNodePort := generateRandomNodePort()
ctx := genericapirequest.NewDefaultContext()
storage, registry, server := NewTestREST(t, nil, singleStackIPv4)
defer server.Terminate(t)
@ -2206,9 +2200,12 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation(t *test
Port: 6502,
Protocol: api.ProtocolTCP,
TargetPort: intstr.FromInt(6502),
// hard-code NodePort to make sure it doesn't conflict with the healthport.
// TODO: remove this once http://issue.k8s.io/93922 fixes auto-allocation conflicting with user-specified health check ports
NodePort: 30500,
}},
ExternalTrafficPolicy: api.ServiceExternalTrafficPolicyTypeLocal,
HealthCheckNodePort: randomNodePort,
HealthCheckNodePort: 30501,
},
}
createdSvc, err := storage.Create(ctx, svc, rest.ValidateAllObjectFunc, &metav1.CreateOptions{})
@ -2225,8 +2222,8 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation(t *test
if port == 0 {
t.Errorf("Failed to allocate health check node port and set the HealthCheckNodePort")
}
if port != randomNodePort {
t.Errorf("Failed to allocate requested nodePort expected %d, got %d", randomNodePort, port)
if port != 30501 {
t.Errorf("Failed to allocate requested nodePort expected %d, got %d", 30501, port)
}
if port != 0 {
// Release the health check node port at the end of the test case.