Commit b787acec authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #49099 from xiangpengzhao/fix-healthcheck-flake

Automatic merge from submit-queue (batch tested with PRs 48914, 48535, 49099, 48935, 48871) Fix health check node port test flake **What this PR does / why we need it**: - Releases the allocated HealthCheck NodePort at the end of each associated test case. - Fixes the weird output `0` in `failed to allocate requested HealthCheck NodePort 0` **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #49098 **Special notes for your reviewer**: /cc @freehan **Release note**: ```release-note NONE ```
parents 94c3c571 d765f91c
...@@ -544,9 +544,9 @@ func (rs *REST) allocateHealthCheckNodePort(service *api.Service) error { ...@@ -544,9 +544,9 @@ func (rs *REST) allocateHealthCheckNodePort(service *api.Service) error {
err := rs.serviceNodePorts.Allocate(int(healthCheckNodePort)) err := rs.serviceNodePorts.Allocate(int(healthCheckNodePort))
if err != nil { if err != nil {
return fmt.Errorf("failed to allocate requested HealthCheck NodePort %v: %v", return fmt.Errorf("failed to allocate requested HealthCheck NodePort %v: %v",
service.Spec.HealthCheckNodePort, err) healthCheckNodePort, err)
} }
glog.Infof("Reserved user requested nodePort: %d", service.Spec.HealthCheckNodePort) glog.Infof("Reserved user requested nodePort: %d", healthCheckNodePort)
} else { } else {
// If the request has no health check nodePort specified, allocate any. // If the request has no health check nodePort specified, allocate any.
healthCheckNodePort, err := rs.serviceNodePorts.AllocateNext() healthCheckNodePort, err := rs.serviceNodePorts.AllocateNext()
......
...@@ -996,8 +996,10 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortAllocation(t *testing. ...@@ -996,8 +996,10 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortAllocation(t *testing.
port := service.GetServiceHealthCheckNodePort(created_service) port := service.GetServiceHealthCheckNodePort(created_service)
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")
} else {
// Release the node port at the end of the test case.
storage.serviceNodePorts.Release(int(port))
} }
} }
// Validate allocation of a nodePort when ExternalTraffic beta annotation is set to OnlyLocal // Validate allocation of a nodePort when ExternalTraffic beta annotation is set to OnlyLocal
...@@ -1034,8 +1036,10 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortAllocationBeta(t *test ...@@ -1034,8 +1036,10 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortAllocationBeta(t *test
port := service.GetServiceHealthCheckNodePort(created_service) port := service.GetServiceHealthCheckNodePort(created_service)
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")
} else {
// Release the node port at the end of the test case.
storage.serviceNodePorts.Release(int(port))
} }
} }
// Validate using the user specified nodePort when ExternalTrafficPolicy is set to Local // Validate using the user specified nodePort when ExternalTrafficPolicy is set to Local
...@@ -1074,6 +1078,11 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation(t *test ...@@ -1074,6 +1078,11 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation(t *test
if port != randomNodePort { if port != randomNodePort {
t.Errorf("Failed to allocate requested nodePort expected %d, got %d", randomNodePort, port) t.Errorf("Failed to allocate requested nodePort expected %d, got %d", randomNodePort, port)
} }
if port != 0 {
// Release the node port at the end of the test case.
storage.serviceNodePorts.Release(int(port))
}
} }
// Validate using the user specified nodePort when ExternalTraffic beta annotation is set to OnlyLocal // Validate using the user specified nodePort when ExternalTraffic beta annotation is set to OnlyLocal
...@@ -1116,6 +1125,11 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocationBeta(t * ...@@ -1116,6 +1125,11 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocationBeta(t *
if port != randomNodePort { if port != randomNodePort {
t.Errorf("Failed to allocate requested nodePort expected %d, got %d", randomNodePort, port) t.Errorf("Failed to allocate requested nodePort expected %d, got %d", randomNodePort, port)
} }
if port != 0 {
// Release the node port at the end of the test case.
storage.serviceNodePorts.Release(int(port))
}
} }
// Validate that the service creation fails when the requested port number is -1. // Validate that the service creation fails when the requested port number is -1.
...@@ -1203,6 +1217,8 @@ func TestServiceRegistryExternalTrafficGlobal(t *testing.T) { ...@@ -1203,6 +1217,8 @@ func TestServiceRegistryExternalTrafficGlobal(t *testing.T) {
// Make sure the service does not have the health check node port allocated // Make sure the service does not have the health check node port allocated
port := service.GetServiceHealthCheckNodePort(created_service) port := service.GetServiceHealthCheckNodePort(created_service)
if port != 0 { if port != 0 {
// Release the node port at the end of the test case.
storage.serviceNodePorts.Release(int(port))
t.Errorf("Unexpected allocation of health check node port: %v", port) t.Errorf("Unexpected allocation of health check node port: %v", port)
} }
} }
...@@ -1240,6 +1256,8 @@ func TestServiceRegistryExternalTrafficGlobalBeta(t *testing.T) { ...@@ -1240,6 +1256,8 @@ func TestServiceRegistryExternalTrafficGlobalBeta(t *testing.T) {
// Make sure the service does not have the health check node port allocated // Make sure the service does not have the health check node port allocated
port := service.GetServiceHealthCheckNodePort(created_service) port := service.GetServiceHealthCheckNodePort(created_service)
if port != 0 { if port != 0 {
// Release the node port at the end of the test case.
storage.serviceNodePorts.Release(int(port))
t.Errorf("Unexpected allocation of health check node port: %v", port) t.Errorf("Unexpected allocation of health check node port: %v", port)
} }
} }
...@@ -1273,6 +1291,8 @@ func TestServiceRegistryExternalTrafficAnnotationClusterIP(t *testing.T) { ...@@ -1273,6 +1291,8 @@ func TestServiceRegistryExternalTrafficAnnotationClusterIP(t *testing.T) {
// Make sure that ClusterIP services do not have the health check node port allocated // Make sure that ClusterIP services do not have the health check node port allocated
port := service.GetServiceHealthCheckNodePort(created_service) port := service.GetServiceHealthCheckNodePort(created_service)
if port != 0 { if port != 0 {
// Release the node port at the end of the test case.
storage.serviceNodePorts.Release(int(port))
t.Errorf("Unexpected allocation of health check node port annotation %s", api.BetaAnnotationHealthCheckNodePort) t.Errorf("Unexpected allocation of health check node port annotation %s", api.BetaAnnotationHealthCheckNodePort)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment