func()

in pkg/providers/v1/aws.go [4100:4155]


func (c *Cloud) buildNLBHealthCheckConfiguration(svc *v1.Service) (healthCheckConfig, error) {
	hc := healthCheckConfig{
		Port:               defaultHealthCheckPort,
		Path:               defaultHealthCheckPath,
		Protocol:           elbv2.ProtocolEnumTcp,
		Interval:           defaultNlbHealthCheckInterval,
		Timeout:            defaultNlbHealthCheckTimeout,
		HealthyThreshold:   defaultNlbHealthCheckThreshold,
		UnhealthyThreshold: defaultNlbHealthCheckThreshold,
	}
	if svc.Spec.ExternalTrafficPolicy == v1.ServiceExternalTrafficPolicyTypeLocal {
		path, port := servicehelpers.GetServiceHealthCheckPathPort(svc)
		hc = healthCheckConfig{
			Port:               strconv.Itoa(int(port)),
			Path:               path,
			Protocol:           elbv2.ProtocolEnumHttp,
			Interval:           10,
			Timeout:            10,
			HealthyThreshold:   2,
			UnhealthyThreshold: 2,
		}
	}
	if parseStringAnnotation(svc.Annotations, ServiceAnnotationLoadBalancerHealthCheckProtocol, &hc.Protocol) {
		hc.Protocol = strings.ToUpper(hc.Protocol)
	}
	switch hc.Protocol {
	case elbv2.ProtocolEnumHttp, elbv2.ProtocolEnumHttps:
		parseStringAnnotation(svc.Annotations, ServiceAnnotationLoadBalancerHealthCheckPath, &hc.Path)
	case elbv2.ProtocolEnumTcp:
		hc.Path = ""
	default:
		return healthCheckConfig{}, fmt.Errorf("Unsupported health check protocol %v", hc.Protocol)
	}

	parseStringAnnotation(svc.Annotations, ServiceAnnotationLoadBalancerHealthCheckPort, &hc.Port)

	if _, err := parseInt64Annotation(svc.Annotations, ServiceAnnotationLoadBalancerHCInterval, &hc.Interval); err != nil {
		return healthCheckConfig{}, err
	}
	if _, err := parseInt64Annotation(svc.Annotations, ServiceAnnotationLoadBalancerHCTimeout, &hc.Timeout); err != nil {
		return healthCheckConfig{}, err
	}
	if _, err := parseInt64Annotation(svc.Annotations, ServiceAnnotationLoadBalancerHCHealthyThreshold, &hc.HealthyThreshold); err != nil {
		return healthCheckConfig{}, err
	}
	if _, err := parseInt64Annotation(svc.Annotations, ServiceAnnotationLoadBalancerHCUnhealthyThreshold, &hc.UnhealthyThreshold); err != nil {
		return healthCheckConfig{}, err
	}

	if hc.Port != defaultHealthCheckPort {
		if _, err := strconv.ParseInt(hc.Port, 10, 0); err != nil {
			return healthCheckConfig{}, fmt.Errorf("Invalid health check port '%v'", hc.Port)
		}
	}
	return hc, nil
}