-
Notifications
You must be signed in to change notification settings - Fork 15
/
cache.go
31 lines (26 loc) · 925 Bytes
/
cache.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
package controllers
import (
"fmt"
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
)
func CacheCreator(conf *rest.Config, opts cache.Options) (cache.Cache, error) {
labelSelector, err := labels.Parse("app.kubernetes.io/managed-by in (btp-manager,kcp-kyma-environment-broker)")
if err != nil {
panic(fmt.Sprintf("unable to parse label selector: %s", err))
}
objSelector := cache.ByObject{
Label: labelSelector,
}
opts.ByObject = map[client.Object]cache.ByObject{
&corev1.Secret{}: objSelector,
&corev1.ConfigMap{}: objSelector,
&admissionregistrationv1.ValidatingWebhookConfiguration{}: objSelector,
&admissionregistrationv1.MutatingWebhookConfiguration{}: objSelector,
}
return cache.New(conf, opts)
}