Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support other Helm storage backends besides Secrets #760

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions internal/controller/helmrelease_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type HelmReleaseReconciler struct {
StatusPoller *polling.StatusPoller
PollingOpts polling.Options
ControllerName string
HelmStorageDriver string

httpClient *retryablehttp.Client
requeueDependency time.Duration
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
9 changes: 5 additions & 4 deletions internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func main() {
oomWatchMemoryThreshold uint8
oomWatchMaxMemoryPath string
oomWatchCurrentMemoryPath string
helmStorageDriver string
)

flag.StringVar(&metricsAddr, "metrics-addr", ":8080",
Expand All @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down