flant / addon-operator

A system to manage additional components for Kubernetes cluster in a simple, consistent and automated way.
https://flant.github.io/addon-operator/
Apache License 2.0
483 stars 27 forks source link

feat: Persist helm3lib Kubernetes clients #374

Closed nabokihms closed 1 year ago

nabokihms commented 1 year ago

Overview

What this PR does / why we need it

This PR prevents instantiating the REST client multiple times. In our current configuration, helm discovery actively allocates memory, which makes GC executions more frequent. The full description can be found here.

image image image

Benchmark results for getting the REST client with the previously used env getter and the new persistent getter:

goos: darwin
goarch: amd64
pkg: github.com/flant/addon-operator/pkg/helm/helm3lib
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
BenchmarkRESTMapper/Env_client-12                   1413            790653 ns/op          183872 B/op       1939 allocs/op
BenchmarkRESTMapper/Persistent_client-12        44701933             27.69 ns/op               0 B/op          0 allocs/op

Special notes for your reviewer

Requires deep testing because this can lead to issues in cases when CRDs are deployed to the cluster, which means new resource types are dynamically added to a cluster.

Another way to solve the problem is to use a single client for all operations with Kubernetes.

Does this PR introduce a user-facing change?

Persist helm3lib Kubernetes clients.