@@ -190,19 +190,19 @@ func (p *HyperlightDevicePlugin) ListAndWatch(req *pluginapi.Empty, srv pluginap
190190 case <- p .stopCh :
191191 return nil
192192 case <- ticker .C :
193- newHealth := pluginapi .Healthy
193+ health := pluginapi .Healthy
194194 if _ , err := os .Stat (p .devicePath ); err != nil {
195- newHealth = pluginapi .Unhealthy
195+ health = pluginapi .Unhealthy
196196 klog .Warningf ("Device %s not found, marking all devices unhealthy" , p .devicePath )
197197 }
198198
199199 // Check if health changed (compare against first device as representative)
200- if p .devices [0 ].Health != newHealth {
200+ if p .devices [0 ].Health != health {
201201 // Update ALL devices - they all share the same underlying hypervisor device
202202 for i := range p .devices {
203- p .devices [i ].Health = newHealth
203+ p .devices [i ].Health = health
204204 }
205- klog .Infof ("Device health changed to %s for all %d devices" , newHealth , len (p .devices ))
205+ klog .Infof ("Device health changed to %s for all %d devices" , health , len (p .devices ))
206206 if err := srv .Send (& pluginapi.ListAndWatchResponse {Devices : p .devices }); err != nil {
207207 return err
208208 }
@@ -336,7 +336,7 @@ func newFSWatcher(files ...string) (*fsnotify.Watcher, error) {
336336
337337// watchKubeletRestart monitors for kubelet restarts using fsnotify.
338338// When kubelet restarts, it deletes all sockets in /var/lib/kubelet/device-plugins/.
339- // This function blocks until it detects a relevant filesystem event .
339+ // This function blocks until it detects our plugin socket being deleted .
340340func (p * HyperlightDevicePlugin ) watchKubeletRestart () {
341341 klog .Info ("Watching for kubelet restart using fsnotify..." )
342342
@@ -352,17 +352,22 @@ func (p *HyperlightDevicePlugin) watchKubeletRestart() {
352352 select {
353353 case <- p .stopCh :
354354 return
355- case event := <- watcher .Events :
355+ case event , ok := <- watcher .Events :
356+ if ! ok {
357+ klog .Warning ("fsnotify events channel closed, falling back to polling" )
358+ p .watchKubeletRestartPolling ()
359+ return
360+ }
356361 if event .Name == serverSock && (event .Op & fsnotify .Remove ) == fsnotify .Remove {
357362 klog .Info ("Plugin socket deleted - kubelet may have restarted" )
358363 return
359364 }
360- // Also watch for kubelet socket recreation (indicates kubelet restart complete)
361- if event .Name == kubeletSock && (event .Op & fsnotify .Create ) == fsnotify .Create {
362- klog .Info ("Kubelet socket recreated - kubelet restart detected" )
365+ case err , ok := <- watcher .Errors :
366+ if ! ok {
367+ klog .Warning ("fsnotify errors channel closed, falling back to polling" )
368+ p .watchKubeletRestartPolling ()
363369 return
364370 }
365- case err := <- watcher .Errors :
366371 klog .Warningf ("fsnotify error: %v" , err )
367372 }
368373 }
0 commit comments