Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add force and reset flags to flux reconcile hr #4437

Merged
merged 5 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions cmd/flux/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
})
}
5 changes: 4 additions & 1 deletion cmd/flux/reconcile_helmrelease.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down