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 Jun 26, 2023
1 parent aa66b29 commit c5b0f24
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, errors.Wrap(err, "cannot create dynamic REST mapper for Kubernetes client")
}
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 c5b0f24

Please sign in to comment.