Skip to content

Commit

Permalink
Use MarkStalled, MarkReconciling from runtime
Browse files Browse the repository at this point in the history
Signed-off-by: Hidde Beydals <[email protected]>
  • Loading branch information
hiddeco committed Jul 27, 2021
1 parent 5600c78 commit 08bb991
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions controllers/bucket_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (r *BucketReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
case metav1.ConditionFalse:
// As we are no longer reconciling and the end-state
// is not ready, the reconciliation has stalled
conditions.MarkTrue(obj, meta.StalledCondition, readyCondition.Reason, readyCondition.Message)
conditions.MarkStalled(obj, readyCondition.Reason, readyCondition.Message)
case metav1.ConditionTrue:
// As we are no longer reconciling and the end-state
// is ready, the reconciliation is no longer stalled
Expand Down Expand Up @@ -187,7 +187,7 @@ func (r *BucketReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res

func (r *BucketReconciler) reconcile(ctx context.Context, obj *sourcev1.Bucket) (ctrl.Result, error) {
// Mark the resource as under reconciliation
conditions.MarkTrue(obj, meta.ReconcilingCondition, "Reconciling", "")
conditions.MarkReconciling(obj, "Reconciling", "")
logr.FromContext(ctx).Info("Starting reconciliation")

// Reconcile the storage data
Expand Down
8 changes: 7 additions & 1 deletion controllers/gitrepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ func (r *GitRepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Reques
obj.Status.SetLastHandledReconcileRequest(v)
}

// We are no longer reconciling
conditions.Delete(obj, meta.ReconcilingCondition)

// Summarize Ready condition
conditions.SetSummary(obj,
meta.ReadyCondition,
Expand Down Expand Up @@ -159,7 +162,7 @@ func (r *GitRepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Reques
case metav1.ConditionFalse:
// As we are no longer reconciling and the end-state
// is not ready, the reconciliation has stalled
conditions.MarkTrue(obj, meta.StalledCondition, readyCondition.Reason, readyCondition.Message)
conditions.MarkStalled(obj, readyCondition.Reason, readyCondition.Message)
case metav1.ConditionTrue:
// As we are no longer reconciling and the end-state
// is ready, the reconciliation is no longer stalled
Expand Down Expand Up @@ -194,6 +197,9 @@ func (r *GitRepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Reques
}

func (r *GitRepositoryReconciler) reconcile(ctx context.Context, obj *sourcev1.GitRepository) (ctrl.Result, error) {
// Mark the resource as under reconciliation
conditions.MarkReconciling(obj, "Reconciling", "")

// Reconcile the storage data
if result, err := r.reconcileStorage(ctx, obj); err != nil {
return result, err
Expand Down
12 changes: 4 additions & 8 deletions controllers/helmchart_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (r *HelmChartReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
case metav1.ConditionFalse:
// As we are no longer reconciling and the end-state
// is not ready, the reconciliation has stalled
conditions.MarkTrue(obj, meta.StalledCondition, readyCondition.Reason, readyCondition.Message)
conditions.MarkStalled(obj, readyCondition.Reason, readyCondition.Message)
case metav1.ConditionTrue:
// As we are no longer reconciling and the end-state
// is ready, the reconciliation is no longer stalled
Expand Down Expand Up @@ -223,7 +223,7 @@ func (r *HelmChartReconciler) Reconcile(ctx context.Context, req ctrl.Request) (

func (r *HelmChartReconciler) reconcile(ctx context.Context, obj *sourcev1.HelmChart) (ctrl.Result, error) {
// Mark the resource as under reconciliation
conditions.MarkTrue(obj, meta.ReconcilingCondition, "Reconciling", "")
conditions.MarkReconciling(obj, "Reconciling", "")

// Reconcile the storage data
if result, err := r.reconcileStorage(ctx, obj); err != nil {
Expand All @@ -232,19 +232,15 @@ func (r *HelmChartReconciler) reconcile(ctx context.Context, obj *sourcev1.HelmC

// Reconcile the source
var sourcePath string
defer func() {
os.RemoveAll(sourcePath)
}()
defer os.RemoveAll(sourcePath)
if result, err := r.reconcileSource(ctx, obj, &sourcePath); err != nil || conditions.IsFalse(obj, sourcev1.SourceAvailableCondition) {
return result, err
}

// Reconcile the chart using the source data
var artifact sourcev1.Artifact
var resultPath string
defer func() {
os.RemoveAll(resultPath)
}()
defer os.RemoveAll(resultPath)
if result, err := r.reconcileChart(ctx, obj, sourcePath, &artifact, &resultPath); err != nil {
return result, err
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/helmrepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (r *HelmRepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Reque
case metav1.ConditionFalse:
// As we are no longer reconciling and the end-state
// is not ready, the reconciliation has stalled
conditions.MarkTrue(obj, meta.StalledCondition, readyCondition.Reason, readyCondition.Message)
conditions.MarkStalled(obj, readyCondition.Reason, readyCondition.Message)
case metav1.ConditionTrue:
// As we are no longer reconciling and the end-state
// is ready, the reconciliation is no longer stalled
Expand Down Expand Up @@ -186,7 +186,7 @@ func (r *HelmRepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Reque

func (r *HelmRepositoryReconciler) reconcile(ctx context.Context, obj *sourcev1.HelmRepository) (ctrl.Result, error) {
// Mark the resource as under reconciliation
conditions.MarkTrue(obj, meta.ReconcilingCondition, "Reconciling", "")
conditions.MarkReconciling(obj, "Reconciling", "")

// Reconcile the storage data
if result, err := r.reconcileStorage(ctx, obj); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/fluxcd/pkg/gitutil v0.1.0
github.com/fluxcd/pkg/helmtestserver v0.2.0
github.com/fluxcd/pkg/lockedfile v0.1.0
github.com/fluxcd/pkg/runtime v0.13.0-rc.1
github.com/fluxcd/pkg/runtime v0.13.0-rc.2
github.com/fluxcd/pkg/ssh v0.1.0
github.com/fluxcd/pkg/testserver v0.1.0
github.com/fluxcd/pkg/untar v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ github.com/fluxcd/pkg/helmtestserver v0.2.0 h1:cE7YHDmrWI0hr9QpaaeQ0vQ16Z0IiqZKi
github.com/fluxcd/pkg/helmtestserver v0.2.0/go.mod h1:Yie8n7xuu5Nvf1Q7302LKsubJhWpwzCaK0rLJvmF7aI=
github.com/fluxcd/pkg/lockedfile v0.1.0 h1:YsYFAkd6wawMCcD74ikadAKXA4s2sukdxrn7w8RB5eo=
github.com/fluxcd/pkg/lockedfile v0.1.0/go.mod h1:EJLan8t9MiOcgTs8+puDjbE6I/KAfHbdvIy9VUgIjm8=
github.com/fluxcd/pkg/runtime v0.13.0-rc.1 h1:eeyo7fiJ2zk2hl5ClEzFZrru/ycY5/IU8j8Ncae32X8=
github.com/fluxcd/pkg/runtime v0.13.0-rc.1/go.mod h1:TmvE2cJl1QkgZNmmlr7XUKoWDQwUiM5/wTUxXsQVoc8=
github.com/fluxcd/pkg/runtime v0.13.0-rc.2 h1:+4uTEg+CU++hlr7NpOP4KYp60MtHDOgYvpz/74tbATg=
github.com/fluxcd/pkg/runtime v0.13.0-rc.2/go.mod h1:TmvE2cJl1QkgZNmmlr7XUKoWDQwUiM5/wTUxXsQVoc8=
github.com/fluxcd/pkg/ssh v0.1.0 h1:cym2bqiT4IINOdLV0J6GYxer16Ii/7b2+RlK3CG+CnA=
github.com/fluxcd/pkg/ssh v0.1.0/go.mod h1:KUuVhaB6AX3IHTGCd3Ti/nesn5t1Nz4zCThFkkjHctM=
github.com/fluxcd/pkg/testserver v0.1.0 h1:nOYgM1HYFZNNSUFykuWDmrsxj4jQxUCvmLHWOQeqmyA=
Expand Down

0 comments on commit 08bb991

Please sign in to comment.