From 409f515d73576c93f6e20233ddfc84f87f024171 Mon Sep 17 00:00:00 2001 From: Giorgia Fiscaletti Date: Thu, 24 Aug 2023 16:36:04 +0200 Subject: [PATCH] feat: add helm storage driver variable and flag Signed-off-by: Giorgia Fiscaletti --- internal/controller/helmrelease_controller.go | 5 +++-- internal/runner/runner.go | 9 +++++---- main.go | 12 ++++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/internal/controller/helmrelease_controller.go b/internal/controller/helmrelease_controller.go index afd58a6a2..749970c9a 100644 --- a/internal/controller/helmrelease_controller.go +++ b/internal/controller/helmrelease_controller.go @@ -89,6 +89,7 @@ type HelmReleaseReconciler struct { StatusPoller *polling.StatusPoller PollingOpts polling.Options ControllerName string + HelmStorageDriver string httpClient *retryablehttp.Client requeueDependency time.Duration @@ -294,7 +295,7 @@ func (r *HelmReleaseReconciler) reconcileRelease(ctx context.Context, if err != nil { return v2.HelmReleaseNotReady(hr, v2.InitFailedReason, err.Error()), err } - run, err := runner.NewRunner(getter, hr.GetStorageNamespace(), log) + run, err := runner.NewRunner(getter, hr.GetStorageNamespace(), r.HelmStorageDriver, log) if err != nil { return v2.HelmReleaseNotReady(hr, v2.InitFailedReason, "failed to initialize Helm action runner"), err } @@ -682,7 +683,7 @@ func (r *HelmReleaseReconciler) reconcileDelete(ctx context.Context, hr *v2.Helm if err != nil { return ctrl.Result{}, err } - run, err := runner.NewRunner(getter, hr.GetStorageNamespace(), ctrl.LoggerFrom(ctx)) + run, err := runner.NewRunner(getter, hr.GetStorageNamespace(), r.HelmStorageDriver, ctrl.LoggerFrom(ctx)) if err != nil { return ctrl.Result{}, err } diff --git a/internal/runner/runner.go b/internal/runner/runner.go index be0bd355a..d6f7bb41d 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -72,14 +72,15 @@ type Runner struct { } // NewRunner constructs a new Runner configured to run Helm actions with the -// given genericclioptions.RESTClientGetter, and the release and storage -// namespace configured to the provided values. -func NewRunner(getter genericclioptions.RESTClientGetter, storageNamespace string, logger logr.Logger) (*Runner, error) { +// given genericclioptions.RESTClientGetter, the release and storage +// namespace configured to the provided values, and the Helm storage driver +// selected to store release information. +func NewRunner(getter genericclioptions.RESTClientGetter, storageNamespace string, helmStorageDriver string, logger logr.Logger) (*Runner, error) { runner := &Runner{ logBuffer: NewLogBuffer(NewDebugLog(logger.V(runtimelogger.DebugLevel)), defaultBufferSize), } cfg := new(action.Configuration) - if err := cfg.Init(getter, storageNamespace, "secret", NewDebugLog(logger.V(runtimelogger.TraceLevel))); err != nil { + if err := cfg.Init(getter, storageNamespace, helmStorageDriver, NewDebugLog(logger.V(runtimelogger.TraceLevel))); err != nil { return nil, err } // Override the logger used by the Helm actions with the log buffer. diff --git a/main.go b/main.go index a9ea78c13..847ea3c10 100644 --- a/main.go +++ b/main.go @@ -94,6 +94,7 @@ func main() { oomWatchMemoryThreshold uint8 oomWatchMaxMemoryPath string oomWatchCurrentMemoryPath string + helmStorageDriver string ) flag.StringVar(&metricsAddr, "metrics-addr", ":8080", @@ -120,6 +121,8 @@ func main() { "The path to the cgroup memory limit file. Requires feature gate 'OOMWatch' to be enabled. If not set, the path will be automatically detected.") flag.StringVar(&oomWatchCurrentMemoryPath, "oom-watch-current-memory-path", "", "The path to the cgroup current memory usage file. Requires feature gate 'OOMWatch' to be enabled. If not set, the path will be automatically detected.") + flag.StringVar(&helmStorageDriver, "helm-storage-driver", "", + "The Helm storage driver to store release information. If not set, it will default to secret.") clientOptions.BindFlags(flag.CommandLine) logOptions.BindFlags(flag.CommandLine) @@ -152,6 +155,14 @@ func main() { watchNamespace = os.Getenv("RUNTIME_NAMESPACE") } + if helmStorageDriver == "" { + helmDriverEnv, exists := os.LookupEnv("HELM_DRIVER") + if !exists { + helmDriverEnv = "secret" + } + helmStorageDriver = helmDriverEnv + } + watchSelector, err := helper.GetWatchSelector(watchOptions) if err != nil { setupLog.Error(err, "unable to configure watch label selector for manager") @@ -250,6 +261,7 @@ func main() { PollingOpts: pollingOpts, StatusPoller: polling.NewStatusPoller(mgr.GetClient(), mgr.GetRESTMapper(), pollingOpts), ControllerName: controllerName, + HelmStorageDriver: helmStorageDriver, }).SetupWithManager(ctx, mgr, controller.HelmReleaseReconcilerOptions{ DependencyRequeueInterval: requeueDependency, HTTPRetry: httpRetry,