Skip to content

Commit 765d570

Browse files
committed
Fix the creation of the cachedClient for the openshift-config-managed namespace
kubernetes-sigs/controller-runtime#2150 deprecated the DelegatedClient and added the CacheOption to the client.Options struct. This commit sync the newConfigManagedClient method with that deprecation.
1 parent b79e257 commit 765d570

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

cmd/manager/main.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ import (
3434
"k8s.io/klog/v2/klogr"
3535
ctrl "sigs.k8s.io/controller-runtime"
3636
"sigs.k8s.io/controller-runtime/pkg/cache"
37+
"sigs.k8s.io/controller-runtime/pkg/client"
3738
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
3839
"sigs.k8s.io/controller-runtime/pkg/client/config"
39-
"sigs.k8s.io/controller-runtime/pkg/cluster"
4040
"sigs.k8s.io/controller-runtime/pkg/controller"
4141
"sigs.k8s.io/controller-runtime/pkg/healthz"
4242
"sigs.k8s.io/controller-runtime/pkg/manager"
@@ -203,24 +203,31 @@ func main() {
203203
// namespace.
204204
func newConfigManagedClient(mgr manager.Manager) (runtimeclient.Client, manager.Runnable, error) {
205205
cacheOpts := cache.Options{
206-
Scheme: mgr.GetScheme(),
207-
Mapper: mgr.GetRESTMapper(),
208-
Namespace: awsclient.KubeCloudConfigNamespace,
206+
Scheme: mgr.GetScheme(),
207+
Mapper: mgr.GetRESTMapper(),
208+
Namespaces: []string{
209+
awsclient.KubeCloudConfigNamespace,
210+
},
209211
}
210-
cache, err := cache.New(mgr.GetConfig(), cacheOpts)
212+
cacheReader, err := cache.New(mgr.GetConfig(), cacheOpts)
211213
if err != nil {
212214
return nil, nil, err
213215
}
214216

215217
clientOpts := runtimeclient.Options{
216218
Scheme: mgr.GetScheme(),
217219
Mapper: mgr.GetRESTMapper(),
220+
Cache: &client.CacheOptions{
221+
Reader: cacheReader,
222+
DisableFor: nil,
223+
Unstructured: false,
224+
},
218225
}
219226

220-
cachedClient, err := cluster.DefaultNewClient(cache, config.GetConfigOrDie(), clientOpts)
227+
cachedClient, err := client.New(config.GetConfigOrDie(), clientOpts)
221228
if err != nil {
222229
return nil, nil, err
223230
}
224231

225-
return cachedClient, cache, nil
232+
return cachedClient, cacheReader, nil
226233
}

0 commit comments

Comments
 (0)