From bed6efa6712a86146f16eca540882e6922ffea30 Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Thu, 30 Nov 2023 10:33:36 +0200 Subject: [PATCH] Add force and reset flags to `flux reconcile hr` Signed-off-by: Stefan Prodan --- cmd/flux/reconcile.go | 27 ++++++++++++++++++++------- cmd/flux/reconcile_helmrelease.go | 5 ++++- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/cmd/flux/reconcile.go b/cmd/flux/reconcile.go index c6c7a4720f..fc6334b6a2 100644 --- a/cmd/flux/reconcile.go +++ b/cmd/flux/reconcile.go @@ -31,6 +31,7 @@ import ( "k8s.io/client-go/util/retry" "sigs.k8s.io/controller-runtime/pkg/client" + helmv2 "github.com/fluxcd/helm-controller/api/v2beta1" "github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/flux2/v2/internal/utils" @@ -166,14 +167,26 @@ func requestReconciliation(ctx context.Context, kubeClient client.Client, return err } patch := client.MergeFrom(object.DeepCopy()) - if ann := object.GetAnnotations(); ann == nil { - object.SetAnnotations(map[string]string{ - meta.ReconcileRequestAnnotation: time.Now().Format(time.RFC3339Nano), - }) - } else { - ann[meta.ReconcileRequestAnnotation] = time.Now().Format(time.RFC3339Nano) - object.SetAnnotations(ann) + + // Add a timestamp annotation to trigger a reconciliation. + ts := time.Now().Format(time.RFC3339Nano) + annotations := object.GetAnnotations() + if annotations == nil { + annotations = make(map[string]string, 1) + } + annotations[meta.ReconcileRequestAnnotation] = ts + + // HelmRelease specific annotations to force or reset a release. + if gvk.Kind == helmv2.HelmReleaseKind { + if rhrArgs.syncForce { + annotations["reconcile.fluxcd.io/forceAt"] = ts + } + if rhrArgs.syncReset { + annotations["reconcile.fluxcd.io/resetAt"] = ts + } } + + object.SetAnnotations(annotations) return kubeClient.Patch(ctx, object, patch) }) } diff --git a/cmd/flux/reconcile_helmrelease.go b/cmd/flux/reconcile_helmrelease.go index b55a12954d..145b6dc9b5 100644 --- a/cmd/flux/reconcile_helmrelease.go +++ b/cmd/flux/reconcile_helmrelease.go @@ -46,13 +46,16 @@ The reconcile kustomization command triggers a reconciliation of a HelmRelease r type reconcileHelmReleaseFlags struct { syncHrWithSource bool + syncForce bool + syncReset bool } var rhrArgs reconcileHelmReleaseFlags func init() { reconcileHrCmd.Flags().BoolVar(&rhrArgs.syncHrWithSource, "with-source", false, "reconcile HelmRelease source") - + reconcileHrCmd.Flags().BoolVar(&rhrArgs.syncForce, "force", false, "force a one-off install or upgrade of the HelmRelease resource") + reconcileHrCmd.Flags().BoolVar(&rhrArgs.syncReset, "reset", false, "reset the reset the failure count for this HelmRelease resource") reconcileCmd.AddCommand(reconcileHrCmd) }