@@ -31,7 +31,6 @@ import (
31
31
"k8s.io/apimachinery/pkg/util/diff"
32
32
"k8s.io/apimachinery/pkg/util/intstr"
33
33
utilnet "k8s.io/apimachinery/pkg/util/net"
34
- "k8s.io/apimachinery/pkg/util/rand"
35
34
"k8s.io/apimachinery/pkg/watch"
36
35
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
37
36
"k8s.io/apiserver/pkg/registry/generic"
@@ -173,10 +172,6 @@ func (s *serviceStorage) StorageVersion() runtime.GroupVersioner {
173
172
panic ("not implemented" )
174
173
}
175
174
176
- func generateRandomNodePort () int32 {
177
- return int32 (rand .IntnRange (30001 , 30999 ))
178
- }
179
-
180
175
func NewTestREST (t * testing.T , endpoints * api.EndpointsList , ipFamilies []api.IPFamily ) (* REST , * serviceStorage , * etcd3testing.EtcdTestServer ) {
181
176
return NewTestRESTWithPods (t , endpoints , nil , ipFamilies )
182
177
}
@@ -2192,7 +2187,6 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortAllocation(t *testing.
2192
2187
// Validate using the user specified nodePort when ExternalTrafficPolicy is set to Local
2193
2188
// and type is LoadBalancer.
2194
2189
func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation (t * testing.T ) {
2195
- randomNodePort := generateRandomNodePort ()
2196
2190
ctx := genericapirequest .NewDefaultContext ()
2197
2191
storage , registry , server := NewTestREST (t , nil , singleStackIPv4 )
2198
2192
defer server .Terminate (t )
@@ -2206,9 +2200,12 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation(t *test
2206
2200
Port : 6502 ,
2207
2201
Protocol : api .ProtocolTCP ,
2208
2202
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 ,
2209
2206
}},
2210
2207
ExternalTrafficPolicy : api .ServiceExternalTrafficPolicyTypeLocal ,
2211
- HealthCheckNodePort : randomNodePort ,
2208
+ HealthCheckNodePort : 30501 ,
2212
2209
},
2213
2210
}
2214
2211
createdSvc , err := storage .Create (ctx , svc , rest .ValidateAllObjectFunc , & metav1.CreateOptions {})
@@ -2225,8 +2222,8 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation(t *test
2225
2222
if port == 0 {
2226
2223
t .Errorf ("Failed to allocate health check node port and set the HealthCheckNodePort" )
2227
2224
}
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 )
2230
2227
}
2231
2228
if port != 0 {
2232
2229
// Release the health check node port at the end of the test case.
0 commit comments