mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +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)
|
_, status := getFinishedStatus(j)
|
||||||
deleteFromActiveList(cj, j.ObjectMeta.UID)
|
deleteFromActiveList(cj, j.ObjectMeta.UID)
|
||||||
jm.recorder.Eventf(cj, corev1.EventTypeNormal, "SawCompletedJob", "Saw completed job: %s, status: %v", j.Name, status)
|
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
|
name := name
|
||||||
tc := tc
|
tc := tc
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
if name == "this ran but done, time drifted back, F" {
|
|
||||||
println("hello")
|
|
||||||
}
|
|
||||||
cj := cronJob()
|
cj := cronJob()
|
||||||
cj.Spec.ConcurrencyPolicy = tc.concurrencyPolicy
|
cj.Spec.ConcurrencyPolicy = tc.concurrencyPolicy
|
||||||
cj.Spec.Suspend = &tc.suspend
|
cj.Spec.Suspend = &tc.suspend
|
||||||
@ -195,6 +192,15 @@ func TestControllerV2SyncCronJob(t *testing.T) {
|
|||||||
if !tc.jobStillNotFoundInLister {
|
if !tc.jobStillNotFoundInLister {
|
||||||
js = append(js, job)
|
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 {
|
} else {
|
||||||
cj.ObjectMeta.CreationTimestamp = metav1.Time{Time: justBeforeTheHour()}
|
cj.ObjectMeta.CreationTimestamp = metav1.Time{Time: justBeforeTheHour()}
|
||||||
@ -233,6 +239,12 @@ func TestControllerV2SyncCronJob(t *testing.T) {
|
|||||||
if tc.expectCreate {
|
if tc.expectCreate {
|
||||||
expectedCreates = 1
|
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 {
|
if len(jc.Jobs) != expectedCreates {
|
||||||
t.Errorf("%s: expected %d job started, actually %v", name, expectedCreates, len(jc.Jobs))
|
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{
|
job := &batchv1.Job{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
Annotations: annotations,
|
Annotations: annotations,
|
||||||
Name: name,
|
Name: name,
|
||||||
OwnerReferences: []metav1.OwnerReference{*metav1.NewControllerRef(cj, controllerKind)},
|
CreationTimestamp: metav1.Time{Time: scheduledTime},
|
||||||
|
OwnerReferences: []metav1.OwnerReference{*metav1.NewControllerRef(cj, controllerKind)},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
cj.Spec.JobTemplate.Spec.DeepCopyInto(&job.Spec)
|
cj.Spec.JobTemplate.Spec.DeepCopyInto(&job.Spec)
|
||||||
|
Loading…
Reference in New Issue
Block a user