Skip to content

Commit

Permalink
Use lazy rest mapper
Browse files Browse the repository at this point in the history
provider-kubernetes initialized a new kubernetes client for each
reconcile. The REST mapper in controller-runtime used to fetch
information about every CRD in the cluster.

controller-runtime introduced a lazy restmapper which means we don't
have to introduce any complex caching to get a significant performance
boost in provider-kubernetes:

kubernetes-sigs/controller-runtime#2116

This seems to become the default in the next release:

kubernetes-sigs/controller-runtime#2296

But this is so significant that we want to update now:

* CPU reduced from constant throttling at 0.4 cores to 0.04 cores

* CloudWatch / EKS audit log costs reduced significantly (55% for our
  cluster, with a lot of provider-kubernetes resources)

Signed-off-by: Carl Henrik Lunde <chlunde@ifi.uio.no>
  • Loading branch information
chlunde committed May 8, 2023
1 parent 5de349f commit b67df2f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/tools/clientcmd/api"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
)

// NewRESTConfig returns a rest config given a secret with connection information.
Expand All @@ -33,7 +34,14 @@ func NewRESTConfig(kubeconfig []byte) (*rest.Config, error) {
// NewKubeClient returns a kubernetes client given a secret with connection
// information.
func NewKubeClient(config *rest.Config) (client.Client, error) {
kc, err := client.New(config, client.Options{})
// in 0.15 this will be default
mapper, err := apiutil.NewDynamicRESTMapper(config, apiutil.WithExperimentalLazyMapper)
if err != nil {
return nil, err
}
kc, err := client.New(config, client.Options{
Mapper: mapper,
})
if err != nil {
return nil, errors.Wrap(err, "cannot create Kubernetes client")
}
Expand Down

0 comments on commit b67df2f

Please sign in to comment.