refactor reaper so that it uses the context of the kh checks
@@ -48,8 +48,6 @@ type Kuberhealthy struct {
wg sync.WaitGroup // used to track running checks
shutdownCtxFunc context.CancelFunc // used to shutdown the main control select
stateReflector *StateReflector // a reflector that can cache the current state of the khState resources
- khStateReaperCtx context.Context // used to control the khState reaper
- khStateReaperCtxFunc context.CancelFunc // used to shut down the khState reaper
}
// NewKuberhealthy creates a new kuberhealthy checker instance
@@ -116,12 +114,6 @@ func (k *Kuberhealthy) Shutdown(doneChan chan struct{}) {
// All checks are sent a shutdown command at the same time.
func (k *Kuberhealthy) StopChecks() {
- // if the reaper has a context to kill, do it
- log.Infoln("control: stopping khState reaper...")
- if k.khStateReaperCtxFunc != nil {
- k.khStateReaperCtxFunc()
- }
-
log.Infoln("control:", len(k.Checks), "checks stopping...")
if k.cancelChecksFunc != nil {
k.cancelChecksFunc()
@@ -207,7 +199,7 @@ func (k *Kuberhealthy) RestartChecks() {
}
// khStateResourceReaper runs reapKHStateResources on an interval until the context for it is canceled
-func (k *Kuberhealthy) khStateResourceReaper() {
+func (k *Kuberhealthy) khStateResourceReaper(ctx context.Context) {
ticker := time.NewTicker(time.Minute)
defer ticker.Stop()
@@ -221,7 +213,7 @@ func (k *Kuberhealthy) khStateResourceReaper() {
if err != nil {
log.Errorln("khState reaper: Error when reaping khState resources:", err)
}
- case <-k.khStateReaperCtx.Done():
+ case <-ctx.Done():
log.Infoln("khState reaper: stopping")
return
}
@@ -510,8 +502,7 @@ func (k *Kuberhealthy) StartChecks() {
// spin up the khState reaper with a context after checks have been configured and started
log.Infoln("control:", len(k.Checks), "reaper starting!")
- k.khStateReaperCtx, k.khStateReaperCtxFunc = context.WithCancel(context.Background())
- go k.khStateResourceReaper()
+ go k.khStateResourceReaper(ctx)
}
// masterStatusWatcher watches for master change events and updates the global upcomingMasterState along
