From 3f65b45e4ab84fb44ff3b947d25580bcffb47e83 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Thu, 30 Mar 2023 12:01:11 +0200 Subject: [PATCH] api: add `PersistentClient` flag to allow control This adds a `PersistentClient` flag which should be consumed by the controller while initializing the Kubernetes client used by Helm actions. This to allow the controller to work with certain charts which do require a client which does not persist, as they create Custom Resource Definitions on demand during e.g. install, which then later aren't observed by Helm as it does not reset the REST mapper between successive action steps. Signed-off-by: Hidde Beydals --- api/v2beta1/helmrelease_types.go | 24 +++++++++++ api/v2beta1/zz_generated.deepcopy.go | 5 +++ .../helm.toolkit.fluxcd.io_helmreleases.yaml | 11 +++++ docs/api/helmrelease.md | 40 +++++++++++++++++++ docs/spec/v2beta1/helmreleases.md | 15 +++++++ 5 files changed, 95 insertions(+) diff --git a/api/v2beta1/helmrelease_types.go b/api/v2beta1/helmrelease_types.go index 1cec7f3..9a6cbd6 100644 --- a/api/v2beta1/helmrelease_types.go +++ b/api/v2beta1/helmrelease_types.go @@ -137,6 +137,21 @@ type HelmReleaseSpec struct { // +optional ServiceAccountName string `json:"serviceAccountName,omitempty"` + // PersistentClient tells the controller to use a persistent Kubernetes + // client for this release. When enabled, the client will be reused for the + // duration of the reconciliation, instead of being created and destroyed + // for each (step of a) Helm action. + // + // This can improve performance, but may cause issues with some Helm charts + // that for example do create Custom Resource Definitions during installation + // outside Helm's CRD lifecycle hooks, which are then not observed to be + // available by e.g. post-install hooks. + // + // If not set, it defaults to true. + // + // +optional + PersistentClient *bool `json:"persistentClient,omitempty"` + // Install holds the configuration for Helm install actions for this HelmRelease. // +optional Install *Install `json:"install,omitempty"` @@ -1039,6 +1054,15 @@ func (in HelmRelease) GetMaxHistory() int { return *in.Spec.MaxHistory } +// UsePersistentClient returns the configured PersistentClient, or the default +// of true. +func (in HelmRelease) UsePersistentClient() bool { + if in.Spec.PersistentClient == nil { + return true + } + return *in.Spec.PersistentClient +} + // GetDependsOn returns the list of dependencies across-namespaces. func (in HelmRelease) GetDependsOn() []meta.NamespacedObjectReference { return in.Spec.DependsOn diff --git a/api/v2beta1/zz_generated.deepcopy.go b/api/v2beta1/zz_generated.deepcopy.go index 252c475..314b34d 100644 --- a/api/v2beta1/zz_generated.deepcopy.go +++ b/api/v2beta1/zz_generated.deepcopy.go @@ -225,6 +225,11 @@ func (in *HelmReleaseSpec) DeepCopyInto(out *HelmReleaseSpec) { *out = new(int) **out = **in } + if in.PersistentClient != nil { + in, out := &in.PersistentClient, &out.PersistentClient + *out = new(bool) + **out = **in + } if in.Install != nil { in, out := &in.Install, &out.Install *out = new(Install) diff --git a/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml b/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml index 8e60df4..80dbdb6 100644 --- a/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml +++ b/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml @@ -322,6 +322,17 @@ spec: this HelmRelease. Use '0' for an unlimited number of revisions; defaults to '10'. type: integer + persistentClient: + description: "PersistentClient tells the controller to use a persistent + Kubernetes client for this release. When enabled, the client will + be reused for the duration of the reconciliation, instead of being + created and destroyed for each (step of a) Helm action. \n This + can improve performance, but may cause issues with some Helm charts + that for example do create Custom Resource Definitions during installation + outside Helm's CRD lifecycle hooks, which are then not observed + to be available by e.g. post-install hooks. \n If not set, it defaults + to true." + type: boolean postRenderers: description: PostRenderers holds an array of Helm PostRenderers, which will be applied in order of their definition. diff --git a/docs/api/helmrelease.md b/docs/api/helmrelease.md index 844aa2d..c1f5bcd 100644 --- a/docs/api/helmrelease.md +++ b/docs/api/helmrelease.md @@ -226,6 +226,26 @@ when reconciling this HelmRelease.

+persistentClient
+ +bool + + + +(Optional) +

PersistentClient tells the controller to use a persistent Kubernetes +client for this release. When enabled, the client will be reused for the +duration of the reconciliation, instead of being created and destroyed +for each (step of a) Helm action.

+

This can improve performance, but may cause issues with some Helm charts +that for example do create Custom Resource Definitions during installation +outside Helm’s CRD lifecycle hooks, which are then not observed to be +available by e.g. post-install hooks.

+

If not set, it defaults to true.

+ + + + install
@@ -1015,6 +1035,26 @@ when reconciling this HelmRelease.

+persistentClient
+ +bool + + + +(Optional) +

PersistentClient tells the controller to use a persistent Kubernetes +client for this release. When enabled, the client will be reused for the +duration of the reconciliation, instead of being created and destroyed +for each (step of a) Helm action.

+

This can improve performance, but may cause issues with some Helm charts +that for example do create Custom Resource Definitions during installation +outside Helm’s CRD lifecycle hooks, which are then not observed to be +available by e.g. post-install hooks.

+

If not set, it defaults to true.

+ + + + install
diff --git a/docs/spec/v2beta1/helmreleases.md b/docs/spec/v2beta1/helmreleases.md index 8dfe392..7ff257a 100644 --- a/docs/spec/v2beta1/helmreleases.md +++ b/docs/spec/v2beta1/helmreleases.md @@ -66,6 +66,21 @@ type HelmReleaseSpec struct { // +optional MaxHistory *int `json:"maxHistory,omitempty"` + // PersistentClient tells the controller to use a persistent Kubernetes + // client for this release. When enabled, the client will be reused for the + // duration of the reconciliation, instead of being created and destroyed + // for each (step of a) Helm action. + // + // This can improve performance, but may cause issues with some Helm charts + // that for example do create Custom Resource Definitions during installation + // outside Helm's CRD lifecycle hooks, which are then not observed to be + // available by e.g. post-install hooks. + // + // If not set, it defaults to true. + // + // +optional + PersistentClient *bool `json:"persistentClient,omitempty"` + // Install holds the configuration for Helm install actions for this HelmRelease. // +optional Install *Install `json:"install,omitempty"`