Skip to content

Commit

Permalink
chore: add update reconciliation for migration job
Browse files Browse the repository at this point in the history
  • Loading branch information
parkedwards committed Aug 27, 2024
1 parent ec23959 commit 02e50f9
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions internal/controller/prefectserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,35 @@ func (r *PrefectServerReconciler) reconcileMigrationJob(ctx context.Context, ser
}

return &ctrl.Result{}, errors.NewBadRequest(errorMessage)
} else if jobNeedsUpdate(&foundMigrationJob.Spec, &desiredMigrationJob.Spec, log) {
// TODO: handle replacing the job if something has changed
} else if migrationJobNeedsUpdate(&foundMigrationJob.Spec, &desiredMigrationJob.Spec, log) {
log.Info("Recreating migration Job", "name", desiredMigrationJob.Name)
// deletes the job + recreates it.
// k8s Jobs are immutable and need to be recreated if they are to be re-run.
if err = r.Delete(ctx, foundMigrationJob); err != nil {
if statusErr := r.updateCondition(ctx, server, metav1.Condition{
Type: "MigrationJobReconciled",
Status: metav1.ConditionFalse,
Reason: "MigrationJobNotDeleted",
Message: "MigrationJob was not deleted: " + err.Error(),
}); statusErr != nil {
return &ctrl.Result{}, statusErr
}

return &ctrl.Result{}, err
}

if err = r.Create(ctx, desiredMigrationJob); err != nil {
if statusErr := r.updateCondition(ctx, server, metav1.Condition{
Type: "MigrationJobReconciled",
Status: metav1.ConditionFalse,
Reason: "MigrationJobNotRecreated",
Message: "MigrationJob was not recreated: " + err.Error(),
}); statusErr != nil {
return &ctrl.Result{}, statusErr
}

return &ctrl.Result{}, err
}
} else {
if !meta.IsStatusConditionTrue(server.Status.Conditions, "MigrationJobReconciled") {
if statusErr := r.updateCondition(ctx, server, metav1.Condition{
Expand Down Expand Up @@ -500,9 +526,9 @@ func pvcNeedsUpdate(current, desired *corev1.PersistentVolumeClaimSpec, log logr
return false
}

func jobNeedsUpdate(current, desired *batchv1.JobSpec, log logr.Logger) bool {
// TODO: check for changes to the job spec that require an update
return false
func migrationJobNeedsUpdate(current, desired *batchv1.JobSpec, log logr.Logger) bool {
merged := current.DeepCopy()
return needsUpdate(current, merged, desired, log)
}

func deploymentNeedsUpdate(current, desired *appsv1.DeploymentSpec, log logr.Logger) bool {
Expand Down

0 comments on commit 02e50f9

Please sign in to comment.