@@ -21,16 +21,23 @@ import (
2121 "fmt"
2222 "os"
2323
24+ corev1 "k8s.io/api/core/v1"
2425 "k8s.io/apimachinery/pkg/api/equality"
2526 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2627 "k8s.io/apimachinery/pkg/runtime"
2728 "k8s.io/apimachinery/pkg/runtime/serializer"
2829 ctrl "sigs.k8s.io/controller-runtime"
30+ ctrlcache "sigs.k8s.io/controller-runtime/pkg/cache"
31+ ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
2932 "sigs.k8s.io/controller-runtime/pkg/webhook"
3033
3134 configapi "sigs.k8s.io/kueue/apis/config/v1beta1"
3235)
3336
37+ var (
38+ objectKeySecret = new (corev1.Secret )
39+ )
40+
3441// fromFile provides an alternative to the deprecated ctrl.ConfigFile().AtPath(path).OfKind(&cfg)
3542func fromFile (path string , scheme * runtime.Scheme , cfg * configapi.Configuration ) error {
3643 content , err := os .ReadFile (path )
@@ -48,6 +55,8 @@ func fromFile(path string, scheme *runtime.Scheme, cfg *configapi.Configuration)
4855// addTo provides an alternative to the deprecated o.AndFrom(&cfg)
4956func addTo (o * ctrl.Options , cfg * configapi.Configuration ) {
5057 addLeaderElectionTo (o , cfg )
58+ addCacheByObjectTo (o , cfg )
59+
5160 if o .Metrics .BindAddress == "" && cfg .Metrics .BindAddress != "" {
5261 o .Metrics .BindAddress = cfg .Metrics .BindAddress
5362 }
@@ -94,6 +103,24 @@ func addTo(o *ctrl.Options, cfg *configapi.Configuration) {
94103 }
95104}
96105
106+ func addCacheByObjectTo (o * ctrl.Options , cfg * configapi.Configuration ) {
107+ if cfg .Namespace == nil {
108+ // Invalid source; noop. This should not be reached
109+ // due to prior defaulting/validation.
110+ return
111+ }
112+
113+ if o .Cache .ByObject == nil {
114+ o .Cache .ByObject = make (map [ctrlclient.Object ]ctrlcache.ByObject )
115+ }
116+
117+ o .Cache .ByObject [objectKeySecret ] = ctrlcache.ByObject {
118+ Namespaces : map [string ]ctrlcache.Config {
119+ * cfg .Namespace : {},
120+ },
121+ }
122+ }
123+
97124func addLeaderElectionTo (o * ctrl.Options , cfg * configapi.Configuration ) {
98125 if cfg .LeaderElection == nil {
99126 // The source does not have any configuration; noop
0 commit comments