From 38da7487698381d90bbfeda96b12c61a6791bc1a Mon Sep 17 00:00:00 2001 From: Andrei Pavlov Date: Mon, 7 Oct 2024 15:55:00 +0700 Subject: [PATCH] Reconcile default helm repo in the release controller Signed-off-by: Andrei Pavlov --- cmd/main.go | 6 ++++++ internal/controller/release_controller.go | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 161b9a53b..4da306c2c 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -264,6 +264,12 @@ func main() { CreateRelease: createRelease, HMCTemplatesChartName: hmcTemplatesChartName, SystemNamespace: currentNamespace, + DefaultRegistryConfig: helm.DefaultRegistryConfig{ + URL: defaultRegistryURL, + RepoType: determinedRepositoryType, + CredentialsSecret: registryCredentialsSecret, + Insecure: insecureRegistry, + }, }).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "Release") os.Exit(1) diff --git a/internal/controller/release_controller.go b/internal/controller/release_controller.go index 452df0a5d..bb3af7bac 100644 --- a/internal/controller/release_controller.go +++ b/internal/controller/release_controller.go @@ -56,6 +56,8 @@ type ReleaseReconciler struct { HMCTemplatesChartName string SystemNamespace string + + DefaultRegistryConfig helm.DefaultRegistryConfig } func (r *ReleaseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { @@ -150,8 +152,8 @@ func (r *ReleaseReconciler) ensureManagement(ctx context.Context) error { func (r *ReleaseReconciler) reconcileHMCTemplates(ctx context.Context, req ctrl.Request) error { l := ctrl.LoggerFrom(ctx) - if !r.CreateRelease { - l.Info("Reconciling HMC Templates is skipped") + if initialReconcile(req) && !r.CreateRelease { + l.Info("Initial creation of HMC Release is skipped") return nil } name := utils.ReleaseNameFromVersion(build.Version) @@ -175,6 +177,14 @@ func (r *ReleaseReconciler) reconcileHMCTemplates(ctx context.Context, req ctrl. } } + if initialReconcile(req) { + err := helm.ReconcileHelmRepository(ctx, r.Client, defaultRepoName, r.SystemNamespace, r.DefaultRegistryConfig.HelmRepositorySpec()) + if err != nil { + l.Error(err, "Failed to reconcile default HelmRepository", "namespace", r.SystemNamespace) + return err + } + } + helmChart := &sourcev1.HelmChart{ ObjectMeta: metav1.ObjectMeta{ Name: name,