@@ -172,6 +172,23 @@ func (s *Service) getAPIServerLBSpec(elbName string, lbSpec *infrav1.AWSLoadBala
172172 scheme = * lbSpec .Scheme
173173 }
174174
175+ // The default API health check is TCP, allowing customization to HTTP or HTTPS when HealthCheckProtocol is set.
176+ apiHealthCheckProtocol := infrav1 .ELBProtocolTCP
177+ if lbSpec != nil && lbSpec .HealthCheckProtocol != nil {
178+ s .scope .Trace ("Found API health check protocol override in the Load Balancer spec, applying it to the API Target Group" , "api-server-elb" , lbSpec .HealthCheckProtocol )
179+ apiHealthCheckProtocol = * lbSpec .HealthCheckProtocol
180+ }
181+ apiHealthCheck := & infrav1.TargetGroupHealthCheck {
182+ Protocol : aws .String (apiHealthCheckProtocol .String ()),
183+ Port : aws .String (infrav1 .DefaultAPIServerPortString ),
184+ Path : nil ,
185+ IntervalSeconds : aws .Int64 (infrav1 .DefaultAPIServerHealthCheckIntervalSec ),
186+ TimeoutSeconds : aws .Int64 (infrav1 .DefaultAPIServerHealthCheckTimeoutSec ),
187+ ThresholdCount : aws .Int64 (infrav1 .DefaultAPIServerHealthThresholdCount ),
188+ }
189+ if apiHealthCheckProtocol == infrav1 .ELBProtocolHTTP || apiHealthCheckProtocol == infrav1 .ELBProtocolHTTPS {
190+ apiHealthCheck .Path = aws .String (infrav1 .DefaultAPIServerHealthCheckPath )
191+ }
175192 res := & infrav1.LoadBalancer {
176193 Name : elbName ,
177194 Scheme : scheme ,
@@ -181,14 +198,11 @@ func (s *Service) getAPIServerLBSpec(elbName string, lbSpec *infrav1.AWSLoadBala
181198 Protocol : infrav1 .ELBProtocolTCP ,
182199 Port : infrav1 .DefaultAPIServerPort ,
183200 TargetGroup : infrav1.TargetGroupSpec {
184- Name : fmt .Sprintf ("apiserver-target-%d" , time .Now ().Unix ()),
185- Port : infrav1 .DefaultAPIServerPort ,
186- Protocol : infrav1 .ELBProtocolTCP ,
187- VpcID : s .scope .VPC ().ID ,
188- HealthCheck : & infrav1.TargetGroupHealthCheck {
189- Protocol : aws .String (string (infrav1 .ELBProtocolTCP )),
190- Port : aws .String (infrav1 .DefaultAPIServerPortString ),
191- },
201+ Name : fmt .Sprintf ("apiserver-target-%d" , time .Now ().Unix ()),
202+ Port : infrav1 .DefaultAPIServerPort ,
203+ Protocol : infrav1 .ELBProtocolTCP ,
204+ VpcID : s .scope .VPC ().ID ,
205+ HealthCheck : apiHealthCheck ,
192206 },
193207 },
194208 },
@@ -321,6 +335,19 @@ func (s *Service) createLB(spec *infrav1.LoadBalancer, lbSpec *infrav1.AWSLoadBa
321335 targetGroupInput .HealthCheckEnabled = aws .Bool (true )
322336 targetGroupInput .HealthCheckProtocol = ln .TargetGroup .HealthCheck .Protocol
323337 targetGroupInput .HealthCheckPort = ln .TargetGroup .HealthCheck .Port
338+ targetGroupInput .UnhealthyThresholdCount = aws .Int64 (infrav1 .DefaultAPIServerUnhealthThresholdCount )
339+ if ln .TargetGroup .HealthCheck .Path != nil {
340+ targetGroupInput .HealthCheckPath = ln .TargetGroup .HealthCheck .Path
341+ }
342+ if ln .TargetGroup .HealthCheck .IntervalSeconds != nil {
343+ targetGroupInput .HealthCheckIntervalSeconds = ln .TargetGroup .HealthCheck .IntervalSeconds
344+ }
345+ if ln .TargetGroup .HealthCheck .TimeoutSeconds != nil {
346+ targetGroupInput .HealthCheckTimeoutSeconds = ln .TargetGroup .HealthCheck .TimeoutSeconds
347+ }
348+ if ln .TargetGroup .HealthCheck .ThresholdCount != nil {
349+ targetGroupInput .HealthyThresholdCount = ln .TargetGroup .HealthCheck .ThresholdCount
350+ }
324351 }
325352 s .scope .Debug ("creating target group" , "group" , targetGroupInput , "listener" , ln )
326353 group , err := s .ELBV2Client .CreateTargetGroup (targetGroupInput )
@@ -1007,10 +1034,10 @@ func (s *Service) getAPIServerClassicELBSpec(elbName string) (*infrav1.LoadBalan
10071034 },
10081035 HealthCheck : & infrav1.ClassicELBHealthCheck {
10091036 Target : s .getHealthCheckTarget (),
1010- Interval : 10 * time .Second ,
1011- Timeout : 5 * time .Second ,
1012- HealthyThreshold : 5 ,
1013- UnhealthyThreshold : 3 ,
1037+ Interval : infrav1 . DefaultAPIServerHealthCheckIntervalSec * time .Second ,
1038+ Timeout : infrav1 . DefaultAPIServerHealthCheckTimeoutSec * time .Second ,
1039+ HealthyThreshold : infrav1 . DefaultAPIServerHealthThresholdCount ,
1040+ UnhealthyThreshold : infrav1 . DefaultAPIServerUnhealthThresholdCount ,
10141041 },
10151042 SecurityGroupIDs : securityGroupIDs ,
10161043 ClassicElbAttributes : infrav1.ClassicELBAttributes {
@@ -1506,7 +1533,7 @@ func (s *Service) getHealthCheckTarget() string {
15061533 if controlPlaneELB != nil && controlPlaneELB .HealthCheckProtocol != nil {
15071534 protocol = controlPlaneELB .HealthCheckProtocol
15081535 if protocol .String () == infrav1 .ELBProtocolHTTP .String () || protocol .String () == infrav1 .ELBProtocolHTTPS .String () {
1509- return fmt .Sprintf ("%v:%d/readyz " , protocol , infrav1 .DefaultAPIServerPort )
1536+ return fmt .Sprintf ("%v:%d%s " , protocol , infrav1 .DefaultAPIServerPort , infrav1 . DefaultAPIServerHealthCheckPath )
15101537 }
15111538 }
15121539 return fmt .Sprintf ("%v:%d" , protocol , infrav1 .DefaultAPIServerPort )
0 commit comments