/
watch_kubeconfigs.go
42 lines (33 loc) · 1.39 KB
/
watch_kubeconfigs.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
package multicluster
import (
"context"
v1 "github.com/solo-io/solo-kit/pkg/multicluster/v1"
"github.com/solo-io/solo-kit/pkg/api/v1/clients"
"github.com/solo-io/solo-kit/pkg/api/v1/clients/factory"
"github.com/solo-io/solo-kit/pkg/api/v1/clients/kube/cache"
"github.com/solo-io/solo-kit/pkg/multicluster/secretconverter"
"k8s.io/client-go/kubernetes"
)
// empty ClusterId refers to local
const LocalCluster = ""
type KubeConfigWatcher interface {
WatchKubeConfigs(ctx context.Context, kube kubernetes.Interface, cache cache.KubeCoreCache) (<-chan v1.KubeConfigList, <-chan error, error)
}
type defaultKubeConfigWatcher struct{}
func NewKubeConfigWatcher() KubeConfigWatcher {
return &defaultKubeConfigWatcher{}
}
func (kcw *defaultKubeConfigWatcher) WatchKubeConfigs(ctx context.Context, kube kubernetes.Interface, cache cache.KubeCoreCache) (<-chan v1.KubeConfigList, <-chan error, error) {
return WatchKubeConfigs(ctx, kube, cache)
}
func WatchKubeConfigs(ctx context.Context, kube kubernetes.Interface, cache cache.KubeCoreCache) (<-chan v1.KubeConfigList, <-chan error, error) {
kubeConfigClient, err := v1.NewKubeConfigClient(ctx, &factory.KubeSecretClientFactory{
Clientset: kube,
Cache: cache,
SecretConverter: &secretconverter.KubeConfigSecretConverter{},
})
if err != nil {
return nil, nil, err
}
return kubeConfigClient.Watch("", clients.WatchOpts{Ctx: ctx})
}