Skip to content

Commit

Permalink
Fix the creation of the cachedClient for the openshift-config-managed…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
aleskandro committed Jun 1, 2023
1 parent a2b4aa0 commit e23d0f3
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import (
"k8s.io/klog/v2/klogr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/cluster"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand Down Expand Up @@ -203,24 +203,31 @@ func main() {
// namespace.
func newConfigManagedClient(mgr manager.Manager) (runtimeclient.Client, manager.Runnable, error) {
cacheOpts := cache.Options{
Scheme: mgr.GetScheme(),
Mapper: mgr.GetRESTMapper(),
Namespace: awsclient.KubeCloudConfigNamespace,
Scheme: mgr.GetScheme(),
Mapper: mgr.GetRESTMapper(),
Namespaces: []string{
awsclient.KubeCloudConfigNamespace,
},
}
cache, err := cache.New(mgr.GetConfig(), cacheOpts)
cacheReader, err := cache.New(mgr.GetConfig(), cacheOpts)
if err != nil {
return nil, nil, err
}

clientOpts := runtimeclient.Options{
Scheme: mgr.GetScheme(),
Mapper: mgr.GetRESTMapper(),
Cache: &client.CacheOptions{
Reader: cacheReader,
DisableFor: nil,
Unstructured: false,
},
}

cachedClient, err := cluster.DefaultNewClient(cache, config.GetConfigOrDie(), clientOpts)
cachedClient, err := client.New(config.GetConfigOrDie(), clientOpts)
if err != nil {
return nil, nil, err
}

return cachedClient, cache, nil
return cachedClient, cacheReader, nil
}

0 comments on commit e23d0f3

Please sign in to comment.