mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 08:17:26 +00:00
Merge pull request #94488 from liggitt/deflake-port-allocation
Deflake TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation
This commit is contained in:
commit
608c0265a8
@ -32,7 +32,6 @@ go_test(
|
|||||||
"//staging/src/k8s.io/apimachinery/pkg/util/diff:go_default_library",
|
"//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/intstr:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/net: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/apimachinery/pkg/watch:go_default_library",
|
||||||
"//staging/src/k8s.io/apiserver/pkg/endpoints/request: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",
|
"//staging/src/k8s.io/apiserver/pkg/registry/generic:go_default_library",
|
||||||
|
@ -31,7 +31,6 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/util/diff"
|
"k8s.io/apimachinery/pkg/util/diff"
|
||||||
"k8s.io/apimachinery/pkg/util/intstr"
|
"k8s.io/apimachinery/pkg/util/intstr"
|
||||||
utilnet "k8s.io/apimachinery/pkg/util/net"
|
utilnet "k8s.io/apimachinery/pkg/util/net"
|
||||||
"k8s.io/apimachinery/pkg/util/rand"
|
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
|
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
|
||||||
"k8s.io/apiserver/pkg/registry/generic"
|
"k8s.io/apiserver/pkg/registry/generic"
|
||||||
@ -173,10 +172,6 @@ func (s *serviceStorage) StorageVersion() runtime.GroupVersioner {
|
|||||||
panic("not implemented")
|
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) {
|
func NewTestREST(t *testing.T, endpoints *api.EndpointsList, ipFamilies []api.IPFamily) (*REST, *serviceStorage, *etcd3testing.EtcdTestServer) {
|
||||||
return NewTestRESTWithPods(t, endpoints, nil, ipFamilies)
|
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
|
// Validate using the user specified nodePort when ExternalTrafficPolicy is set to Local
|
||||||
// and type is LoadBalancer.
|
// and type is LoadBalancer.
|
||||||
func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation(t *testing.T) {
|
func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation(t *testing.T) {
|
||||||
randomNodePort := generateRandomNodePort()
|
|
||||||
ctx := genericapirequest.NewDefaultContext()
|
ctx := genericapirequest.NewDefaultContext()
|
||||||
storage, registry, server := NewTestREST(t, nil, singleStackIPv4)
|
storage, registry, server := NewTestREST(t, nil, singleStackIPv4)
|
||||||
defer server.Terminate(t)
|
defer server.Terminate(t)
|
||||||
@ -2206,9 +2200,12 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation(t *test
|
|||||||
Port: 6502,
|
Port: 6502,
|
||||||
Protocol: api.ProtocolTCP,
|
Protocol: api.ProtocolTCP,
|
||||||
TargetPort: intstr.FromInt(6502),
|
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,
|
ExternalTrafficPolicy: api.ServiceExternalTrafficPolicyTypeLocal,
|
||||||
HealthCheckNodePort: randomNodePort,
|
HealthCheckNodePort: 30501,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
createdSvc, err := storage.Create(ctx, svc, rest.ValidateAllObjectFunc, &metav1.CreateOptions{})
|
createdSvc, err := storage.Create(ctx, svc, rest.ValidateAllObjectFunc, &metav1.CreateOptions{})
|
||||||
@ -2225,8 +2222,8 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation(t *test
|
|||||||
if port == 0 {
|
if port == 0 {
|
||||||
t.Errorf("Failed to allocate health check node port and set the HealthCheckNodePort")
|
t.Errorf("Failed to allocate health check node port and set the HealthCheckNodePort")
|
||||||
}
|
}
|
||||||
if port != randomNodePort {
|
if port != 30501 {
|
||||||
t.Errorf("Failed to allocate requested nodePort expected %d, got %d", randomNodePort, port)
|
t.Errorf("Failed to allocate requested nodePort expected %d, got %d", 30501, port)
|
||||||
}
|
}
|
||||||
if port != 0 {
|
if port != 0 {
|
||||||
// Release the health check node port at the end of the test case.
|
// Release the health check node port at the end of the test case.
|
||||||
|
Loading…
Reference in New Issue
Block a user