@@ -406,8 +406,7 @@ func (s *Service) reconcileAPILoadBalancerListener(lb *loadbalancers.LoadBalance
406
406
if err != nil {
407
407
return err
408
408
}
409
-
410
- if err := s .getOrCreateMonitor (openStackCluster , lbPortObjectsName , pool .ID , lb .ID ); err != nil {
409
+ if err := s .getOrUpdateMonitor (openStackCluster , lbPortObjectsName , pool .ID , lb .ID ); err != nil {
411
410
return err
412
411
}
413
412
@@ -532,13 +531,83 @@ func (s *Service) getOrCreatePool(openStackCluster *infrav1.OpenStackCluster, po
532
531
return pool , nil
533
532
}
534
533
535
- func (s * Service ) getOrCreateMonitor (openStackCluster * infrav1.OpenStackCluster , monitorName , poolID , lbID string ) error {
534
+ func (s * Service ) getOrUpdateMonitor (openStackCluster * infrav1.OpenStackCluster , monitorName , poolID , lbID string ) error {
536
535
monitor , err := s .checkIfMonitorExists (monitorName )
537
536
if err != nil {
538
537
return err
539
538
}
540
539
540
+ monitorConfig := openStackCluster .Spec .APIServerLoadBalancer .Monitor
541
+
542
+ // Default values for monitor
543
+ const (
544
+ defaultDelay = 10
545
+ defaultTimeout = 5
546
+ defaultMaxRetries = 5
547
+ defaultMaxRetriesDown = 3
548
+ )
549
+
541
550
if monitor != nil {
551
+ needsUpdate := false
552
+ monitorUpdateOpts := monitors.UpdateOpts {}
553
+
554
+ if (monitorConfig == nil || monitorConfig .Delay == nil ) && monitor .Delay != defaultDelay {
555
+ s .scope .Logger ().Info ("Monitor delay needs update to default" , "current" , monitor .Delay , "default" , defaultDelay )
556
+ monitorUpdateOpts .Delay = defaultDelay
557
+ needsUpdate = true
558
+ } else if monitorConfig != nil && monitorConfig .Delay != nil && monitor .Delay != * monitorConfig .Delay {
559
+ s .scope .Logger ().Info ("Monitor delay needs update" , "current" , monitor .Delay , "desired" , * monitorConfig .Delay )
560
+ monitorUpdateOpts .Delay = * monitorConfig .Delay
561
+ needsUpdate = true
562
+ }
563
+
564
+ if (monitorConfig == nil || monitorConfig .Timeout == nil ) && monitor .Timeout != defaultTimeout {
565
+ s .scope .Logger ().Info ("Monitor timeout needs update to default" , "current" , monitor .Timeout , "default" , defaultTimeout )
566
+ monitorUpdateOpts .Timeout = defaultTimeout
567
+ needsUpdate = true
568
+ } else if monitorConfig != nil && monitorConfig .Timeout != nil && monitor .Timeout != * monitorConfig .Timeout {
569
+ s .scope .Logger ().Info ("Monitor timeout needs update" , "current" , monitor .Timeout , "desired" , * monitorConfig .Timeout )
570
+ monitorUpdateOpts .Timeout = * monitorConfig .Timeout
571
+ needsUpdate = true
572
+ }
573
+
574
+ if (monitorConfig == nil || monitorConfig .MaxRetries == nil ) && monitor .MaxRetries != defaultMaxRetries {
575
+ s .scope .Logger ().Info ("Monitor maxRetries needs update to default" , "current" , monitor .MaxRetries , "default" , defaultMaxRetries )
576
+ monitorUpdateOpts .MaxRetries = defaultMaxRetries
577
+ needsUpdate = true
578
+ } else if monitorConfig != nil && monitorConfig .MaxRetries != nil && monitor .MaxRetries != * monitorConfig .MaxRetries {
579
+ s .scope .Logger ().Info ("Monitor maxRetries needs update" , "current" , monitor .MaxRetries , "desired" , * monitorConfig .MaxRetries )
580
+ monitorUpdateOpts .MaxRetries = * monitorConfig .MaxRetries
581
+ needsUpdate = true
582
+ }
583
+
584
+ if (monitorConfig == nil || monitorConfig .MaxRetriesDown == nil ) && monitor .MaxRetriesDown != defaultMaxRetriesDown {
585
+ s .scope .Logger ().Info ("Monitor maxRetriesDown needs update to default" , "current" , monitor .MaxRetriesDown , "default" , defaultMaxRetriesDown )
586
+ monitorUpdateOpts .MaxRetriesDown = defaultMaxRetriesDown
587
+ needsUpdate = true
588
+ } else if monitorConfig != nil && monitorConfig .MaxRetriesDown != nil && monitor .MaxRetriesDown != * monitorConfig .MaxRetriesDown {
589
+ s .scope .Logger ().Info ("Monitor maxRetriesDown needs update" , "current" , monitor .MaxRetriesDown , "desired" , * monitorConfig .MaxRetriesDown )
590
+ monitorUpdateOpts .MaxRetriesDown = * monitorConfig .MaxRetriesDown
591
+ needsUpdate = true
592
+ }
593
+
594
+ if needsUpdate {
595
+ s .scope .Logger ().Info ("Updating load balancer monitor" , "loadBalancerID" , lbID , "name" , monitorName , "monitorID" , monitor .ID )
596
+
597
+ updatedMonitor , err := s .loadbalancerClient .UpdateMonitor (monitor .ID , monitorUpdateOpts )
598
+ if err != nil {
599
+ record .Warnf (openStackCluster , "FailedUpdateMonitor" , "Failed to update monitor %s with id %s: %v" , monitorName , monitor .ID , err )
600
+ return err
601
+ }
602
+
603
+ if _ , err = s .waitForLoadBalancerActive (lbID ); err != nil {
604
+ record .Warnf (openStackCluster , "FailedUpdateMonitor" , "Failed to update monitor %s with id %s: wait for load balancer active %s: %v" , monitorName , monitor .ID , lbID , err )
605
+ return err
606
+ }
607
+
608
+ record .Eventf (openStackCluster , "SuccessfulUpdateMonitor" , "Updated monitor %s with id %s" , monitorName , updatedMonitor .ID )
609
+ }
610
+
542
611
return nil
543
612
}
544
613
@@ -548,13 +617,29 @@ func (s *Service) getOrCreateMonitor(openStackCluster *infrav1.OpenStackCluster,
548
617
Name : monitorName ,
549
618
PoolID : poolID ,
550
619
Type : "TCP" ,
551
- Delay : 10 ,
552
- MaxRetries : 5 ,
553
- MaxRetriesDown : 3 ,
554
- Timeout : 5 ,
620
+ Delay : defaultDelay ,
621
+ Timeout : defaultTimeout ,
622
+ MaxRetries : defaultMaxRetries ,
623
+ MaxRetriesDown : defaultMaxRetriesDown ,
624
+ }
625
+
626
+ if monitorConfig != nil {
627
+ if monitorConfig .Delay != nil {
628
+ monitorCreateOpts .Delay = * monitorConfig .Delay
629
+ }
630
+ if monitorConfig .MaxRetries != nil {
631
+ monitorCreateOpts .MaxRetries = * monitorConfig .MaxRetries
632
+ }
633
+ if monitorConfig .MaxRetriesDown != nil {
634
+ monitorCreateOpts .MaxRetriesDown = * monitorConfig .MaxRetriesDown
635
+ }
636
+ if monitorConfig .Timeout != nil {
637
+ monitorCreateOpts .Timeout = * monitorConfig .Timeout
638
+ }
555
639
}
556
- monitor , err = s .loadbalancerClient .CreateMonitor (monitorCreateOpts )
557
- // Skip creating monitor if it is not supported by Octavia provider
640
+
641
+ newMonitor , err := s .loadbalancerClient .CreateMonitor (monitorCreateOpts )
642
+
558
643
if capoerrors .IsNotImplementedError (err ) {
559
644
record .Warnf (openStackCluster , "SkippedCreateMonitor" , "Health Monitor is not created as it's not implemented with the current Octavia provider." )
560
645
return nil
@@ -566,11 +651,11 @@ func (s *Service) getOrCreateMonitor(openStackCluster *infrav1.OpenStackCluster,
566
651
}
567
652
568
653
if _ , err = s .waitForLoadBalancerActive (lbID ); err != nil {
569
- record .Warnf (openStackCluster , "FailedCreateMonitor" , "Failed to create monitor %s with id %s: wait for load balancer active %s: %v" , monitorName , monitor .ID , lbID , err )
654
+ record .Warnf (openStackCluster , "FailedCreateMonitor" , "Failed to create monitor %s with id %s: wait for load balancer active %s: %v" , monitorName , newMonitor .ID , lbID , err )
570
655
return err
571
656
}
572
657
573
- record .Eventf (openStackCluster , "SuccessfulCreateMonitor" , "Created monitor %s with id %s" , monitorName , monitor .ID )
658
+ record .Eventf (openStackCluster , "SuccessfulCreateMonitor" , "Created monitor %s with id %s" , monitorName , newMonitor .ID )
574
659
return nil
575
660
}
576
661
0 commit comments