k8s.io/kubernetes@v1.29.3/pkg/volume/flexvolume/fake_watcher.go (about) 1 /* 2 Copyright 2017 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package flexvolume 18 19 import ( 20 "github.com/fsnotify/fsnotify" 21 utilfs "k8s.io/kubernetes/pkg/util/filesystem" 22 ) 23 24 // Mock filesystem watcher 25 type fakeWatcher struct { 26 watches []string // List of watches added by the prober, ordered from least recent to most recent. 27 eventHandler utilfs.FSEventHandler 28 } 29 30 var _ utilfs.FSWatcher = &fakeWatcher{} 31 32 func newFakeWatcher() *fakeWatcher { 33 return &fakeWatcher{ 34 watches: nil, 35 } 36 } 37 38 func (w *fakeWatcher) Init(eventHandler utilfs.FSEventHandler, _ utilfs.FSErrorHandler) error { 39 w.eventHandler = eventHandler 40 return nil 41 } 42 43 func (w *fakeWatcher) Run() { /* no-op */ } 44 45 func (w *fakeWatcher) AddWatch(path string) error { 46 w.watches = append(w.watches, path) 47 return nil 48 } 49 50 // Triggers a mock filesystem event. 51 func (w *fakeWatcher) TriggerEvent(op fsnotify.Op, filename string) { 52 w.eventHandler(fsnotify.Event{Op: op, Name: filename}) 53 }