-
Notifications
You must be signed in to change notification settings - Fork 12
/
utils.go
54 lines (47 loc) · 1.26 KB
/
utils.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
package main
import (
"os"
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
corev1informers "k8s.io/client-go/informers/core/v1"
"k8s.io/client-go/kubernetes"
corev1listers "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/tools/cache"
)
type secretInformer struct {
informer cache.SharedIndexInformer
lister corev1listers.SecretLister
}
func NewSecretInformer(
client kubernetes.Interface,
namespace string,
name string,
resyncPeriod time.Duration,
) corev1informers.SecretInformer {
indexers := cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}
options := func(lo *metav1.ListOptions) {
lo.FieldSelector = fields.OneTermEqualSelector(metav1.ObjectNameField, name).String()
}
informer := corev1informers.NewFilteredSecretInformer(
client,
namespace,
resyncPeriod,
indexers,
options,
)
lister := corev1listers.NewSecretLister(informer.GetIndexer())
return &secretInformer{informer, lister}
}
func (i *secretInformer) Informer() cache.SharedIndexInformer {
return i.informer
}
func (i *secretInformer) Lister() corev1listers.SecretLister {
return i.lister
}
func getEnvWithFallback(name, fallback string) string {
if value := os.Getenv(name); value != "" {
return value
}
return fallback
}