From 8d6768b0c5c3cdece864ff46f4dddbadca31d1da Mon Sep 17 00:00:00 2001 From: Tom Hayward Date: Wed, 17 Apr 2024 16:58:36 -0700 Subject: [PATCH 1/3] fix path in file changed detected message Signed-off-by: Tom Hayward --- internal/ingress/controller/nginx.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/ingress/controller/nginx.go b/internal/ingress/controller/nginx.go index 0df5409f4d..398f188d12 100644 --- a/internal/ingress/controller/nginx.go +++ b/internal/ingress/controller/nginx.go @@ -202,6 +202,7 @@ func NewNGINXController(config *Configuration, mc metric.Collector) *NGINXContro } for _, f := range filesToWatch { + f := f _, err = file.NewFileWatcher(f, func() { klog.InfoS("File changed detected. Reloading NGINX", "path", f) n.syncQueue.EnqueueTask(task.GetDummyObject("file-change")) From c826eebbbb31afdcafb9b6ee006abf446fe9e0b2 Mon Sep 17 00:00:00 2001 From: Tom Hayward Date: Wed, 17 Apr 2024 16:58:58 -0700 Subject: [PATCH 2/3] fix typo in log message --- internal/ingress/controller/nginx.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/ingress/controller/nginx.go b/internal/ingress/controller/nginx.go index 398f188d12..8a89ba1818 100644 --- a/internal/ingress/controller/nginx.go +++ b/internal/ingress/controller/nginx.go @@ -204,7 +204,7 @@ func NewNGINXController(config *Configuration, mc metric.Collector) *NGINXContro for _, f := range filesToWatch { f := f _, err = file.NewFileWatcher(f, func() { - klog.InfoS("File changed detected. Reloading NGINX", "path", f) + klog.InfoS("File change detected. Reloading NGINX", "path", f) n.syncQueue.EnqueueTask(task.GetDummyObject("file-change")) }) if err != nil { From 4a1e3c420025710d10f2454248e07ed31a189241 Mon Sep 17 00:00:00 2001 From: Tom Hayward Date: Fri, 19 Apr 2024 07:40:51 -0700 Subject: [PATCH 3/3] explain code per review comments --- internal/ingress/controller/nginx.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/ingress/controller/nginx.go b/internal/ingress/controller/nginx.go index 8a89ba1818..b81734154d 100644 --- a/internal/ingress/controller/nginx.go +++ b/internal/ingress/controller/nginx.go @@ -202,6 +202,8 @@ func NewNGINXController(config *Configuration, mc metric.Collector) *NGINXContro } for _, f := range filesToWatch { + // This redeclaration is necessary for the closure to get the correct value for the iteration in go versions <1.22 + // See https://go.dev/blog/loopvar-preview f := f _, err = file.NewFileWatcher(f, func() { klog.InfoS("File change detected. Reloading NGINX", "path", f)