From 2872f246825e7d1179655b63a66d6837bb98784e Mon Sep 17 00:00:00 2001 From: Jimmi Dyson Date: Thu, 14 Mar 2024 11:31:40 +0000 Subject: [PATCH] refactor: Move cluster paused check to per-cluster reconciliation func --- controllers/helmchartproxy/helmchartproxy_controller.go | 6 ------ .../helmchartproxy/helmchartproxy_controller_phases.go | 7 +++++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/controllers/helmchartproxy/helmchartproxy_controller.go b/controllers/helmchartproxy/helmchartproxy_controller.go index d5fd3190..4636feef 100644 --- a/controllers/helmchartproxy/helmchartproxy_controller.go +++ b/controllers/helmchartproxy/helmchartproxy_controller.go @@ -218,12 +218,6 @@ func (r *HelmChartProxyReconciler) reconcileNormal(ctx context.Context, helmChar continue } - // Don't reconcile if the Cluster is paused. - if cluster.Spec.Paused { - log.V(2).Info("Cluster is paused, skipping reconcile", "cluster", cluster.Name) - continue - } - err := r.reconcileForCluster(ctx, helmChartProxy, cluster) if err != nil { return err diff --git a/controllers/helmchartproxy/helmchartproxy_controller_phases.go b/controllers/helmchartproxy/helmchartproxy_controller_phases.go index 09f6ee97..dc820e2c 100644 --- a/controllers/helmchartproxy/helmchartproxy_controller_phases.go +++ b/controllers/helmchartproxy/helmchartproxy_controller_phases.go @@ -29,6 +29,7 @@ import ( "sigs.k8s.io/cluster-api-addon-provider-helm/internal" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/util" + "sigs.k8s.io/cluster-api/util/annotations" "sigs.k8s.io/cluster-api/util/conditions" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -57,6 +58,12 @@ func (r *HelmChartProxyReconciler) deleteOrphanedHelmReleaseProxies(ctx context. func (r *HelmChartProxyReconciler) reconcileForCluster(ctx context.Context, helmChartProxy *addonsv1alpha1.HelmChartProxy, cluster clusterv1.Cluster) error { log := ctrl.LoggerFrom(ctx) + // Don't reconcile if the Cluster or the helmChartProxy is paused. + if annotations.IsPaused(&cluster, helmChartProxy) { + log.V(2).Info("Reconciliation is paused for this Cluster", "cluster", cluster.Name) + return nil + } + existingHelmReleaseProxy, err := r.getExistingHelmReleaseProxy(ctx, helmChartProxy, &cluster) if err != nil { // TODO: Should we set a condition here?