Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(operator/inventory): drain sigexit channel on shutdown #194

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion operator/inventory/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ func newClusterNodes(ctx context.Context, image, namespace string) *clusterNodes
}

func (cl *clusterNodes) Wait() error {
return cl.group.Wait()
log := fromctx.LogrFromCtx(cl.ctx).WithName("nodes")

log.Info("waiting for nodes to finish")
err := cl.group.Wait()
log.Info("all nodes finished")

return err
}

func (cl *clusterNodes) connector() error {
Expand All @@ -92,12 +98,33 @@ func (cl *clusterNodes) connector() error {

nctx, ncancel := context.WithCancel(ctx)
defer func() {
log.Info("shutting down node connectors")

ncancel()

lctx, lcancel := context.WithCancel(context.Background())

go func() {
for {
select {
case <-lctx.Done():
return
case <-cl.signaldone:
}
}
}()

for name, node := range nodes {
log.Info(fmt.Sprintf("shutting down node %s", name))
_ = node.shutdown()
delete(nodes, name)

log.Info(fmt.Sprintf("node %s has been shutdown", name))
}

lcancel()

log.Info("node connectors down")
}()

for {
Expand Down Expand Up @@ -153,6 +180,7 @@ func (cl *clusterNodes) run() error {

events := bus.Sub(topicInventoryNode)
defer bus.Unsub(events)

for {
select {
case <-cl.ctx.Done():
Expand Down
Loading