mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 07:27:21 +00:00
Merge pull request #51519 from hzxuzhonghu/cronjob
Automatic merge from submit-queue update deprecated interface and fix bug not return when list pod failed in cronjob_controller.go **What this PR does / why we need it**: remove some unused redundant code, and fix bug: when list pod failed, job still deleted but pod may still exist in func `deleteJob` **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package cronjob
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -34,9 +35,10 @@ import (
|
||||
_ "k8s.io/kubernetes/pkg/apis/batch/install"
|
||||
)
|
||||
|
||||
// schedule is hourly on the hour
|
||||
var (
|
||||
onTheHour string = "0 * * * ?"
|
||||
// schedule is hourly on the hour
|
||||
onTheHour string = "0 * * * ?"
|
||||
errorSchedule string = "obvious error schedule"
|
||||
)
|
||||
|
||||
func justBeforeTheHour() time.Time {
|
||||
@@ -197,6 +199,9 @@ func TestSyncOne_RunOrNot(t *testing.T) {
|
||||
expectActive int
|
||||
expectedWarnings int
|
||||
}{
|
||||
"never ran, not valid schedule, A": {A, F, errorSchedule, noDead, F, F, justBeforeTheHour(), F, F, 0, 1},
|
||||
"never ran, not valid schedule, F": {f, F, errorSchedule, noDead, F, F, justBeforeTheHour(), F, F, 0, 1},
|
||||
"never ran, not valid schedule, R": {f, F, errorSchedule, noDead, F, F, justBeforeTheHour(), F, F, 0, 1},
|
||||
"never ran, not time, A": {A, F, onTheHour, noDead, F, F, justBeforeTheHour(), F, F, 0, 0},
|
||||
"never ran, not time, F": {f, F, onTheHour, noDead, F, F, justBeforeTheHour(), F, F, 0, 0},
|
||||
"never ran, not time, R": {R, F, onTheHour, noDead, F, F, justBeforeTheHour(), F, F, 0, 0},
|
||||
@@ -480,6 +485,16 @@ func TestCleanupFinishedJobs_DeleteOrNot(t *testing.T) {
|
||||
{"2016-05-19T08:00:00Z", F, F, F, F},
|
||||
{"2016-05-19T09:00:00Z", F, F, F, F},
|
||||
}, justBeforeTheHour(), &limitZero, &limitZero, 6},
|
||||
|
||||
"failed list pod err": {
|
||||
[]CleanupJobSpec{
|
||||
{"2016-05-19T04:00:00Z", T, F, F, F},
|
||||
{"2016-05-19T05:00:00Z", T, F, F, F},
|
||||
{"2016-05-19T06:00:00Z", T, T, F, F},
|
||||
{"2016-05-19T07:00:00Z", T, T, F, F},
|
||||
{"2016-05-19T08:00:00Z", T, F, F, F},
|
||||
{"2016-05-19T09:00:00Z", T, F, F, F},
|
||||
}, justBeforeTheHour(), &limitZero, &limitZero, 0},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
@@ -551,6 +566,9 @@ func TestCleanupFinishedJobs_DeleteOrNot(t *testing.T) {
|
||||
pc := &fakePodControl{}
|
||||
sjc := &fakeSJControl{}
|
||||
recorder := record.NewFakeRecorder(10)
|
||||
if name == "failed list pod err" {
|
||||
pc.Err = errors.New("fakePodControl err")
|
||||
}
|
||||
|
||||
cleanupFinishedJobs(&sj, js, jc, sjc, pc, recorder)
|
||||
|
||||
@@ -569,6 +587,9 @@ func TestCleanupFinishedJobs_DeleteOrNot(t *testing.T) {
|
||||
|
||||
// Check for events
|
||||
expectedEvents := len(jobsToDelete)
|
||||
if name == "failed list pod err" {
|
||||
expectedEvents = len(tc.jobSpecs)
|
||||
}
|
||||
if len(recorder.Events) != expectedEvents {
|
||||
t.Errorf("%s: expected %d event, actually %v", name, expectedEvents, len(recorder.Events))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user