Skip to content

Commit

Permalink
kube: unify clients into single RESTClientGetter
Browse files Browse the repository at this point in the history
This drops the twofold implementation in favor of a single
`MemoryRESTClientGetter` which can work with an arbitrary `rest.Config`.

The new `MemoryRESTClientGetter` lazy-loads and caches the objects it
initializes, thereby creating at most one instance of each object for
the duration of the reconcile of a single `HelmRelease` object.

Based on some initial tests, this seems to reduce the overal memory
footprint of the controller.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
  • Loading branch information
hiddeco committed Mar 6, 2023
1 parent 90a03d0 commit 247ba12
Show file tree
Hide file tree
Showing 7 changed files with 407 additions and 466 deletions.
9 changes: 5 additions & 4 deletions controllers/helmrelease_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,8 @@ func (r *HelmReleaseReconciler) checkDependencies(hr v2.HelmRelease) error {
}

func (r *HelmReleaseReconciler) buildRESTClientGetter(ctx context.Context, hr v2.HelmRelease) (genericclioptions.RESTClientGetter, error) {
opts := []kube.ClientGetterOption{
opts := []kube.Option{
kube.WithNamespace(hr.GetReleaseNamespace()),
kube.WithClientOptions(r.ClientOpts),
// When ServiceAccountName is empty, it will fall back to the configured default.
// If this is not configured either, this option will result in a no-op.
Expand All @@ -535,13 +536,13 @@ func (r *HelmReleaseReconciler) buildRESTClientGetter(ctx context.Context, hr v2
if err := r.Get(ctx, secretName, &secret); err != nil {
return nil, fmt.Errorf("could not find KubeConfig secret '%s': %w", secretName, err)
}
kubeConfig, err := kube.ConfigFromSecret(&secret, hr.Spec.KubeConfig.SecretRef.Key)
kubeConfig, err := kube.ConfigFromSecret(&secret, hr.Spec.KubeConfig.SecretRef.Key, r.KubeConfigOpts)
if err != nil {
return nil, err
}
opts = append(opts, kube.WithKubeConfig(kubeConfig, r.KubeConfigOpts))
return kube.NewMemoryRESTClientGetter(kubeConfig, opts...), nil
}
return kube.BuildClientGetter(hr.GetReleaseNamespace(), opts...)
return kube.NewInClusterMemoryRESTClientGetter(opts...)
}

// composeValues attempts to resolve all v2beta1.ValuesReference resources
Expand Down
89 changes: 0 additions & 89 deletions internal/kube/builder.go

This file was deleted.

121 changes: 0 additions & 121 deletions internal/kube/builder_test.go

This file was deleted.

Loading

0 comments on commit 247ba12

Please sign in to comment.