Skip to content

Commit 7f6e7f0

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

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
@@ -30,6 +30,7 @@ import (
3030
"k8s.io/client-go/util/retry"
3131
"sigs.k8s.io/controller-runtime/pkg/client"
3232

33+
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
3334
notificationv1 "github.com/fluxcd/notification-controller/api/v1"
3435
notificationv1b2 "github.com/fluxcd/notification-controller/api/v1beta2"
3536
"github.com/fluxcd/pkg/apis/meta"
@@ -163,14 +164,26 @@ func requestReconciliation(ctx context.Context, kubeClient client.Client,
163164
return err
164165
}
165166
patch := client.MergeFrom(object.DeepCopy())
166-
if ann := object.GetAnnotations(); ann == nil {
167-
object.SetAnnotations(map[string]string{
168-
meta.ReconcileRequestAnnotation: time.Now().Format(time.RFC3339Nano),
169-
})
170-
} else {
171-
ann[meta.ReconcileRequestAnnotation] = time.Now().Format(time.RFC3339Nano)
172-
object.SetAnnotations(ann)
167+
168+
// Add a timestamp annotation to trigger a reconciliation.
169+
ts := time.Now().Format(time.RFC3339Nano)
170+
annotations := object.GetAnnotations()
171+
if annotations == nil {
172+
annotations = make(map[string]string, 1)
173+
}
174+
annotations[meta.ReconcileRequestAnnotation] = ts
175+
176+
// HelmRelease specific annotations to force or reset a release.
177+
if gvk.Kind == helmv2.HelmReleaseKind {
178+
if rhrArgs.syncForce {
179+
annotations["reconcile.fluxcd.io/forceAt"] = ts
180+
}
181+
if rhrArgs.syncReset {
182+
annotations["reconcile.fluxcd.io/resetAt"] = ts
183+
}
173184
}
185+
186+
object.SetAnnotations(annotations)
174187
return kubeClient.Patch(ctx, object, patch)
175188
})
176189
}

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)