-
Notifications
You must be signed in to change notification settings - Fork 79
/
config_sync.go
48 lines (41 loc) · 1.16 KB
/
config_sync.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
package params
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/informers"
"k8s.io/client-go/tools/cache"
"knative.dev/pkg/system"
)
func StartConfigSync(ctx context.Context, run *Run) {
// init pac config
_ = run.UpdatePacConfig(ctx)
informerFactory := informers.NewSharedInformerFactoryWithOptions(run.Clients.Kube, 0,
informers.WithNamespace(system.Namespace()),
informers.WithTweakListOptions(func(opts *metav1.ListOptions) {
opts.FieldSelector = fmt.Sprintf("metadata.name=%s", run.Info.Controller.Configmap)
}))
informer := informerFactory.Core().V1().ConfigMaps().Informer()
_, _ = informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(_ interface{}) {
// nothing to do
},
UpdateFunc: func(_, _ interface{}) {
_ = run.UpdatePacConfig(ctx)
},
DeleteFunc: func(_ interface{}) {
// nothing to do
},
})
stopCh := make(chan struct{})
defer close(stopCh)
// start the informer
informer.Run(stopCh)
// Wait for termination signal to stop the informer
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
<-sig
}