Skip to content

Commit

Permalink
Use blockers
Browse files Browse the repository at this point in the history
Use the `RebootBlocker` interface to implement the min-reboot-period
feature.
  • Loading branch information
leonnicolas committed Oct 18, 2024
1 parent a4d71f6 commit aa627d9
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions cmd/kured/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,30 @@ type KubernetesBlockingChecker struct {
filter []string
}

type MinimumRebootPeriodChecker struct {
client *kubernetes.Clientset
nodename string
}

func (mpb MinimumRebootPeriodChecker) isBlocked() bool {
if minRebootPeriod <= 0 {
return false
}
node, err := mpb.client.CoreV1().Nodes().Get(context.TODO(), nodeID, metav1.GetOptions{})
if err != nil {
log.Errorf("Error retrieving node object via k8s API: %s", err)
return true
}
if t, err := nextAllowedReboot(node); err != nil {
log.Warnf("Failed to determine next allowed reboot time: %s", err.Error())
return false
} else if diff := t.Sub(time.Now()); diff > 0 {
log.Infof("Reboot blocked: not allowed until %s (%s)", t.String(), diff.String())
return true
}
return false
}

func (pb PrometheusBlockingChecker) isBlocked() bool {
alertNames, err := pb.promClient.ActiveAlerts(pb.filter, pb.firingOnly, pb.filterMatchOnly)
if err != nil {
Expand Down Expand Up @@ -744,15 +768,6 @@ func rebootAsRequired(nodeID string, booter reboot.Reboot, sentinelCommand []str
log.Fatalf("Error retrieving node object via k8s API: %v", err)
}

if minRebootPeriod > 0 {
if t, err := nextAllowedReboot(node); err != nil {
log.Warnf("Failed to determine next allowed reboot time: %s", err.Error())
} else if diff := t.Sub(time.Now()); diff > 0 {
log.Infof("Reboot not allowed until %s (%s)", t.String(), diff.String())
continue
}
}

if !rebootRequired(sentinelCommand) {
log.Infof("Reboot not required")
preferNoScheduleTaint.Disable()
Expand Down Expand Up @@ -784,6 +799,9 @@ func rebootAsRequired(nodeID string, booter reboot.Reboot, sentinelCommand []str
if podSelectors != nil {
blockCheckers = append(blockCheckers, KubernetesBlockingChecker{client: client, nodename: nodeID, filter: podSelectors})
}
if minRebootPeriod >= 0 {
blockCheckers = append(blockCheckers, MinimumRebootPeriodChecker{client: client, nodename: nodeID})
}

var rebootRequiredBlockCondition string
if rebootBlocked(blockCheckers...) {
Expand Down

0 comments on commit aa627d9

Please sign in to comment.