fix(clickhouse): drop the predecessor wait once a run's own Job starts

A BackupJob or RestoreJob that waited for the Job of an earlier owner
of its name kept its Ready=False PredecessorJobPending condition after
that Job was gone and its own Job had started, so for the whole run it
still said it was waiting for the garbage collector.

The condition is now dropped when the run's own Job is running, the
way the credentials wait is.

Assisted-by: LLM
Signed-off-by: Alexey Artamonov <aleksei.artamonov@aenix.io>
This commit is contained in:
Alexey Artamonov authored and Aleksei Sviridkin committed 2026-11-23 12:15:07 +03:00
1 parent 8cf04bdd0f
commit a2f7ea18ee
2 files changed
+51 -4

No files matched your search

@@ -180,6 +180,17 @@ func clearCredentialsWait(conditions *[]metav1.Condition) bool {
return apimeta.RemoveStatusCondition(conditions, "Ready")
}
// clearPredecessorWait drops the Ready condition a run set while it waited
// for the Job of an earlier owner of its name, once its own Job runs. It
// reports whether it did.
func clearPredecessorWait(conditions *[]metav1.Condition) bool {
ready := apimeta.FindStatusCondition(*conditions, "Ready")
if ready == nil || ready.Reason != altinityPredecessorJobReason {
return false
}
return apimeta.RemoveStatusCondition(conditions, "Ready")
}
const credentialsWaitReason = "WaitingForCredentials"
// credentialsWaitCondition is the Ready condition of a job held back by
@@ -436,7 +447,7 @@ func (r *BackupJobReconciler) reconcileAltinity(ctx context.Context, j *backupsv
apimeta.SetStatusCondition(&j.Status.Conditions, metav1.Condition{
Type: "Ready",
Status: metav1.ConditionFalse,
Reason: "PredecessorJobPending",
Reason: altinityPredecessorJobReason,
Message: err.Error(),
})
if uerr := r.Status().Update(ctx, j); uerr != nil {
@@ -494,7 +505,7 @@ func (r *BackupJobReconciler) reconcileAltinity(ctx context.Context, j *backupsv
return r.markBackupJobFailed(ctx, j, message)
default:
if clearCredentialsWait(&j.Status.Conditions) {
if clearCredentialsWait(&j.Status.Conditions) || clearPredecessorWait(&j.Status.Conditions) {
if err := r.Status().Update(ctx, j); err != nil {
return ctrl.Result{}, err
}
@@ -547,6 +558,10 @@ func (r *BackupJobReconciler) ensureAltinityJob(
return desired, nil
}
// altinityPredecessorJobReason is the Ready reason of a run that waits for
// the Job of an earlier owner of its name to be removed.
const altinityPredecessorJobReason = "PredecessorJobPending"
// errAltinityPredecessorJob marks a Job left under the Job name by an earlier
// BackupJob or RestoreJob of the same name. Its owner is gone, so the garbage
// collector removes it, and the new owner waits for that instead of failing.
@@ -926,7 +941,7 @@ func (r *RestoreJobReconciler) reconcileAltinityRestore(ctx context.Context, res
apimeta.SetStatusCondition(&restoreJob.Status.Conditions, metav1.Condition{
Type: "Ready",
Status: metav1.ConditionFalse,
Reason: "PredecessorJobPending",
Reason: altinityPredecessorJobReason,
Message: err.Error(),
})
if uerr := r.Status().Update(ctx, restoreJob); uerr != nil {
@@ -962,7 +977,7 @@ func (r *RestoreJobReconciler) reconcileAltinityRestore(ctx context.Context, res
return r.markRestoreJobFailed(ctx, restoreJob, message)
default:
if clearCredentialsWait(&restoreJob.Status.Conditions) {
if clearCredentialsWait(&restoreJob.Status.Conditions) || clearPredecessorWait(&restoreJob.Status.Conditions) {
if err := r.Status().Update(ctx, restoreJob); err != nil {
return ctrl.Result{}, err
}
@@ -1805,6 +1805,22 @@ func TestReconcileAltinity_DoesNotReuseAJobItDoesNotControl(t *testing.T) {
if c := meta.FindStatusCondition(got.Status.Conditions, "Ready"); c == nil || !strings.Contains(c.Message, job.Name) {
t.Errorf("Ready condition %+v does not say which Job it waits for", c)
}
// Once the garbage collector has removed the earlier Job, this
// run's own Job starts and the wait is over.
if err := r.Delete(ctx, job); err != nil {
t.Fatalf("remove the earlier Job: %v", err)
}
if _, err := r.reconcileAltinity(ctx, got, altinityResolved(strategy.Name)); err != nil {
t.Fatalf("reconcileAltinity after the earlier Job went: %v", err)
}
after := &backupsv1alpha1.BackupJob{}
if err := r.Get(ctx, client.ObjectKeyFromObject(bj), after); err != nil {
t.Fatalf("get BackupJob: %v", err)
}
if c := meta.FindStatusCondition(after.Status.Conditions, "Ready"); c != nil && c.Reason == altinityPredecessorJobReason {
t.Errorf("Ready condition %+v still says the run waits for an earlier Job while its own runs", c)
}
})
}
}
@@ -1902,6 +1918,22 @@ func TestReconcileAltinityRestore_DoesNotReuseAJobItDoesNotControl(t *testing.T)
if c := meta.FindStatusCondition(got.Status.Conditions, "Ready"); c == nil || !strings.Contains(c.Message, job.Name) {
t.Errorf("Ready condition %+v does not say which Job it waits for", c)
}
// Once the garbage collector has removed the earlier Job, this
// run's own Job starts and the wait is over.
if err := rr.Delete(ctx, job); err != nil {
t.Fatalf("remove the earlier Job: %v", err)
}
if _, err := rr.reconcileAltinityRestore(ctx, got, backup); err != nil {
t.Fatalf("reconcileAltinityRestore after the earlier Job went: %v", err)
}
after := &backupsv1alpha1.RestoreJob{}
if err := rr.Get(ctx, client.ObjectKeyFromObject(restoreJob), after); err != nil {
t.Fatalf("get RestoreJob: %v", err)
}
if c := meta.FindStatusCondition(after.Status.Conditions, "Ready"); c != nil && c.Reason == altinityPredecessorJobReason {
t.Errorf("Ready condition %+v still says the run waits for an earlier Job while its own runs", c)
}
})
}
}