forked from kubeedge/kubeedge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
secret.go
34 lines (28 loc) · 1.05 KB
/
secret.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
package manager
import (
"github.com/kubeedge/kubeedge/cloud/pkg/controller/config"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/cache"
)
// SecretManager manage all events of secret by SharedInformer
type SecretManager struct {
events chan watch.Event
}
// Events return the channel save events from watch secret change
func (sm *SecretManager) Events() chan watch.Event {
return sm.events
}
// NewSecretManager create SecretManager by kube clientset and namespace
func NewSecretManager(kubeClient *kubernetes.Clientset, namespace string) (*SecretManager, error) {
lw := cache.NewListWatchFromClient(kubeClient.CoreV1().RESTClient(), "secrets", namespace, fields.Everything())
events := make(chan watch.Event, config.SecretEventBuffer)
rh := NewCommonResourceEventHandler(events)
si := cache.NewSharedInformer(lw, &v1.Secret{}, 0)
si.AddEventHandler(rh)
stopNever := make(chan struct{})
go si.Run(stopNever)
return &SecretManager{events: events}, nil
}