mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #102642 from alaypatel07/lastSuccessfulTime
populate last successful time to cronjob status
This commit is contained in:
commit
270b66fb94
@ -425,6 +425,14 @@ func (jm *ControllerV2) syncCronJob(
|
||||
_, status := getFinishedStatus(j)
|
||||
deleteFromActiveList(cj, j.ObjectMeta.UID)
|
||||
jm.recorder.Eventf(cj, corev1.EventTypeNormal, "SawCompletedJob", "Saw completed job: %s, status: %v", j.Name, status)
|
||||
} else if IsJobFinished(j) {
|
||||
// a job does not have to be in active list, as long as it is finished, we will process the timestamp
|
||||
if cj.Status.LastSuccessfulTime == nil {
|
||||
cj.Status.LastSuccessfulTime = j.Status.CompletionTime
|
||||
}
|
||||
if j.Status.CompletionTime != nil && j.Status.CompletionTime.After(cj.Status.LastSuccessfulTime.Time) {
|
||||
cj.Status.LastSuccessfulTime = j.Status.CompletionTime
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,9 +157,6 @@ func TestControllerV2SyncCronJob(t *testing.T) {
|
||||
name := name
|
||||
tc := tc
|
||||
t.Run(name, func(t *testing.T) {
|
||||
if name == "this ran but done, time drifted back, F" {
|
||||
println("hello")
|
||||
}
|
||||
cj := cronJob()
|
||||
cj.Spec.ConcurrencyPolicy = tc.concurrencyPolicy
|
||||
cj.Spec.Suspend = &tc.suspend
|
||||
@ -195,6 +192,15 @@ func TestControllerV2SyncCronJob(t *testing.T) {
|
||||
if !tc.jobStillNotFoundInLister {
|
||||
js = append(js, job)
|
||||
}
|
||||
} else {
|
||||
job.Status.CompletionTime = &metav1.Time{Time: job.ObjectMeta.CreationTimestamp.Add(time.Second * 10)}
|
||||
job.Status.Conditions = append(job.Status.Conditions, batchv1.JobCondition{
|
||||
Type: batchv1.JobComplete,
|
||||
Status: v1.ConditionTrue,
|
||||
})
|
||||
if !tc.jobStillNotFoundInLister {
|
||||
js = append(js, job)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cj.ObjectMeta.CreationTimestamp = metav1.Time{Time: justBeforeTheHour()}
|
||||
@ -233,6 +239,12 @@ func TestControllerV2SyncCronJob(t *testing.T) {
|
||||
if tc.expectCreate {
|
||||
expectedCreates = 1
|
||||
}
|
||||
if tc.ranPreviously && !tc.stillActive {
|
||||
completionTime := tc.jobCreationTime.Add(10 * time.Second)
|
||||
if cjCopy.Status.LastSuccessfulTime == nil || !cjCopy.Status.LastSuccessfulTime.Time.Equal(completionTime) {
|
||||
t.Errorf("cj.status.lastSuccessfulTime: %s expected, got %#v", completionTime, cj.Status.LastSuccessfulTime)
|
||||
}
|
||||
}
|
||||
if len(jc.Jobs) != expectedCreates {
|
||||
t.Errorf("%s: expected %d job started, actually %v", name, expectedCreates, len(jc.Jobs))
|
||||
}
|
||||
|
@ -267,10 +267,11 @@ func getJobFromTemplate2(cj *batchv1.CronJob, scheduledTime time.Time) (*batchv1
|
||||
|
||||
job := &batchv1.Job{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: labels,
|
||||
Annotations: annotations,
|
||||
Name: name,
|
||||
OwnerReferences: []metav1.OwnerReference{*metav1.NewControllerRef(cj, controllerKind)},
|
||||
Labels: labels,
|
||||
Annotations: annotations,
|
||||
Name: name,
|
||||
CreationTimestamp: metav1.Time{Time: scheduledTime},
|
||||
OwnerReferences: []metav1.OwnerReference{*metav1.NewControllerRef(cj, controllerKind)},
|
||||
},
|
||||
}
|
||||
cj.Spec.JobTemplate.Spec.DeepCopyInto(&job.Spec)
|
||||
|
Loading…
Reference in New Issue
Block a user