mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
Fix manifest polling
This commit is contained in:
parent
7fbeafea46
commit
769c1d5415
@ -52,21 +52,15 @@ func WatchFiles(ctx context.Context, skips []string, bases ...string) error {
|
||||
addons.Enqueue("", startKey)
|
||||
addons.Interface().AddHandler(ctx, "addon-start", func(key string, _ *v1.Addon) (runtime.Object, error) {
|
||||
if key == startKey {
|
||||
if err := w.listFiles(true); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
w.started = true
|
||||
return nil, nil
|
||||
go w.start(ctx)
|
||||
}
|
||||
return nil, nil
|
||||
})
|
||||
|
||||
w.start(ctx)
|
||||
return nil
|
||||
}
|
||||
|
||||
type watcher struct {
|
||||
started bool
|
||||
addonCache v1.AddonClientCache
|
||||
addons v1.AddonClient
|
||||
bases []string
|
||||
@ -77,14 +71,17 @@ type watcher struct {
|
||||
}
|
||||
|
||||
func (w *watcher) start(ctx context.Context) {
|
||||
force := true
|
||||
for {
|
||||
if err := w.listFiles(force); err == nil {
|
||||
force = false
|
||||
} else {
|
||||
logrus.Errorf("failed to process config: %v", err)
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-time.After(15 * time.Second):
|
||||
if err := w.listFiles(false); err != nil {
|
||||
logrus.Errorf("failed to process config: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -101,10 +98,6 @@ func (w *watcher) listFiles(force bool) error {
|
||||
}
|
||||
|
||||
func (w *watcher) listFilesIn(base string, force bool) error {
|
||||
if !w.started {
|
||||
return nil
|
||||
}
|
||||
|
||||
files, err := ioutil.ReadDir(base)
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user