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:
carlory
2025-08-08 15:41:09 +08:00
parent 8e6d788887
commit 233384d4e4
2 changed files with 16 additions and 1 deletions

View File

@@ -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)
}

View File

@@ -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)