Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deflake TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation #94488

Merged
merged 1 commit into from Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion pkg/registry/core/service/storage/BUILD
Expand Up @@ -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",
Expand Down
15 changes: 6 additions & 9 deletions pkg/registry/core/service/storage/rest_test.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand All @@ -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{})
Expand All @@ -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.
Expand Down