From 68dd0b7f27dd5212f6186c02cee7dc527158df81 Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Thu, 3 Sep 2020 15:46:07 -0400 Subject: [PATCH] Deflake TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation --- pkg/registry/core/service/storage/BUILD | 1 - pkg/registry/core/service/storage/rest_test.go | 15 ++++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/pkg/registry/core/service/storage/BUILD b/pkg/registry/core/service/storage/BUILD index feb59391435..69c036254e5 100644 --- a/pkg/registry/core/service/storage/BUILD +++ b/pkg/registry/core/service/storage/BUILD @@ -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", diff --git a/pkg/registry/core/service/storage/rest_test.go b/pkg/registry/core/service/storage/rest_test.go index c095a8fbce5..c5cf97a62af 100644 --- a/pkg/registry/core/service/storage/rest_test.go +++ b/pkg/registry/core/service/storage/rest_test.go @@ -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.