Skip to content

Commit

Permalink
Remove allocations from rebootasrequired loop
Browse files Browse the repository at this point in the history
There is no need to continuously allocate more resources to
check blockers, they are defined only once.

Signed-off-by: Jean-Philippe Evrard <[email protected]>
  • Loading branch information
evrardjp committed Nov 6, 2024
1 parent 94e7346 commit 97d755c
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions cmd/kured/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ func main() {
log.Fatal(err)
}

var blockCheckers []blockers.RebootBlocker
if prometheusURL != "" {
blockCheckers = append(blockCheckers, blockers.NewPrometheusBlockingChecker(papi.Config{Address: prometheusURL}, alertFilter.Regexp, alertFiringOnly, alertFilterMatchOnly))
}
if podSelectors != nil {
blockCheckers = append(blockCheckers, blockers.NewKubernetesBlockingChecker(client, nodeID, podSelectors))
}
log.Infof("Lock Annotation: %s/%s:%s", dsNamespace, dsName, lockAnnotation)
if lockTTL > 0 {
log.Infof("Lock TTL set, lock will expire after: %v", lockTTL)
Expand All @@ -275,7 +282,7 @@ func main() {
}
lock := daemonsetlock.New(client, nodeID, dsNamespace, dsName, lockAnnotation, lockTTL, concurrency, lockReleaseDelay)

go rebootAsRequired(nodeID, rebooter, rebootChecker, window, lock, client)
go rebootAsRequired(nodeID, rebooter, rebootChecker, blockCheckers, window, lock, client)
go maintainRebootRequiredMetric(nodeID, rebootChecker)

http.Handle("/metrics", promhttp.Handler())
Expand Down Expand Up @@ -546,7 +553,7 @@ func updateNodeLabels(client *kubernetes.Clientset, node *v1.Node, labels []stri
}
}

func rebootAsRequired(nodeID string, rebooter reboot.Rebooter, checker checkers.Checker, window *timewindow.TimeWindow, lock daemonsetlock.Lock, client *kubernetes.Clientset) {
func rebootAsRequired(nodeID string, rebooter reboot.Rebooter, checker checkers.Checker, blockCheckers []blockers.RebootBlocker, window *timewindow.TimeWindow, lock daemonsetlock.Lock, client *kubernetes.Clientset) {

source := rand.NewSource(time.Now().UnixNano())
tick := delaytick.New(source, 1*time.Minute)
Expand Down Expand Up @@ -645,14 +652,6 @@ func rebootAsRequired(nodeID string, rebooter reboot.Rebooter, checker checkers.
}
}

var blockCheckers []blockers.RebootBlocker
if prometheusURL != "" {
blockCheckers = append(blockCheckers, blockers.NewPrometheusBlockingChecker(papi.Config{Address: prometheusURL}, alertFilter.Regexp, alertFiringOnly, alertFilterMatchOnly))
}
if podSelectors != nil {
blockCheckers = append(blockCheckers, blockers.NewKubernetesBlockingChecker(client, nodeID, podSelectors))
}

var rebootRequiredBlockCondition string
if blockers.RebootBlocked(blockCheckers...) {
rebootRequiredBlockCondition = ", but blocked at this time"
Expand Down

0 comments on commit 97d755c

Please sign in to comment.