-
Notifications
You must be signed in to change notification settings - Fork 1
/
ondemand.go
59 lines (47 loc) · 1.24 KB
/
ondemand.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package watcher
import (
"context"
"github.com/gardener/gardener/pkg/apis/core/v1beta1"
"github.com/pPrecel/cloudagent/pkg/agent"
"github.com/pPrecel/cloudagent/pkg/config"
"github.com/sirupsen/logrus"
)
type ondemand struct {
cache agent.Cache[*v1beta1.ShootList]
fns []agent.WatchFn
context context.Context
logger *logrus.Entry
configPath string
getConfig func(string) (*config.Config, error)
parseWatcherFns func(*logrus.Entry, agent.Cache[*v1beta1.ShootList], *config.Config) []agent.WatchFn
}
func newOnDemand(o *Options) *ondemand {
return &ondemand{
context: o.Context,
logger: o.Logger,
cache: agent.NewCache[*v1beta1.ShootList](),
configPath: o.ConfigPath,
getConfig: config.Read,
parseWatcherFns: parseWatcherFns,
}
}
func (w *ondemand) start(ctx context.Context) error {
// wait for cotext Done only
<-ctx.Done()
return nil
}
func (w *ondemand) GetGardenerCache() agent.Cache[*v1beta1.ShootList] {
for i := range w.fns {
w.fns[i](w.context)
}
return w.cache
}
func (w *ondemand) GetGeneralError() error {
w.cache.Clean()
cfg, err := w.getConfig(w.configPath)
if err != nil {
return err
}
w.fns = w.parseWatcherFns(w.logger, w.cache, cfg)
return nil
}