Skip to content

Commit

Permalink
fix(inventory/operator): exit node monitor when pods watcher closes
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Feb 19, 2024
1 parent a9888ba commit bc7c3f4
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions operator/inventory/node-discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit bc7c3f4

Please sign in to comment.