1717package main
1818
1919import (
20+ "context"
2021 "encoding/json"
2122 "errors"
2223 "fmt"
@@ -53,8 +54,8 @@ func main() {
5354 c .Name = "NVIDIA Device Plugin"
5455 c .Usage = "NVIDIA device plugin for Kubernetes"
5556 c .Version = info .GetVersionString ()
56- c .Action = func (ctx * cli.Context ) error {
57- return start (ctx , o )
57+ c .Action = func (ctx context. Context , cmd * cli.Command ) error {
58+ return start (ctx , cmd , o )
5859 }
5960
6061 c .Flags = []cli.Flag {
@@ -173,7 +174,7 @@ func main() {
173174 }
174175 o .flags = c .Flags
175176
176- err := c .Run (os .Args )
177+ err := c .Run (context . Background (), os .Args )
177178 if err != nil {
178179 klog .Error (err )
179180 os .Exit (1 )
@@ -227,7 +228,7 @@ func validateFlags(infolib nvinfo.Interface, config *spec.Config) error {
227228 return nil
228229}
229230
230- func loadConfig (c * cli.Context , flags []cli.Flag ) (* spec.Config , error ) {
231+ func loadConfig (c * cli.Command , flags []cli.Flag ) (* spec.Config , error ) {
231232 config , err := spec .NewConfig (c , flags )
232233 if err != nil {
233234 return nil , fmt .Errorf ("unable to finalize config: %v" , err )
@@ -236,8 +237,8 @@ func loadConfig(c *cli.Context, flags []cli.Flag) (*spec.Config, error) {
236237 return config , nil
237238}
238239
239- func start (c * cli.Context , o * options ) error {
240- klog .InfoS (fmt .Sprintf ("Starting %s" , c .App . Name ), "version" , c . App .Version )
240+ func start (ctx context. Context , c * cli.Command , o * options ) error {
241+ klog .InfoS (fmt .Sprintf ("Starting %s" , c .Name ), "version" , c .Version )
241242
242243 kubeletSocketDir := filepath .Dir (o .kubeletSocket )
243244 klog .Infof ("Starting FS watcher for %v" , kubeletSocketDir )
@@ -263,7 +264,7 @@ restart:
263264 }
264265
265266 klog .Info ("Starting Plugins." )
266- plugins , restartPlugins , err := startPlugins (c , o )
267+ plugins , restartPlugins , err := startPlugins (ctx , c , o )
267268 if err != nil {
268269 return fmt .Errorf ("error starting plugins: %v" , err )
269270 }
@@ -317,7 +318,7 @@ exit:
317318 return nil
318319}
319320
320- func startPlugins (c * cli.Context , o * options ) ([]plugin.Interface , bool , error ) {
321+ func startPlugins (ctx context. Context , c * cli.Command , o * options ) ([]plugin.Interface , bool , error ) {
321322 // Load the configuration file
322323 klog .Info ("Loading configuration." )
323324 config , err := loadConfig (c , o .flags )
@@ -359,7 +360,7 @@ func startPlugins(c *cli.Context, o *options) ([]plugin.Interface, bool, error)
359360
360361 // Get the set of plugins.
361362 klog .Info ("Retrieving plugins." )
362- plugins , err := GetPlugins (c . Context , infolib , nvmllib , devicelib , config )
363+ plugins , err := GetPlugins (ctx , infolib , nvmllib , devicelib , config )
363364 if err != nil {
364365 return nil , false , fmt .Errorf ("error getting plugins: %v" , err )
365366 }
0 commit comments