mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 04:27:54 +00:00
Merge pull request #118743 from mimowo/use-generics-in-job-tests
Replace deprecated sets.Int with sets.Set[int] in Job integration tests
This commit is contained in:
commit
d2332eb5fd
@ -998,7 +998,7 @@ func TestIndexedJob(t *testing.T) {
|
||||
Active: 3,
|
||||
Ready: pointer.Int32(0),
|
||||
})
|
||||
validateIndexedJobPods(ctx, t, clientSet, jobObj, sets.NewInt(0, 1, 2), "")
|
||||
validateIndexedJobPods(ctx, t, clientSet, jobObj, sets.New(0, 1, 2), "")
|
||||
|
||||
// One Pod succeeds.
|
||||
if err := setJobPhaseForIndex(ctx, clientSet, jobObj, v1.PodSucceeded, 1); err != nil {
|
||||
@ -1009,7 +1009,7 @@ func TestIndexedJob(t *testing.T) {
|
||||
Succeeded: 1,
|
||||
Ready: pointer.Int32(0),
|
||||
})
|
||||
validateIndexedJobPods(ctx, t, clientSet, jobObj, sets.NewInt(0, 2, 3), "1")
|
||||
validateIndexedJobPods(ctx, t, clientSet, jobObj, sets.New(0, 2, 3), "1")
|
||||
|
||||
// One Pod fails, which should be recreated.
|
||||
if err := setJobPhaseForIndex(ctx, clientSet, jobObj, v1.PodFailed, 2); err != nil {
|
||||
@ -1021,7 +1021,7 @@ func TestIndexedJob(t *testing.T) {
|
||||
Succeeded: 1,
|
||||
Ready: pointer.Int32(0),
|
||||
})
|
||||
validateIndexedJobPods(ctx, t, clientSet, jobObj, sets.NewInt(0, 2, 3), "1")
|
||||
validateIndexedJobPods(ctx, t, clientSet, jobObj, sets.New(0, 2, 3), "1")
|
||||
|
||||
// Remaining Pods succeed.
|
||||
if err, _ := setJobPodsPhase(ctx, clientSet, jobObj, v1.PodSucceeded, 3); err != nil {
|
||||
@ -1047,7 +1047,7 @@ func TestElasticIndexedJob(t *testing.T) {
|
||||
failIndexes []int
|
||||
wantSucceededIndexes string
|
||||
wantFailed int
|
||||
wantRemainingIndexes sets.Int
|
||||
wantRemainingIndexes sets.Set[int]
|
||||
wantActivePods int
|
||||
}
|
||||
cases := map[string]struct {
|
||||
@ -1087,7 +1087,7 @@ func TestElasticIndexedJob(t *testing.T) {
|
||||
failIndexes: []int{2},
|
||||
wantSucceededIndexes: "1",
|
||||
wantFailed: 1,
|
||||
wantRemainingIndexes: sets.NewInt(0, 2),
|
||||
wantRemainingIndexes: sets.New(0, 2),
|
||||
wantActivePods: 2,
|
||||
},
|
||||
// Scale down completions 3->1, verify prev failure out of range still counts
|
||||
@ -1107,13 +1107,13 @@ func TestElasticIndexedJob(t *testing.T) {
|
||||
{
|
||||
succeedIndexes: []int{2},
|
||||
wantSucceededIndexes: "2",
|
||||
wantRemainingIndexes: sets.NewInt(0, 1),
|
||||
wantRemainingIndexes: sets.New(0, 1),
|
||||
wantActivePods: 2,
|
||||
},
|
||||
// Scale completions down 3->2 to exclude previously succeeded index.
|
||||
{
|
||||
completions: pointer.Int32Ptr(2),
|
||||
wantRemainingIndexes: sets.NewInt(0, 1),
|
||||
wantRemainingIndexes: sets.New(0, 1),
|
||||
wantActivePods: 2,
|
||||
},
|
||||
// Scale completions back up to include previously succeeded index that was temporarily out of range.
|
||||
@ -1815,7 +1815,7 @@ func validateFinishedPodsNoFinalizer(ctx context.Context, t *testing.T, clientSe
|
||||
// validateIndexedJobPods validates indexes and hostname of
|
||||
// active and completed Pods of an Indexed Job.
|
||||
// Call after validateJobPodsStatus
|
||||
func validateIndexedJobPods(ctx context.Context, t *testing.T, clientSet clientset.Interface, jobObj *batchv1.Job, wantActive sets.Int, gotCompleted string) {
|
||||
func validateIndexedJobPods(ctx context.Context, t *testing.T, clientSet clientset.Interface, jobObj *batchv1.Job, wantActive sets.Set[int], gotCompleted string) {
|
||||
t.Helper()
|
||||
updatedJob, err := clientSet.BatchV1().Jobs(jobObj.Namespace).Get(ctx, jobObj.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
@ -1828,7 +1828,7 @@ func validateIndexedJobPods(ctx context.Context, t *testing.T, clientSet clients
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to list Job Pods: %v", err)
|
||||
}
|
||||
gotActive := sets.NewInt()
|
||||
gotActive := sets.New[int]()
|
||||
for _, pod := range pods.Items {
|
||||
if metav1.IsControlledBy(&pod, jobObj) {
|
||||
if pod.Status.Phase == v1.PodPending || pod.Status.Phase == v1.PodRunning {
|
||||
@ -1846,9 +1846,9 @@ func validateIndexedJobPods(ctx context.Context, t *testing.T, clientSet clients
|
||||
}
|
||||
}
|
||||
if wantActive == nil {
|
||||
wantActive = sets.NewInt()
|
||||
wantActive = sets.New[int]()
|
||||
}
|
||||
if diff := cmp.Diff(wantActive.List(), gotActive.List()); diff != "" {
|
||||
if diff := cmp.Diff(sets.List(wantActive), sets.List(gotActive)); diff != "" {
|
||||
t.Errorf("Unexpected active indexes (-want,+got):\n%s", diff)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user