mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-08-08 15:25:26 +00:00
deflake e2e test: Services should implement NodePort and HealthCheckNodePort correctly when ExternalTrafficPolicy changes
Signed-off-by: carlory <baofa.fan@daocloud.io>
This commit is contained in:
@@ -169,6 +169,15 @@ func ReserveStaticNodePort(port int32) bool {
|
||||
// ReleaseStaticNodePort releases the specified port.
|
||||
// The corresponding service should have already been deleted, to ensure that the
|
||||
// port allocator doesn't try to reuse it before the apiserver considers it available.
|
||||
// The caller should do it like below:
|
||||
//
|
||||
// ginkgo.DeferCleanup(func(ctx context.Context) {
|
||||
// err := cs.CoreV1().Services(ns).Delete(ctx, serviceName, metav1.DeleteOptions{})
|
||||
// if err != nil && !apierrors.IsNotFound(err) {
|
||||
// framework.ExpectNoError(err, "failed to delete service %s in namespace %s", serviceName, ns)
|
||||
// }
|
||||
// e2eservice.ReleaseStaticNodePort(nodePort)
|
||||
// })
|
||||
func ReleaseStaticNodePort(port int32) {
|
||||
staticPortAllocator.releasePort(port)
|
||||
}
|
||||
|
||||
@@ -1747,7 +1747,13 @@ var _ = common.SIGDescribe("Services", func() {
|
||||
}
|
||||
|
||||
nodePort := service.Spec.Ports[0].NodePort
|
||||
defer e2eservice.ReleaseStaticNodePort(nodePort)
|
||||
ginkgo.DeferCleanup(func(ctx context.Context) {
|
||||
err := cs.CoreV1().Services(ns).Delete(ctx, serviceName, metav1.DeleteOptions{})
|
||||
if err != nil && !apierrors.IsNotFound(err) {
|
||||
framework.ExpectNoError(err, "failed to delete service %s in namespace %s", serviceName, ns)
|
||||
}
|
||||
e2eservice.ReleaseStaticNodePort(nodePort)
|
||||
})
|
||||
|
||||
if service.Spec.Type != v1.ServiceTypeNodePort {
|
||||
framework.Failf("got unexpected Spec.Type for new service: %v", service)
|
||||
|
||||
Reference in New Issue
Block a user