Skip to content

Commit

Permalink
Fix multus-daemon quit process (#1133)
Browse files Browse the repository at this point in the history
  • Loading branch information
s1061123 authored Aug 3, 2023
1 parent 46d446f commit d5883bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
13 changes: 4 additions & 9 deletions cmd/multus-daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,8 @@ func main() {
}()
}

wg.Add(1)
go func() {
<-serverDoneChannel
logging.Verbosef("multus-server done.")
wg.Done()
}()

wg.Wait()
// never reached
logging.Verbosef("multus daemon is exited")
}

func waitUntilAPIReady(socketPath string) error {
Expand Down Expand Up @@ -223,8 +216,10 @@ func startMultusDaemon(ctx context.Context, daemonConfig *srv.ControllerNetConf,
utilruntime.HandleError(fmt.Errorf("CNI server Serve() failed: %v", err))
}
}, 0)
}()
go func() {
<-ctx.Done()
server.Shutdown(context.Background())
close(done)
}()

return nil
Expand Down
7 changes: 6 additions & 1 deletion pkg/server/config/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func (m *Manager) MonitorPluginConfiguration(ctx context.Context, done chan<- st
case <-ctx.Done():
logging.Verbosef("Stopped monitoring, closing channel ...")
_ = m.configWatcher.Close()
close(done)
return nil
}
}
Expand All @@ -225,7 +226,11 @@ func (m *Manager) MonitorPluginConfiguration(ctx context.Context, done chan<- st
// PersistMultusConfig persists the provided configuration to the disc, with
// Read / Write permissions. The output file path is `<multus auto config dir>/00-multus.conf`
func (m *Manager) PersistMultusConfig(config string) (string, error) {
logging.Debugf("Writing Multus CNI configuration @ %s", m.multusConfigFilePath)
if _, err := os.Stat(m.multusConfigFilePath); err == nil {
logging.Debugf("Overwriting Multus CNI configuration @ %s", m.multusConfigFilePath)
} else {
logging.Debugf("Writing Multus CNI configuration @ %s", m.multusConfigFilePath)
}
return m.multusConfigFilePath, os.WriteFile(m.multusConfigFilePath, []byte(config), UserRWPermission)
}

Expand Down

0 comments on commit d5883bd

Please sign in to comment.