From 71c17b39fbacd4710bb906fe9135c3991b9a93a4 Mon Sep 17 00:00:00 2001 From: Joe Julian Date: Tue, 5 Sep 2023 14:16:08 -0700 Subject: [PATCH] add public controller interface --- controller/helmrelease_controller.go | 75 ++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 controller/helmrelease_controller.go diff --git a/controller/helmrelease_controller.go b/controller/helmrelease_controller.go new file mode 100644 index 000000000..b4b77901f --- /dev/null +++ b/controller/helmrelease_controller.go @@ -0,0 +1,75 @@ +/* +Copyright 2020 The Flux authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package controller + +import ( + "context" + + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/client-go/rest" + kuberecorder "k8s.io/client-go/tools/record" + "sigs.k8s.io/cli-utils/pkg/kstatus/polling" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + + internalController "github.com/fluxcd/helm-controller/internal/controller" + runtimeClient "github.com/fluxcd/pkg/runtime/client" + helper "github.com/fluxcd/pkg/runtime/controller" +) + +type HelmReleaseReconciler struct { + client.Client + helper.Metrics + + Config *rest.Config + Scheme *runtime.Scheme + EventRecorder kuberecorder.EventRecorder + DefaultServiceAccount string + NoCrossNamespaceRef bool + ClientOpts runtimeClient.Options + KubeConfigOpts runtimeClient.KubeConfigOptions + StatusPoller *polling.StatusPoller + PollingOpts polling.Options + ControllerName string + + helmReleaseReconciler *internalController.HelmReleaseReconciler +} + +type HelmReleaseReconcilerOptions internalController.HelmReleaseReconcilerOptions + +func (r *HelmReleaseReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opts HelmReleaseReconcilerOptions) error { + r.helmReleaseReconciler = &internalController.HelmReleaseReconciler{ + Client: r.Client, + Metrics: r.Metrics, + Config: r.Config, + Scheme: r.Scheme, + EventRecorder: r.EventRecorder, + DefaultServiceAccount: r.DefaultServiceAccount, + NoCrossNamespaceRef: r.NoCrossNamespaceRef, + ClientOpts: r.ClientOpts, + KubeConfigOpts: r.KubeConfigOpts, + StatusPoller: r.StatusPoller, + PollingOpts: r.PollingOpts, + ControllerName: r.ControllerName, + } + o := internalController.HelmReleaseReconcilerOptions{ + HTTPRetry: opts.HTTPRetry, + DependencyRequeueInterval: opts.DependencyRequeueInterval, + RateLimiter: opts.RateLimiter, + } + return r.helmReleaseReconciler.SetupWithManager(ctx, mgr, o) +}