Skip to content

Commit

Permalink
Move recording of generation to end of reconcile
Browse files Browse the repository at this point in the history
  • Loading branch information
djwhatle committed Mar 26, 2021
1 parent 2a81bf1 commit c437b28
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ func (r *ReconcileDirectImageMigration) Reconcile(request reconcile.Request) (re
if r.uidGenerationMap.IsCacheStale(imageMigration.UID, imageMigration.Generation) {
return reconcile.Result{Requeue: true}, nil
}
// Record reconciled generation
defer r.uidGenerationMap.RecordReconciledGeneration(imageMigration.UID, imageMigration.Generation)

// Set up jaeger tracing
reconcileSpan := r.initTracer(imageMigration)
Expand Down Expand Up @@ -185,6 +183,9 @@ func (r *ReconcileDirectImageMigration) Reconcile(request reconcile.Request) (re
return reconcile.Result{Requeue: true}, nil
}

// Record reconciled generation
r.uidGenerationMap.RecordReconciledGeneration(imageMigration.UID, imageMigration.Generation)

// Requeue
if requeueAfter > 0 {
return reconcile.Result{RequeueAfter: requeueAfter}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ func (r *ReconcileDirectImageStreamMigration) Reconcile(request reconcile.Reques
if r.uidGenerationMap.IsCacheStale(imageStreamMigration.UID, imageStreamMigration.Generation) {
return reconcile.Result{Requeue: true}, nil
}
// Record reconciled generation
defer r.uidGenerationMap.RecordReconciledGeneration(
imageStreamMigration.UID, imageStreamMigration.Generation)

// Set up jaeger tracing
reconcileSpan, err := r.initTracer(*imageStreamMigration)
Expand Down Expand Up @@ -177,6 +174,10 @@ func (r *ReconcileDirectImageStreamMigration) Reconcile(request reconcile.Reques
return reconcile.Result{Requeue: true}, nil
}

// Record reconciled generation
r.uidGenerationMap.RecordReconciledGeneration(
imageStreamMigration.UID, imageStreamMigration.Generation)

// Requeue
if requeueAfter > 0 {
return reconcile.Result{RequeueAfter: requeueAfter}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ func (r *ReconcileDirectVolumeMigration) Reconcile(request reconcile.Request) (r
if r.uidGenerationMap.IsCacheStale(direct.UID, direct.Generation) {
return reconcile.Result{Requeue: true}, nil
}
// Record reconciled generation
defer r.uidGenerationMap.RecordReconciledGeneration(direct.UID, direct.Generation)

// Set up jaeger tracing
reconcileSpan := r.initTracer(direct)
Expand Down Expand Up @@ -172,6 +170,9 @@ func (r *ReconcileDirectVolumeMigration) Reconcile(request reconcile.Request) (r
return reconcile.Result{Requeue: true}, nil
}

// Record reconciled generation
r.uidGenerationMap.RecordReconciledGeneration(direct.UID, direct.Generation)

// Requeue
if requeueAfter > 0 {
return reconcile.Result{RequeueAfter: requeueAfter}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ func (r *ReconcileDirectVolumeMigrationProgress) Reconcile(request reconcile.Req
if r.uidGenerationMap.IsCacheStale(pvProgress.UID, pvProgress.Generation) {
return reconcile.Result{Requeue: true}, nil
}
// Record reconciled generation
defer r.uidGenerationMap.RecordReconciledGeneration(pvProgress.UID, pvProgress.Generation)

// Set up jaeger tracing
reconcileSpan, err := r.initTracer(*pvProgress)
Expand Down Expand Up @@ -191,7 +189,10 @@ func (r *ReconcileDirectVolumeMigrationProgress) Reconcile(request reconcile.Req
return reconcile.Result{Requeue: true}, nil
}

// we will requeue this every 5 seconds
// Record reconciled generation
r.uidGenerationMap.RecordReconciledGeneration(pvProgress.UID, pvProgress.Generation)

// Requeue every 5 seconds
return reconcile.Result{Requeue: true, RequeueAfter: time.Second * 5}, nil
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/controller/miganalytic/miganalytics_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ func (r *ReconcileMigAnalytic) Reconcile(request reconcile.Request) (reconcile.R
if r.uidGenerationMap.IsCacheStale(analytic.UID, analytic.Generation) {
return reconcile.Result{Requeue: true}, nil
}
// Record reconciled generation
defer r.uidGenerationMap.RecordReconciledGeneration(analytic.UID, analytic.Generation)

// Exit early if the MigAnalytic already has a ready condition
// and Refresh boolean is unset
Expand Down Expand Up @@ -224,6 +222,9 @@ func (r *ReconcileMigAnalytic) Reconcile(request reconcile.Request) (reconcile.R
return reconcile.Result{Requeue: true}, nil
}

// Record reconciled generation
r.uidGenerationMap.RecordReconciledGeneration(analytic.UID, analytic.Generation)

// Done
return reconcile.Result{Requeue: false}, nil
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/controller/migcluster/migcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ func (r *ReconcileMigCluster) Reconcile(request reconcile.Request) (reconcile.Re
if r.uidGenerationMap.IsCacheStale(cluster.UID, cluster.Generation) {
return reconcile.Result{Requeue: true}, nil
}
// Record reconciled generation
defer r.uidGenerationMap.RecordReconciledGeneration(cluster.UID, cluster.Generation)

// Report reconcile error.
defer func() {
Expand Down Expand Up @@ -193,6 +191,9 @@ func (r *ReconcileMigCluster) Reconcile(request reconcile.Request) (reconcile.Re
return reconcile.Result{Requeue: true}, nil
}

// Record reconciled generation
r.uidGenerationMap.RecordReconciledGeneration(cluster.UID, cluster.Generation)

// Done
return reconcile.Result{Requeue: false}, nil
}
5 changes: 3 additions & 2 deletions pkg/controller/mighook/mighook_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ func (r *ReconcileMigHook) Reconcile(request reconcile.Request) (reconcile.Resul
if r.uidGenerationMap.IsCacheStale(hook.UID, hook.Generation) {
return reconcile.Result{Requeue: true}, nil
}
// Record reconciled generation
defer r.uidGenerationMap.RecordReconciledGeneration(hook.UID, hook.Generation)

// Report reconcile error.
defer func() {
Expand Down Expand Up @@ -148,6 +146,9 @@ func (r *ReconcileMigHook) Reconcile(request reconcile.Request) (reconcile.Resul
return reconcile.Result{Requeue: true}, nil
}

// Record reconciled generation
r.uidGenerationMap.RecordReconciledGeneration(hook.UID, hook.Generation)

// Done
return reconcile.Result{Requeue: false}, nil
}
5 changes: 3 additions & 2 deletions pkg/controller/migmigration/migmigration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ func (r *ReconcileMigMigration) Reconcile(request reconcile.Request) (reconcile.
if r.uidGenerationMap.IsCacheStale(migration.UID, migration.Generation) {
return reconcile.Result{Requeue: true}, nil
}
// Record reconciled generation
defer r.uidGenerationMap.RecordReconciledGeneration(migration.UID, migration.Generation)

// Get jaeger spans for migration and reconcile
_, reconcileSpan := r.initTracer(migration)
Expand Down Expand Up @@ -276,6 +274,9 @@ func (r *ReconcileMigMigration) Reconcile(request reconcile.Request) (reconcile.
return reconcile.Result{Requeue: true}, nil
}

// Record reconciled generation
r.uidGenerationMap.RecordReconciledGeneration(migration.UID, migration.Generation)

// Requeue
if requeueAfter > 0 {
return reconcile.Result{RequeueAfter: requeueAfter}, nil
Expand Down
5 changes: 3 additions & 2 deletions pkg/controller/migplan/migplan_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,6 @@ func (r *ReconcileMigPlan) Reconcile(request reconcile.Request) (reconcile.Resul
if r.uidGenerationMap.IsCacheStale(plan.UID, plan.Generation) {
return reconcile.Result{Requeue: true}, nil
}
// Record reconciled generation
defer r.uidGenerationMap.RecordReconciledGeneration(plan.UID, plan.Generation)

// Report reconcile error.
defer func() {
Expand Down Expand Up @@ -332,6 +330,9 @@ func (r *ReconcileMigPlan) Reconcile(request reconcile.Request) (reconcile.Resul
return reconcile.Result{Requeue: true}, nil
}

// Record reconciled generation
r.uidGenerationMap.RecordReconciledGeneration(plan.UID, plan.Generation)

// Timed requeue on Plan conflict.
if plan.Status.HasCondition(PlanConflict) {
return reconcile.Result{RequeueAfter: time.Second * 10}, nil
Expand Down
5 changes: 3 additions & 2 deletions pkg/controller/migstorage/migstorage_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ func (r *ReconcileMigStorage) Reconcile(request reconcile.Request) (reconcile.Re
if r.uidGenerationMap.IsCacheStale(storage.UID, storage.Generation) {
return reconcile.Result{Requeue: true}, nil
}
// Record reconciled generation
defer r.uidGenerationMap.RecordReconciledGeneration(storage.UID, storage.Generation)

// Report reconcile error.
defer func() {
Expand Down Expand Up @@ -177,6 +175,9 @@ func (r *ReconcileMigStorage) Reconcile(request reconcile.Request) (reconcile.Re
return reconcile.Result{Requeue: true}, nil
}

// Record reconciled generation
r.uidGenerationMap.RecordReconciledGeneration(storage.UID, storage.Generation)

// Done
return reconcile.Result{Requeue: false}, nil
}

0 comments on commit c437b28

Please sign in to comment.