@@ -172,6 +172,23 @@ func (s *Service) getAPIServerLBSpec(elbName string, lbSpec *infrav1.AWSLoadBala
172
172
scheme = * lbSpec .Scheme
173
173
}
174
174
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
+ }
175
192
res := & infrav1.LoadBalancer {
176
193
Name : elbName ,
177
194
Scheme : scheme ,
@@ -181,14 +198,11 @@ func (s *Service) getAPIServerLBSpec(elbName string, lbSpec *infrav1.AWSLoadBala
181
198
Protocol : infrav1 .ELBProtocolTCP ,
182
199
Port : infrav1 .DefaultAPIServerPort ,
183
200
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 ,
192
206
},
193
207
},
194
208
},
@@ -321,6 +335,19 @@ func (s *Service) createLB(spec *infrav1.LoadBalancer, lbSpec *infrav1.AWSLoadBa
321
335
targetGroupInput .HealthCheckEnabled = aws .Bool (true )
322
336
targetGroupInput .HealthCheckProtocol = ln .TargetGroup .HealthCheck .Protocol
323
337
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
+ }
324
351
}
325
352
s .scope .Debug ("creating target group" , "group" , targetGroupInput , "listener" , ln )
326
353
group , err := s .ELBV2Client .CreateTargetGroup (targetGroupInput )
@@ -1007,10 +1034,10 @@ func (s *Service) getAPIServerClassicELBSpec(elbName string) (*infrav1.LoadBalan
1007
1034
},
1008
1035
HealthCheck : & infrav1.ClassicELBHealthCheck {
1009
1036
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 ,
1014
1041
},
1015
1042
SecurityGroupIDs : securityGroupIDs ,
1016
1043
ClassicElbAttributes : infrav1.ClassicELBAttributes {
@@ -1506,7 +1533,7 @@ func (s *Service) getHealthCheckTarget() string {
1506
1533
if controlPlaneELB != nil && controlPlaneELB .HealthCheckProtocol != nil {
1507
1534
protocol = controlPlaneELB .HealthCheckProtocol
1508
1535
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 )
1510
1537
}
1511
1538
}
1512
1539
return fmt .Sprintf ("%v:%d" , protocol , infrav1 .DefaultAPIServerPort )
0 commit comments