From f782929eb568966f9c273fed8e8f3fe77096f931 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Sat, 16 Jun 2018 16:22:59 -0400 Subject: [PATCH] Remove dummy file watcher --- internal/ingress/controller/nginx.go | 54 ++++++++++++++-------------- internal/watch/dummy.go | 30 ---------------- 2 files changed, 26 insertions(+), 58 deletions(-) delete mode 100644 internal/watch/dummy.go diff --git a/internal/ingress/controller/nginx.go b/internal/ingress/controller/nginx.go index 1681022d7f..5fcba2f14d 100644 --- a/internal/ingress/controller/nginx.go +++ b/internal/ingress/controller/nginx.go @@ -163,44 +163,42 @@ Error loading new template: %v n.t = ngxTpl - // TODO: refactor if _, ok := fs.(filesystem.DefaultFs); !ok { - watch.NewDummyFileWatcher(tmplPath, onTemplateChange) - } else { + // do not setup watchers on tests + return n + } + + _, err = watch.NewFileWatcher(tmplPath, onTemplateChange) + if err != nil { + glog.Fatalf("Error creating file watcher for %v: %v", tmplPath, err) + } - _, err = watch.NewFileWatcher(tmplPath, onTemplateChange) + filesToWatch := []string{} + err = filepath.Walk("/etc/nginx/geoip/", func(path string, info os.FileInfo, err error) error { if err != nil { - glog.Fatalf("Error creating file watcher for %v: %v", tmplPath, err) + return err } - filesToWatch := []string{} - err := filepath.Walk("/etc/nginx/geoip/", func(path string, info os.FileInfo, err error) error { - if err != nil { - return err - } + if info.IsDir() { + return nil + } - if info.IsDir() { - return nil - } + filesToWatch = append(filesToWatch, path) + return nil + }) - filesToWatch = append(filesToWatch, path) - return nil - }) + if err != nil { + glog.Fatalf("Error creating file watchers: %v", err) + } + for _, f := range filesToWatch { + _, err = watch.NewFileWatcher(f, func() { + glog.Info("File %v changed. Reloading NGINX", f) + n.SetForceReload(true) + }) if err != nil { - glog.Fatalf("Error creating file watchers: %v", err) + glog.Fatalf("Error creating file watcher for %v: %v", f, err) } - - for _, f := range filesToWatch { - _, err = watch.NewFileWatcher(f, func() { - glog.Info("File %v changed. Reloading NGINX", f) - n.SetForceReload(true) - }) - if err != nil { - glog.Fatalf("Error creating file watcher for %v: %v", f, err) - } - } - } return n diff --git a/internal/watch/dummy.go b/internal/watch/dummy.go deleted file mode 100644 index eb9874a327..0000000000 --- a/internal/watch/dummy.go +++ /dev/null @@ -1,30 +0,0 @@ -/* -Copyright 2017 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package watch - -// DummyFileWatcher noop implementation of a file watcher -type DummyFileWatcher struct{} - -// NewDummyFileWatcher creates a FileWatcher using the DummyFileWatcher -func NewDummyFileWatcher(file string, onEvent func()) FileWatcher { - return DummyFileWatcher{} -} - -// Close ends the watch -func (f DummyFileWatcher) Close() error { - return nil -}