Skip to content

Commit 663df04

Browse files
committed
Pass Context from app.Run
Signed-off-by: Evan Lezar <[email protected]>
1 parent da96644 commit 663df04

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

cmd/mps-control-daemon/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ func main() {
5555
c := cli.Command{}
5656
c.Name = "NVIDIA MPS Control Daemon"
5757
c.Version = info.GetVersionString()
58-
c.Action = func(_ context.Context, cmd *cli.Command) error {
59-
return start(cmd, config)
58+
c.Action = func(ctx context.Context, cmd *cli.Command) error {
59+
return start(ctx, cmd, config)
6060
}
6161
c.Commands = []*cli.Command{
6262
mount.NewCommand(),
@@ -106,7 +106,7 @@ func (cfg *Config) loadConfig(c *cli.Command) (*spec.Config, error) {
106106
return config, nil
107107
}
108108

109-
func start(c *cli.Command, cfg *Config) error {
109+
func start(ctx context.Context, c *cli.Command, cfg *Config) error {
110110
klog.Info("Starting OS watcher.")
111111
sigs := watch.Signals(syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
112112
var started bool
@@ -122,7 +122,7 @@ restart:
122122
}
123123

124124
klog.Info("Starting Daemons.")
125-
daemons, restartDaemons, err := startDaemons(c, cfg)
125+
daemons, restartDaemons, err := startDaemons(ctx, c, cfg)
126126
if err != nil {
127127
return fmt.Errorf("error starting plugins: %v", err)
128128
}
@@ -162,7 +162,7 @@ exit:
162162
return nil
163163
}
164164

165-
func startDaemons(c *cli.Command, cfg *Config) ([]*mps.Daemon, bool, error) {
165+
func startDaemons(ctx context.Context, c *cli.Command, cfg *Config) ([]*mps.Daemon, bool, error) {
166166
// Load the configuration file
167167
klog.Info("Loading configuration.")
168168
config, err := cfg.loadConfig(c)
@@ -209,7 +209,7 @@ func startDaemons(c *cli.Command, cfg *Config) ([]*mps.Daemon, bool, error) {
209209
// Loop through all MPS daemons and start them.
210210
// If any daemon fails to start, all daemons are started again.
211211
for _, mpsDaemon := range mpsDaemons {
212-
if err := mpsDaemon.Start(); err != nil {
212+
if err := mpsDaemon.Start(ctx); err != nil {
213213
klog.Errorf("Failed to start MPS daemon: %v", err)
214214
return mpsDaemons, true, nil
215215
}

cmd/mps-control-daemon/mps/daemon.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package mps
1818

1919
import (
2020
"bytes"
21+
"context"
2122
"errors"
2223
"fmt"
2324
"io"
@@ -89,7 +90,7 @@ func (d *Daemon) EnvVars() envvars {
8990
}
9091

9192
// Start starts the MPS deamon as a background process.
92-
func (d *Daemon) Start() error {
93+
func (d *Daemon) Start(ctx context.Context) error {
9394
if err := d.setComputeMode(computeModeExclusiveProcess); err != nil {
9495
return fmt.Errorf("error setting compute mode %v: %w", computeModeExclusiveProcess, err)
9596
}
@@ -137,7 +138,7 @@ func (d *Daemon) Start() error {
137138

138139
d.logTailer = newTailer(filepath.Join(logDir, "control.log"))
139140
klog.InfoS("Starting log tailer", "resource", d.rm.Resource())
140-
if err := d.logTailer.Start(); err != nil {
141+
if err := d.logTailer.Start(ctx); err != nil {
141142
klog.ErrorS(err, "Could not start tail command on control.log; ignoring logs")
142143
}
143144

cmd/mps-control-daemon/mps/log-tailer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ func newTailer(filename string) *tailer {
3737
}
3838

3939
// Start starts tailing the specified filename.
40-
func (t *tailer) Start() error {
41-
ctx, cancel := context.WithCancel(context.Background())
40+
func (t *tailer) Start(ctx context.Context) error {
41+
ctx, cancel := context.WithCancel(ctx)
4242
t.cancel = cancel
4343

4444
//nolint:gosec // G204: Subprocess launched with a potential tainted input or cmd arguments (gosec)

0 commit comments

Comments
 (0)