@@ -24,11 +24,16 @@ import (
24
24
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
25
25
// to ensure that exec-entrypoint and run can make use of them.
26
26
_ "k8s.io/client-go/plugin/pkg/client/auth"
27
+ "k8s.io/client-go/rest"
27
28
29
+ corev1 "k8s.io/api/core/v1"
30
+ "k8s.io/apimachinery/pkg/labels"
28
31
"k8s.io/apimachinery/pkg/runtime"
29
32
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
30
33
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
31
34
ctrl "sigs.k8s.io/controller-runtime"
35
+ "sigs.k8s.io/controller-runtime/pkg/cache"
36
+ "sigs.k8s.io/controller-runtime/pkg/client"
32
37
"sigs.k8s.io/controller-runtime/pkg/healthz"
33
38
"sigs.k8s.io/controller-runtime/pkg/log/zap"
34
39
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
@@ -133,6 +138,11 @@ func main() {
133
138
metricsServerOptions .FilterProvider = filters .WithAuthenticationAndAuthorization
134
139
}
135
140
141
+ cacheObjLabelSelector := labels .SelectorFromSet (map [string ]string {
142
+ "app.kubernetes.io/managed-by" : "sealos" ,
143
+ "app.kubernetes.io/part-of" : "devbox" ,
144
+ })
145
+
136
146
mgr , err := ctrl .NewManager (ctrl .GetConfigOrDie (), ctrl.Options {
137
147
Scheme : scheme ,
138
148
Metrics : metricsServerOptions ,
@@ -151,6 +161,15 @@ func main() {
151
161
// if you are doing or is intended to do any operation such as perform cleanups
152
162
// after the manager stops then its usage might be unsafe.
153
163
// LeaderElectionReleaseOnCancel: true,
164
+
165
+ NewCache : func (config * rest.Config , opts cache.Options ) (cache.Cache , error ) {
166
+ opts .ByObject = map [client.Object ]cache.ByObject {
167
+ & corev1.Service {}: {Label : cacheObjLabelSelector },
168
+ & corev1.Pod {}: {Label : cacheObjLabelSelector },
169
+ & corev1.Secret {}: {Label : cacheObjLabelSelector },
170
+ }
171
+ return cache .New (config , opts )
172
+ },
154
173
})
155
174
if err != nil {
156
175
setupLog .Error (err , "unable to start manager" )
0 commit comments