Skip to content

Commit bed6efa

Browse files
committed
Add force and reset flags to flux reconcile hr
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
1 parent 7cf0451 commit bed6efa

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

cmd/flux/reconcile.go

+20-7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"k8s.io/client-go/util/retry"
3232
"sigs.k8s.io/controller-runtime/pkg/client"
3333

34+
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
3435
"github.com/fluxcd/pkg/apis/meta"
3536

3637
"github.com/fluxcd/flux2/v2/internal/utils"
@@ -166,14 +167,26 @@ func requestReconciliation(ctx context.Context, kubeClient client.Client,
166167
return err
167168
}
168169
patch := client.MergeFrom(object.DeepCopy())
169-
if ann := object.GetAnnotations(); ann == nil {
170-
object.SetAnnotations(map[string]string{
171-
meta.ReconcileRequestAnnotation: time.Now().Format(time.RFC3339Nano),
172-
})
173-
} else {
174-
ann[meta.ReconcileRequestAnnotation] = time.Now().Format(time.RFC3339Nano)
175-
object.SetAnnotations(ann)
170+
171+
// Add a timestamp annotation to trigger a reconciliation.
172+
ts := time.Now().Format(time.RFC3339Nano)
173+
annotations := object.GetAnnotations()
174+
if annotations == nil {
175+
annotations = make(map[string]string, 1)
176+
}
177+
annotations[meta.ReconcileRequestAnnotation] = ts
178+
179+
// HelmRelease specific annotations to force or reset a release.
180+
if gvk.Kind == helmv2.HelmReleaseKind {
181+
if rhrArgs.syncForce {
182+
annotations["reconcile.fluxcd.io/forceAt"] = ts
183+
}
184+
if rhrArgs.syncReset {
185+
annotations["reconcile.fluxcd.io/resetAt"] = ts
186+
}
176187
}
188+
189+
object.SetAnnotations(annotations)
177190
return kubeClient.Patch(ctx, object, patch)
178191
})
179192
}

cmd/flux/reconcile_helmrelease.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,16 @@ The reconcile kustomization command triggers a reconciliation of a HelmRelease r
4646

4747
type reconcileHelmReleaseFlags struct {
4848
syncHrWithSource bool
49+
syncForce bool
50+
syncReset bool
4951
}
5052

5153
var rhrArgs reconcileHelmReleaseFlags
5254

5355
func init() {
5456
reconcileHrCmd.Flags().BoolVar(&rhrArgs.syncHrWithSource, "with-source", false, "reconcile HelmRelease source")
55-
57+
reconcileHrCmd.Flags().BoolVar(&rhrArgs.syncForce, "force", false, "force a one-off install or upgrade of the HelmRelease resource")
58+
reconcileHrCmd.Flags().BoolVar(&rhrArgs.syncReset, "reset", false, "reset the reset the failure count for this HelmRelease resource")
5659
reconcileCmd.AddCommand(reconcileHrCmd)
5760
}
5861

0 commit comments

Comments
 (0)