mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Merge pull request #51902 from zhangxiaoyu-zidif/fix-typo-cronjob-utils
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.. Refactor cronjob test case with sets.String **What this PR does / why we need it**: Refactor cronjob test case with sets.String **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes https://github.com/kubernetes/kubernetes/issues/51396 **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
commit
2b24df3407
@ -54,6 +54,7 @@ go_test(
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
||||
"//vendor/k8s.io/client-go/tools/record:go_default_library",
|
||||
],
|
||||
)
|
||||
|
@ -18,7 +18,6 @@ package cronjob
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
@ -29,6 +28,7 @@ import (
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/client-go/tools/record"
|
||||
// For the cronjob controller to do conversions.
|
||||
_ "k8s.io/kubernetes/pkg/api/install"
|
||||
@ -524,7 +524,7 @@ func TestCleanupFinishedJobs_DeleteOrNot(t *testing.T) {
|
||||
|
||||
// Create jobs
|
||||
js := []batchv1.Job{}
|
||||
jobsToDelete := []string{}
|
||||
jobsToDelete := sets.NewString()
|
||||
sj.Status.Active = []v1.ObjectReference{}
|
||||
|
||||
for i, spec := range tc.jobSpecs {
|
||||
@ -558,7 +558,7 @@ func TestCleanupFinishedJobs_DeleteOrNot(t *testing.T) {
|
||||
|
||||
js = append(js, *job)
|
||||
if spec.ExpectDelete {
|
||||
jobsToDelete = append(jobsToDelete, job.Name)
|
||||
jobsToDelete.Insert(job.Name)
|
||||
}
|
||||
}
|
||||
|
||||
@ -576,12 +576,9 @@ func TestCleanupFinishedJobs_DeleteOrNot(t *testing.T) {
|
||||
if len(jc.DeleteJobName) != len(jobsToDelete) {
|
||||
t.Errorf("%s: expected %d job deleted, actually %d", name, len(jobsToDelete), len(jc.DeleteJobName))
|
||||
} else {
|
||||
sort.Strings(jobsToDelete)
|
||||
sort.Strings(jc.DeleteJobName)
|
||||
for i, expectedJobName := range jobsToDelete {
|
||||
if expectedJobName != jc.DeleteJobName[i] {
|
||||
t.Errorf("%s: expected job %s deleted, actually %v -- %v vs %v", name, expectedJobName, jc.DeleteJobName[i], jc.DeleteJobName, jobsToDelete)
|
||||
}
|
||||
jcDeleteJobName := sets.NewString(jc.DeleteJobName...)
|
||||
if !jcDeleteJobName.Equal(jobsToDelete) {
|
||||
t.Errorf("%s: expected jobs: %v deleted, actually: %v deleted", name, jobsToDelete, jcDeleteJobName)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,7 @@ func getRecentUnmetScheduleTimes(sj batchv1beta1.CronJob, now time.Time) ([]time
|
||||
|
||||
for t := sched.Next(earliestTime); !t.After(now); t = sched.Next(t) {
|
||||
starts = append(starts, t)
|
||||
// An object might miss several starts. For example, if
|
||||
// An object might miss several starts. For example, if
|
||||
// controller gets wedged on friday at 5:01pm when everyone has
|
||||
// gone home, and someone comes in on tuesday AM and discovers
|
||||
// the problem and restarts the controller, then all the hourly
|
||||
@ -159,7 +159,7 @@ func getRecentUnmetScheduleTimes(sj batchv1beta1.CronJob, now time.Time) ([]time
|
||||
// of this controller. In that case, we want to not try to list
|
||||
// all the missed start times.
|
||||
//
|
||||
// I've somewhat arbitrarily picked 100, as more than 80, but
|
||||
// I've somewhat arbitrarily picked 100, as more than 80,
|
||||
// but less than "lots".
|
||||
if len(starts) > 100 {
|
||||
// We can't get the most recent times so just return an empty slice
|
||||
|
Loading…
Reference in New Issue
Block a user