-
Notifications
You must be signed in to change notification settings - Fork 1
/
config_watchers.go
46 lines (39 loc) · 1.23 KB
/
config_watchers.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
package agent
import (
"context"
"sync"
"github.com/datawire/k8sapi/pkg/k8sapi"
"github.com/emissary-ingress/emissary/v3/pkg/kates"
)
type ConfigWatchers struct {
cond *sync.Cond
mapsWatcher *k8sapi.Watcher[*kates.ConfigMap]
secretWatcher *k8sapi.Watcher[*kates.Secret]
}
func NewConfigWatchers(ctx context.Context, watchedNs string) *ConfigWatchers {
coreClient := k8sapi.GetK8sInterface(ctx).CoreV1().RESTClient()
cond := &sync.Cond{
L: &sync.Mutex{},
}
return &ConfigWatchers{
mapsWatcher: k8sapi.NewWatcher[*kates.ConfigMap]("configmaps", coreClient, cond,
k8sapi.WithNamespace[*kates.ConfigMap](watchedNs),
k8sapi.WithEquals(func(o1, o2 *kates.ConfigMap) bool {
// TODO equals func to prevent over-broadcasting
return false
})),
secretWatcher: k8sapi.NewWatcher[*kates.Secret]("secrets", coreClient, cond,
k8sapi.WithNamespace[*kates.Secret](watchedNs),
k8sapi.WithEquals(func(o1, o2 *kates.Secret) bool {
// TODO equals func to prevent over-broadcasting
return false
})),
cond: cond,
}
}
func (w *ConfigWatchers) EnsureStarted(ctx context.Context) error {
if err := w.mapsWatcher.EnsureStarted(ctx, nil); err != nil {
return err
}
return w.secretWatcher.EnsureStarted(ctx, nil)
}