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

Merge pull request #43585 from foolusion/add-health-check-node-port-to-aws-loadbalancer

Automatic merge from submit-queue AWS: support node port health check **What this PR does / why we need it**: if a custom health check is set from the beta annotation on a service it should be used for the ELB health check. This patch adds support for that. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: Let me know if any tests need to be added. **Release note**: ```release-note ```
parents d6cc1de9 e397ca4b
...@@ -2804,9 +2804,28 @@ func (c *Cloud) EnsureLoadBalancer(clusterName string, apiService *v1.Service, n ...@@ -2804,9 +2804,28 @@ func (c *Cloud) EnsureLoadBalancer(clusterName string, apiService *v1.Service, n
return nil, err return nil, err
} }
err = c.ensureLoadBalancerHealthCheck(loadBalancer, listeners) if path, healthCheckNodePort := service.GetServiceHealthCheckPathPort(apiService); path != "" {
if err != nil { glog.V(4).Infof("service %v (%v) needs health checks on :%d%s)", apiService.Name, loadBalancerName, healthCheckNodePort, path)
return nil, err err = c.ensureLoadBalancerHealthCheck(loadBalancer, "HTTP", healthCheckNodePort, path)
if err != nil {
return nil, fmt.Errorf("Failed to ensure health check for localized service %v on node port %v: %v", loadBalancerName, healthCheckNodePort, err)
}
} else {
glog.V(4).Infof("service %v does not need custom health checks", apiService.Name)
// We only configure a TCP health-check on the first port
var tcpHealthCheckPort int32
for _, listener := range listeners {
if listener.InstancePort == nil {
continue
}
tcpHealthCheckPort = int32(*listener.InstancePort)
break
}
// there must be no path on TCP health check
err = c.ensureLoadBalancerHealthCheck(loadBalancer, "TCP", tcpHealthCheckPort, "")
if err != nil {
return nil, err
}
} }
err = c.updateInstanceSecurityGroupsForLoadBalancer(loadBalancer, instances) err = c.updateInstanceSecurityGroupsForLoadBalancer(loadBalancer, instances)
......
...@@ -355,8 +355,8 @@ func (c *Cloud) ensureLoadBalancer(namespacedName types.NamespacedName, loadBala ...@@ -355,8 +355,8 @@ func (c *Cloud) ensureLoadBalancer(namespacedName types.NamespacedName, loadBala
return loadBalancer, nil return loadBalancer, nil
} }
// Makes sure that the health check for an ELB matches the configured listeners // Makes sure that the health check for an ELB matches the configured health check node port
func (c *Cloud) ensureLoadBalancerHealthCheck(loadBalancer *elb.LoadBalancerDescription, listeners []*elb.Listener) error { func (c *Cloud) ensureLoadBalancerHealthCheck(loadBalancer *elb.LoadBalancerDescription, protocol string, port int32, path string) error {
name := aws.StringValue(loadBalancer.LoadBalancerName) name := aws.StringValue(loadBalancer.LoadBalancerName)
actual := loadBalancer.HealthCheck actual := loadBalancer.HealthCheck
...@@ -367,19 +367,7 @@ func (c *Cloud) ensureLoadBalancerHealthCheck(loadBalancer *elb.LoadBalancerDesc ...@@ -367,19 +367,7 @@ func (c *Cloud) ensureLoadBalancerHealthCheck(loadBalancer *elb.LoadBalancerDesc
expectedTimeout := int64(5) expectedTimeout := int64(5)
expectedInterval := int64(10) expectedInterval := int64(10)
// We only configure a TCP health-check on the first port expectedTarget := protocol + ":" + strconv.FormatInt(int64(port), 10) + path
expectedTarget := ""
for _, listener := range listeners {
if listener.InstancePort == nil {
continue
}
expectedTarget = "TCP:" + strconv.FormatInt(*listener.InstancePort, 10)
break
}
if expectedTarget == "" {
return fmt.Errorf("unable to determine health check port for %q (no valid listeners)", name)
}
if expectedTarget == orEmpty(actual.Target) && if expectedTarget == orEmpty(actual.Target) &&
expectedHealthyThreshold == orZero(actual.HealthyThreshold) && expectedHealthyThreshold == orZero(actual.HealthyThreshold) &&
......
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