mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	fsnotify: use event.Has instead of "event.Op&h == h"
This commit is contained in:
		@@ -257,10 +257,7 @@ func (o *Options) initWatcher() error {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (o *Options) eventHandler(ent fsnotify.Event) {
 | 
					func (o *Options) eventHandler(ent fsnotify.Event) {
 | 
				
			||||||
	eventOpIs := func(Op fsnotify.Op) bool {
 | 
						if ent.Has(fsnotify.Write) || ent.Has(fsnotify.Rename) {
 | 
				
			||||||
		return ent.Op&Op == Op
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if eventOpIs(fsnotify.Write) || eventOpIs(fsnotify.Rename) {
 | 
					 | 
				
			||||||
		// error out when ConfigFile is updated
 | 
							// error out when ConfigFile is updated
 | 
				
			||||||
		o.errCh <- fmt.Errorf("content of the proxy server's configuration file was updated")
 | 
							o.errCh <- fmt.Errorf("content of the proxy server's configuration file was updated")
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -73,12 +73,12 @@ func (w *Watcher) Start(stopCh <-chan struct{}) error {
 | 
				
			|||||||
			select {
 | 
								select {
 | 
				
			||||||
			case event := <-fsWatcher.Events:
 | 
								case event := <-fsWatcher.Events:
 | 
				
			||||||
				//TODO: Handle errors by taking corrective measures
 | 
									//TODO: Handle errors by taking corrective measures
 | 
				
			||||||
				if event.Op&fsnotify.Create == fsnotify.Create {
 | 
									if event.Has(fsnotify.Create) {
 | 
				
			||||||
					err := w.handleCreateEvent(event)
 | 
										err := w.handleCreateEvent(event)
 | 
				
			||||||
					if err != nil {
 | 
										if err != nil {
 | 
				
			||||||
						klog.ErrorS(err, "Error when handling create event", "event", event)
 | 
											klog.ErrorS(err, "Error when handling create event", "event", event)
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				} else if event.Op&fsnotify.Remove == fsnotify.Remove {
 | 
									} else if event.Has(fsnotify.Remove) {
 | 
				
			||||||
					w.handleDeleteEvent(event)
 | 
										w.handleDeleteEvent(event)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				continue
 | 
									continue
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -169,7 +169,7 @@ func (prober *flexVolumeProber) handleWatchEvent(event fsnotify.Event) error {
 | 
				
			|||||||
	if eventPathAbs == pluginDirAbs {
 | 
						if eventPathAbs == pluginDirAbs {
 | 
				
			||||||
		// If the Flexvolume plugin directory is removed, need to recreate it
 | 
							// If the Flexvolume plugin directory is removed, need to recreate it
 | 
				
			||||||
		// in order to keep it under watch.
 | 
							// in order to keep it under watch.
 | 
				
			||||||
		if eventOpIs(event, fsnotify.Remove) {
 | 
							if event.Has(fsnotify.Remove) {
 | 
				
			||||||
			if err := prober.createPluginDir(); err != nil {
 | 
								if err := prober.createPluginDir(); err != nil {
 | 
				
			||||||
				return err
 | 
									return err
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@@ -181,7 +181,7 @@ func (prober *flexVolumeProber) handleWatchEvent(event fsnotify.Event) error {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// watch newly added subdirectories inside a driver directory
 | 
						// watch newly added subdirectories inside a driver directory
 | 
				
			||||||
	if eventOpIs(event, fsnotify.Create) {
 | 
						if event.Has(fsnotify.Create) {
 | 
				
			||||||
		if err := prober.addWatchRecursive(eventPathAbs); err != nil {
 | 
							if err := prober.addWatchRecursive(eventPathAbs); err != nil {
 | 
				
			||||||
			return err
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -197,7 +197,7 @@ func (prober *flexVolumeProber) handleWatchEvent(event fsnotify.Event) error {
 | 
				
			|||||||
		driverDirName := strings.Split(eventRelPathToPluginDir, string(os.PathSeparator))[0]
 | 
							driverDirName := strings.Split(eventRelPathToPluginDir, string(os.PathSeparator))[0]
 | 
				
			||||||
		driverDirAbs := filepath.Join(pluginDirAbs, driverDirName)
 | 
							driverDirAbs := filepath.Join(pluginDirAbs, driverDirName)
 | 
				
			||||||
		// executable is removed, will trigger ProbeRemove event
 | 
							// executable is removed, will trigger ProbeRemove event
 | 
				
			||||||
		if eventOpIs(event, fsnotify.Remove) && (eventRelPathToPluginDir == getExecutablePathRel(driverDirName) || parentPathAbs == pluginDirAbs) {
 | 
							if event.Has(fsnotify.Remove) && (eventRelPathToPluginDir == getExecutablePathRel(driverDirName) || parentPathAbs == pluginDirAbs) {
 | 
				
			||||||
			prober.updateEventsMap(driverDirAbs, volume.ProbeRemove)
 | 
								prober.updateEventsMap(driverDirAbs, volume.ProbeRemove)
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			prober.updateEventsMap(driverDirAbs, volume.ProbeAddOrUpdate)
 | 
								prober.updateEventsMap(driverDirAbs, volume.ProbeAddOrUpdate)
 | 
				
			||||||
@@ -281,7 +281,3 @@ func (prober *flexVolumeProber) testAndSetProbeAllNeeded(newval bool) (oldval bo
 | 
				
			|||||||
	oldval, prober.probeAllNeeded = prober.probeAllNeeded, newval
 | 
						oldval, prober.probeAllNeeded = prober.probeAllNeeded, newval
 | 
				
			||||||
	return
 | 
						return
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
func eventOpIs(event fsnotify.Event, op fsnotify.Op) bool {
 | 
					 | 
				
			||||||
	return event.Op&op == op
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -204,7 +204,7 @@ func (c *DynamicFileCAContent) watchCAFile(stopCh <-chan struct{}) error {
 | 
				
			|||||||
func (c *DynamicFileCAContent) handleWatchEvent(e fsnotify.Event, w *fsnotify.Watcher) error {
 | 
					func (c *DynamicFileCAContent) handleWatchEvent(e fsnotify.Event, w *fsnotify.Watcher) error {
 | 
				
			||||||
	// This should be executed after restarting the watch (if applicable) to ensure no file event will be missing.
 | 
						// This should be executed after restarting the watch (if applicable) to ensure no file event will be missing.
 | 
				
			||||||
	defer c.queue.Add(workItemKey)
 | 
						defer c.queue.Add(workItemKey)
 | 
				
			||||||
	if e.Op&(fsnotify.Remove|fsnotify.Rename) == 0 {
 | 
						if !e.Has(fsnotify.Remove) && !e.Has(fsnotify.Rename) {
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err := w.Remove(c.filename); err != nil {
 | 
						if err := w.Remove(c.filename); err != nil {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -185,7 +185,7 @@ func (c *DynamicCertKeyPairContent) watchCertKeyFile(stopCh <-chan struct{}) err
 | 
				
			|||||||
func (c *DynamicCertKeyPairContent) handleWatchEvent(e fsnotify.Event, w *fsnotify.Watcher) error {
 | 
					func (c *DynamicCertKeyPairContent) handleWatchEvent(e fsnotify.Event, w *fsnotify.Watcher) error {
 | 
				
			||||||
	// This should be executed after restarting the watch (if applicable) to ensure no file event will be missing.
 | 
						// This should be executed after restarting the watch (if applicable) to ensure no file event will be missing.
 | 
				
			||||||
	defer c.queue.Add(workItemKey)
 | 
						defer c.queue.Add(workItemKey)
 | 
				
			||||||
	if e.Op&(fsnotify.Remove|fsnotify.Rename) == 0 {
 | 
						if !e.Has(fsnotify.Remove) && !e.Has(fsnotify.Rename) {
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err := w.Remove(e.Name); err != nil {
 | 
						if err := w.Remove(e.Name); err != nil {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user