@@ -293,8 +293,7 @@ func (dp *PCIDevicePlugin) Allocate(_ context.Context, r *pluginapi.AllocateRequ
293293}
294294
295295func (dp * PCIDevicePlugin ) healthCheck () error {
296- logger := log .DefaultLogger ()
297- monitoredDevices := map [string ]string {}
296+ monitoredDevices := make (map [string ]string )
298297 watcher , err := fsnotify .NewWatcher ()
299298 if err != nil {
300299 return fmt .Errorf ("failed to creating a fsnotify watcher: %v" , err )
@@ -349,33 +348,37 @@ func (dp *PCIDevicePlugin) healthCheck() error {
349348 return fmt .Errorf ("failed to watch device-plugin socket: %v" , err )
350349 }
351350
351+ return dp .performCheck (monitoredDevices , watcher )
352+ }
353+
354+ func (dp * PCIDevicePlugin ) performCheck (monitoredDevices map [string ]string , watcher * fsnotify.Watcher ) error {
352355 for {
353356 select {
354357 case <- dp .stop :
355358 return nil
356359 case <- dp .done :
357360 return nil
358361 case err := <- watcher .Errors :
359- logger . Reason ( err ). Errorf ("error watching devices and device plugin directory" )
362+ logrus . Errorf ("error watching devices and device plugin directory: %v" , err )
360363 case event := <- watcher .Events :
361- logger . V ( 4 ) .Infof ("health Event: %v" , event )
364+ logrus .Infof ("health Event: %v" , event )
362365 if monDevID , exist := monitoredDevices [event .Name ]; exist {
363366 // Health in this case is if the device path actually exists
364367 if event .Op == fsnotify .Create {
365- logger .Infof ("monitored device %s appeared" , dp .resourceName )
368+ logrus .Infof ("monitored device %s appeared" , dp .resourceName )
366369 dp .health <- deviceHealth {
367370 DevID : monDevID ,
368371 Health : pluginapi .Healthy ,
369372 }
370373 } else if (event .Op == fsnotify .Remove ) || (event .Op == fsnotify .Rename ) {
371- logger .Infof ("monitored device %s disappeared" , dp .resourceName )
374+ logrus .Infof ("monitored device %s disappeared" , dp .resourceName )
372375 dp .health <- deviceHealth {
373376 DevID : monDevID ,
374377 Health : pluginapi .Unhealthy ,
375378 }
376379 }
377380 } else if event .Name == dp .socketPath && event .Op == fsnotify .Remove {
378- logger .Infof ("device socket file for device %s was removed, kubelet probably restarted." , dp .resourceName )
381+ logrus .Infof ("device socket file for device %s was removed, kubelet probably restarted." , dp .resourceName )
379382 return nil
380383 }
381384 }
0 commit comments