From c6e8c712c75aa189b02609599cdfa01d7c0c37b6 Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Mon, 19 Feb 2024 15:50:29 -0500 Subject: [PATCH] fix(inventory/operator): exit node monitor when pods watcher closes (#197) Signed-off-by: Artur Troian --- operator/inventory/node-discovery.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/operator/inventory/node-discovery.go b/operator/inventory/node-discovery.go index 537dd66d..433fb4a2 100644 --- a/operator/inventory/node-discovery.go +++ b/operator/inventory/node-discovery.go @@ -30,6 +30,10 @@ import ( "github.com/akash-network/provider/tools/fromctx" ) +var ( + errWorkerExit = errors.New("worker finished") +) + type k8sPatch struct { Op string `json:"op"` Path string `json:"path"` @@ -266,7 +270,10 @@ initloop: select { case <-dp.ctx.Done(): return dp.ctx.Err() - case evt := <-watcher.ResultChan(): + case evt, isopen := <-watcher.ResultChan(): + if !isopen { + return errWorkerExit + } resp := evt.Object.(*corev1.Pod) if resp.Status.Phase == corev1.PodRunning { watcher.Stop() @@ -460,7 +467,11 @@ func (dp *nodeDiscovery) monitor() error { signalLabels() } } - case res := <-podsWatch.ResultChan(): + case res, isopen := <-podsWatch.ResultChan(): + if !isopen { + return errWorkerExit + } + obj := res.Object.(*corev1.Pod) switch res.Type { case watch.Added: