diff --git a/pkg/deviceplugins/device_manager.go b/pkg/deviceplugins/device_manager.go index 67884f38..89cc71d6 100644 --- a/pkg/deviceplugins/device_manager.go +++ b/pkg/deviceplugins/device_manager.go @@ -293,8 +293,7 @@ func (dp *PCIDevicePlugin) Allocate(_ context.Context, r *pluginapi.AllocateRequ } func (dp *PCIDevicePlugin) healthCheck() error { - logger := log.DefaultLogger() - monitoredDevices := map[string]string{} + monitoredDevices := make(map[string]string) watcher, err := fsnotify.NewWatcher() if err != nil { return fmt.Errorf("failed to creating a fsnotify watcher: %v", err) @@ -349,6 +348,10 @@ func (dp *PCIDevicePlugin) healthCheck() error { return fmt.Errorf("failed to watch device-plugin socket: %v", err) } + return dp.performCheck(monitoredDevices, watcher) +} + +func (dp *PCIDevicePlugin) performCheck(monitoredDevices map[string]string, watcher *fsnotify.Watcher) error { for { select { case <-dp.stop: @@ -356,26 +359,26 @@ func (dp *PCIDevicePlugin) healthCheck() error { case <-dp.done: return nil case err := <-watcher.Errors: - logger.Reason(err).Errorf("error watching devices and device plugin directory") + logrus.Errorf("error watching devices and device plugin directory: %v", err) case event := <-watcher.Events: - logger.V(4).Infof("health Event: %v", event) + logrus.Infof("health Event: %v", event) if monDevID, exist := monitoredDevices[event.Name]; exist { // Health in this case is if the device path actually exists if event.Op == fsnotify.Create { - logger.Infof("monitored device %s appeared", dp.resourceName) + logrus.Infof("monitored device %s appeared", dp.resourceName) dp.health <- deviceHealth{ DevID: monDevID, Health: pluginapi.Healthy, } } else if (event.Op == fsnotify.Remove) || (event.Op == fsnotify.Rename) { - logger.Infof("monitored device %s disappeared", dp.resourceName) + logrus.Infof("monitored device %s disappeared", dp.resourceName) dp.health <- deviceHealth{ DevID: monDevID, Health: pluginapi.Unhealthy, } } } else if event.Name == dp.socketPath && event.Op == fsnotify.Remove { - logger.Infof("device socket file for device %s was removed, kubelet probably restarted.", dp.resourceName) + logrus.Infof("device socket file for device %s was removed, kubelet probably restarted.", dp.resourceName) return nil } }