Updated to directory crawl
This commit is contained in:
parent
fd62c96e93
commit
14fc5d4def
1 changed files with 26 additions and 26 deletions
|
@ -56,6 +56,7 @@ import (
|
|||
"k8s.io/ingress-nginx/internal/net/ssl"
|
||||
"k8s.io/ingress-nginx/internal/task"
|
||||
"k8s.io/ingress-nginx/internal/watch"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type statusModule string
|
||||
|
@ -153,12 +154,6 @@ func NewNGINXController(config *Configuration, fs file.Filesystem) *NGINXControl
|
|||
glog.Warning("Update of ingress status is disabled (flag --update-status=false was specified)")
|
||||
}
|
||||
|
||||
var reloadNginx func()
|
||||
reloadNginx = func() {
|
||||
glog.Info("Triggering NGINX reload")
|
||||
n.SetForceReload(true)
|
||||
}
|
||||
|
||||
var onTemplateChange func()
|
||||
onTemplateChange = func() {
|
||||
template, err := ngx_template.NewTemplate(tmplPath, fs)
|
||||
|
@ -174,7 +169,7 @@ Error loading new template : %v
|
|||
|
||||
n.t = template
|
||||
glog.Info("new NGINX template loaded")
|
||||
reloadNginx()
|
||||
n.SetForceReload(true)
|
||||
}
|
||||
|
||||
ngxTpl, err := ngx_template.NewTemplate(tmplPath, fs)
|
||||
|
@ -189,28 +184,33 @@ Error loading new template : %v
|
|||
watch.NewDummyFileWatcher(tmplPath, onTemplateChange)
|
||||
} else {
|
||||
|
||||
var watchPath string
|
||||
var watchAction func()
|
||||
var addWatcher func()
|
||||
addWatcher = func() {
|
||||
_, err = watch.NewFileWatcher(watchPath, watchAction)
|
||||
if err != nil {
|
||||
glog.Fatalf("unexpected error watching %v: %v", watchPath, err)
|
||||
}
|
||||
_, err = watch.NewFileWatcher(tmplPath, onTemplateChange)
|
||||
if err != nil {
|
||||
glog.Fatalf("unexpected error creating file watcher: %v", err)
|
||||
}
|
||||
|
||||
// Add the template path to the watcher
|
||||
watchPath = tmplPath
|
||||
watchAction = onTemplateChange
|
||||
addWatcher()
|
||||
filesToWatch := []string{}
|
||||
err := filepath.Walk("/etc/nginx/geoip/", func(path string, info os.FileInfo, err error) error {
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Add the GeoIP data to the watcher
|
||||
geoData := [3]string{"/etc/nginx/geoip/GeoIP.dat", "/etc/nginx/geoip/GeoIPASNum.dat", "/etc/nginx/geoip/GeoLiteCity.dat"}
|
||||
for index, element := range geoData {
|
||||
fmt.Println(index, ":", element)
|
||||
watchPath = element
|
||||
watchAction = reloadNginx
|
||||
addWatcher()
|
||||
filesToWatch = append(filesToWatch, path)
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
glog.Fatalf("unexpected error creating file watcher: %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("unexpected error creating file watcher: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue