Skip to content

Commit 608c026

Browse files
authored
Merge pull request kubernetes#94488 from liggitt/deflake-port-allocation
Deflake TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation
2 parents a9f1d72 + 68dd0b7 commit 608c026

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

pkg/registry/core/service/storage/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ go_test(
3232
"//staging/src/k8s.io/apimachinery/pkg/util/diff:go_default_library",
3333
"//staging/src/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
3434
"//staging/src/k8s.io/apimachinery/pkg/util/net:go_default_library",
35-
"//staging/src/k8s.io/apimachinery/pkg/util/rand:go_default_library",
3635
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
3736
"//staging/src/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
3837
"//staging/src/k8s.io/apiserver/pkg/registry/generic:go_default_library",

pkg/registry/core/service/storage/rest_test.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
"k8s.io/apimachinery/pkg/util/diff"
3232
"k8s.io/apimachinery/pkg/util/intstr"
3333
utilnet "k8s.io/apimachinery/pkg/util/net"
34-
"k8s.io/apimachinery/pkg/util/rand"
3534
"k8s.io/apimachinery/pkg/watch"
3635
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
3736
"k8s.io/apiserver/pkg/registry/generic"
@@ -173,10 +172,6 @@ func (s *serviceStorage) StorageVersion() runtime.GroupVersioner {
173172
panic("not implemented")
174173
}
175174

176-
func generateRandomNodePort() int32 {
177-
return int32(rand.IntnRange(30001, 30999))
178-
}
179-
180175
func NewTestREST(t *testing.T, endpoints *api.EndpointsList, ipFamilies []api.IPFamily) (*REST, *serviceStorage, *etcd3testing.EtcdTestServer) {
181176
return NewTestRESTWithPods(t, endpoints, nil, ipFamilies)
182177
}
@@ -2192,7 +2187,6 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortAllocation(t *testing.
21922187
// Validate using the user specified nodePort when ExternalTrafficPolicy is set to Local
21932188
// and type is LoadBalancer.
21942189
func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation(t *testing.T) {
2195-
randomNodePort := generateRandomNodePort()
21962190
ctx := genericapirequest.NewDefaultContext()
21972191
storage, registry, server := NewTestREST(t, nil, singleStackIPv4)
21982192
defer server.Terminate(t)
@@ -2206,9 +2200,12 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation(t *test
22062200
Port: 6502,
22072201
Protocol: api.ProtocolTCP,
22082202
TargetPort: intstr.FromInt(6502),
2203+
// hard-code NodePort to make sure it doesn't conflict with the healthport.
2204+
// TODO: remove this once http://issue.k8s.io/93922 fixes auto-allocation conflicting with user-specified health check ports
2205+
NodePort: 30500,
22092206
}},
22102207
ExternalTrafficPolicy: api.ServiceExternalTrafficPolicyTypeLocal,
2211-
HealthCheckNodePort: randomNodePort,
2208+
HealthCheckNodePort: 30501,
22122209
},
22132210
}
22142211
createdSvc, err := storage.Create(ctx, svc, rest.ValidateAllObjectFunc, &metav1.CreateOptions{})
@@ -2225,8 +2222,8 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation(t *test
22252222
if port == 0 {
22262223
t.Errorf("Failed to allocate health check node port and set the HealthCheckNodePort")
22272224
}
2228-
if port != randomNodePort {
2229-
t.Errorf("Failed to allocate requested nodePort expected %d, got %d", randomNodePort, port)
2225+
if port != 30501 {
2226+
t.Errorf("Failed to allocate requested nodePort expected %d, got %d", 30501, port)
22302227
}
22312228
if port != 0 {
22322229
// Release the health check node port at the end of the test case.

0 commit comments

Comments
 (0)