@@ -136,7 +136,7 @@ type syncJobCtx struct {
136
136
succeededIndexes orderedIntervals
137
137
failedIndexes * orderedIntervals
138
138
newBackoffRecord backoffRecord
139
- expectedRmFinalizers sets.Set [string ]
139
+ expectedRmFinalizers sets.Set [types. UID ]
140
140
uncounted * uncountedTerminatedPods
141
141
podsWithDelayedDeletionPerIndex map [int ]* v1.Pod
142
142
terminating * int32
@@ -370,7 +370,7 @@ func (jm *Controller) updatePod(logger klog.Logger, old, cur interface{}) {
370
370
if finalizerRemoved {
371
371
key , err := controller .KeyFunc (job )
372
372
if err == nil {
373
- jm .finalizerExpectations .finalizerRemovalObserved (logger , key , string ( curPod .UID ) )
373
+ jm .finalizerExpectations .finalizerRemovalObserved (logger , key , curPod .UID )
374
374
}
375
375
}
376
376
jm .enqueueSyncJobBatched (logger , job )
@@ -386,7 +386,7 @@ func (jm *Controller) updatePod(logger klog.Logger, old, cur interface{}) {
386
386
if finalizerRemoved {
387
387
key , err := controller .KeyFunc (job )
388
388
if err == nil {
389
- jm .finalizerExpectations .finalizerRemovalObserved (logger , key , string ( curPod .UID ) )
389
+ jm .finalizerExpectations .finalizerRemovalObserved (logger , key , curPod .UID )
390
390
}
391
391
}
392
392
jm .enqueueSyncJobBatched (logger , job )
@@ -460,7 +460,7 @@ func (jm *Controller) deletePod(logger klog.Logger, obj interface{}, final bool)
460
460
// Consider the finalizer removed if this is the final delete. Otherwise,
461
461
// it's an update for the deletion timestamp, then check finalizer.
462
462
if final || ! hasFinalizer {
463
- jm .finalizerExpectations .finalizerRemovalObserved (logger , jobKey , string ( pod .UID ) )
463
+ jm .finalizerExpectations .finalizerRemovalObserved (logger , jobKey , pod .UID )
464
464
}
465
465
466
466
jm .enqueueSyncJobBatched (logger , job )
@@ -1167,11 +1167,10 @@ func (jm *Controller) trackJobStatusAndRemoveFinalizers(ctx context.Context, job
1167
1167
// Sort to introduce completed Indexes in order.
1168
1168
sort .Sort (byCompletionIndex (jobCtx .pods ))
1169
1169
}
1170
- uidsWithFinalizer := make (sets.Set [string ], len (jobCtx .pods ))
1170
+ uidsWithFinalizer := make (sets.Set [types. UID ], len (jobCtx .pods ))
1171
1171
for _ , p := range jobCtx .pods {
1172
- uid := string (p .UID )
1173
- if hasJobTrackingFinalizer (p ) && ! jobCtx .expectedRmFinalizers .Has (uid ) {
1174
- uidsWithFinalizer .Insert (uid )
1172
+ if hasJobTrackingFinalizer (p ) && ! jobCtx .expectedRmFinalizers .Has (p .UID ) {
1173
+ uidsWithFinalizer .Insert (p .UID )
1175
1174
}
1176
1175
}
1177
1176
@@ -1183,7 +1182,7 @@ func (jm *Controller) trackJobStatusAndRemoveFinalizers(ctx context.Context, job
1183
1182
podFailureCountByPolicyAction := map [string ]int {}
1184
1183
reachedMaxUncountedPods := false
1185
1184
for _ , pod := range jobCtx .pods {
1186
- if ! hasJobTrackingFinalizer (pod ) || jobCtx .expectedRmFinalizers .Has (string ( pod .UID ) ) {
1185
+ if ! hasJobTrackingFinalizer (pod ) || jobCtx .expectedRmFinalizers .Has (pod .UID ) {
1187
1186
// This pod was processed in a previous sync.
1188
1187
continue
1189
1188
}
@@ -1192,7 +1191,7 @@ func (jm *Controller) trackJobStatusAndRemoveFinalizers(ctx context.Context, job
1192
1191
continue
1193
1192
}
1194
1193
podsToRemoveFinalizer = append (podsToRemoveFinalizer , pod )
1195
- if pod .Status .Phase == v1 .PodSucceeded && ! jobCtx .uncounted .failed .Has (string ( pod .UID ) ) {
1194
+ if pod .Status .Phase == v1 .PodSucceeded && ! jobCtx .uncounted .failed .Has (pod .UID ) {
1196
1195
if isIndexed {
1197
1196
// The completion index is enough to avoid recounting succeeded pods.
1198
1197
// No need to track UIDs.
@@ -1201,14 +1200,14 @@ func (jm *Controller) trackJobStatusAndRemoveFinalizers(ctx context.Context, job
1201
1200
newSucceededIndexes = append (newSucceededIndexes , ix )
1202
1201
needsFlush = true
1203
1202
}
1204
- } else if ! jobCtx .uncounted .succeeded .Has (string ( pod .UID ) ) {
1203
+ } else if ! jobCtx .uncounted .succeeded .Has (pod .UID ) {
1205
1204
needsFlush = true
1206
1205
uncountedStatus .Succeeded = append (uncountedStatus .Succeeded , pod .UID )
1207
1206
}
1208
1207
} else if considerPodFailed || (jobCtx .finishedCondition != nil && ! isSuccessCriteriaMetCondition (jobCtx .finishedCondition )) {
1209
1208
// When the job is considered finished, every non-terminated pod is considered failed.
1210
1209
ix := getCompletionIndex (pod .Annotations )
1211
- if ! jobCtx .uncounted .failed .Has (string ( pod .UID ) ) && (! isIndexed || (ix != unknownCompletionIndex && ix < int (* jobCtx .job .Spec .Completions ))) {
1210
+ if ! jobCtx .uncounted .failed .Has (pod .UID ) && (! isIndexed || (ix != unknownCompletionIndex && ix < int (* jobCtx .job .Spec .Completions ))) {
1212
1211
if jobCtx .job .Spec .PodFailurePolicy != nil {
1213
1212
_ , countFailed , action := matchPodFailurePolicy (jobCtx .job .Spec .PodFailurePolicy , pod )
1214
1213
if action != nil {
@@ -1333,7 +1332,7 @@ func canRemoveFinalizer(logger klog.Logger, jobCtx *syncJobCtx, pod *v1.Pod, con
1333
1332
//
1334
1333
// Returns whether there are pending changes in the Job status that need to be
1335
1334
// flushed in subsequent calls.
1336
- func (jm * Controller ) flushUncountedAndRemoveFinalizers (ctx context.Context , jobCtx * syncJobCtx , podsToRemoveFinalizer []* v1.Pod , uidsWithFinalizer sets.Set [string ], oldCounters * batch.JobStatus , podFailureCountByPolicyAction map [string ]int , needsFlush bool ) (* batch.Job , bool , error ) {
1335
+ func (jm * Controller ) flushUncountedAndRemoveFinalizers (ctx context.Context , jobCtx * syncJobCtx , podsToRemoveFinalizer []* v1.Pod , uidsWithFinalizer sets.Set [types. UID ], oldCounters * batch.JobStatus , podFailureCountByPolicyAction map [string ]int , needsFlush bool ) (* batch.Job , bool , error ) {
1337
1336
logger := klog .FromContext (ctx )
1338
1337
var err error
1339
1338
if needsFlush {
@@ -1367,7 +1366,7 @@ func (jm *Controller) flushUncountedAndRemoveFinalizers(ctx context.Context, job
1367
1366
rmSucceded , rmErr = jm .removeTrackingFinalizerFromPods (ctx , jobKey , podsToRemoveFinalizer )
1368
1367
for i , p := range podsToRemoveFinalizer {
1369
1368
if rmSucceded [i ] {
1370
- uidsWithFinalizer .Delete (string ( p .UID ) )
1369
+ uidsWithFinalizer .Delete (p .UID )
1371
1370
}
1372
1371
}
1373
1372
}
@@ -1388,7 +1387,7 @@ func (jm *Controller) flushUncountedAndRemoveFinalizers(ctx context.Context, job
1388
1387
// .status.uncountedTerminatedPods for which the finalizer was successfully
1389
1388
// removed and increments the corresponding status counters.
1390
1389
// Returns whether there was any status change.
1391
- func cleanUncountedPodsWithoutFinalizers (status * batch.JobStatus , uidsWithFinalizer sets.Set [string ]) bool {
1390
+ func cleanUncountedPodsWithoutFinalizers (status * batch.JobStatus , uidsWithFinalizer sets.Set [types. UID ]) bool {
1392
1391
updated := false
1393
1392
uncountedStatus := status .UncountedTerminatedPods
1394
1393
newUncounted := filterInUncountedUIDs (uncountedStatus .Succeeded , uidsWithFinalizer )
@@ -1414,9 +1413,9 @@ func (jm *Controller) removeTrackingFinalizerFromPods(ctx context.Context, jobKe
1414
1413
logger := klog .FromContext (ctx )
1415
1414
errCh := make (chan error , len (pods ))
1416
1415
succeeded := make ([]bool , len (pods ))
1417
- uids := make ([]string , len (pods ))
1416
+ uids := make ([]types. UID , len (pods ))
1418
1417
for i , p := range pods {
1419
- uids [i ] = string ( p .UID )
1418
+ uids [i ] = p .UID
1420
1419
}
1421
1420
if jobKey != "" {
1422
1421
err := jm .finalizerExpectations .expectFinalizersRemoved (logger , jobKey , uids )
@@ -1435,7 +1434,7 @@ func (jm *Controller) removeTrackingFinalizerFromPods(ctx context.Context, jobKe
1435
1434
// In case of any failure, we don't expect a Pod update for the
1436
1435
// finalizer removed. Clear expectation now.
1437
1436
if jobKey != "" {
1438
- jm .finalizerExpectations .finalizerRemovalObserved (logger , jobKey , string ( pod .UID ) )
1437
+ jm .finalizerExpectations .finalizerRemovalObserved (logger , jobKey , pod .UID )
1439
1438
}
1440
1439
if ! apierrors .IsNotFound (err ) {
1441
1440
errCh <- err
@@ -1495,10 +1494,10 @@ func (jm *Controller) recordJobFinished(job *batch.Job, finishedCond *batch.JobC
1495
1494
return true
1496
1495
}
1497
1496
1498
- func filterInUncountedUIDs (uncounted []types.UID , include sets.Set [string ]) []types.UID {
1497
+ func filterInUncountedUIDs (uncounted []types.UID , include sets.Set [types. UID ]) []types.UID {
1499
1498
var newUncounted []types.UID
1500
1499
for _ , uid := range uncounted {
1501
- if include .Has (string ( uid ) ) {
1500
+ if include .Has (uid ) {
1502
1501
newUncounted = append (newUncounted , uid )
1503
1502
}
1504
1503
}
@@ -1852,14 +1851,12 @@ func (jm *Controller) patchJob(ctx context.Context, job *batch.Job, data []byte)
1852
1851
// getValidPodsWithFilter returns the valid pods that pass the filter.
1853
1852
// Pods are valid if they have a finalizer or in uncounted set
1854
1853
// and, for Indexed Jobs, a valid completion index.
1855
- func getValidPodsWithFilter (jobCtx * syncJobCtx , uncounted sets.Set [string ], filter func (* v1.Pod ) bool ) []* v1.Pod {
1854
+ func getValidPodsWithFilter (jobCtx * syncJobCtx , uncounted sets.Set [types. UID ], filter func (* v1.Pod ) bool ) []* v1.Pod {
1856
1855
var result []* v1.Pod
1857
1856
for _ , p := range jobCtx .pods {
1858
- uid := string (p .UID )
1859
-
1860
1857
// Pods that don't have a completion finalizer are in the uncounted set or
1861
1858
// have already been accounted for in the Job status.
1862
- if ! hasJobTrackingFinalizer (p ) || uncounted .Has (uid ) || jobCtx .expectedRmFinalizers .Has (uid ) {
1859
+ if ! hasJobTrackingFinalizer (p ) || uncounted .Has (p . UID ) || jobCtx .expectedRmFinalizers .Has (p . UID ) {
1863
1860
continue
1864
1861
}
1865
1862
if isIndexedJob (jobCtx .job ) {
@@ -1906,32 +1903,25 @@ func removeTrackingFinalizerPatch(pod *v1.Pod) []byte {
1906
1903
}
1907
1904
1908
1905
type uncountedTerminatedPods struct {
1909
- succeeded sets.Set [string ]
1910
- failed sets.Set [string ]
1906
+ succeeded sets.Set [types. UID ]
1907
+ failed sets.Set [types. UID ]
1911
1908
}
1912
1909
1913
1910
func newUncountedTerminatedPods (in batch.UncountedTerminatedPods ) * uncountedTerminatedPods {
1914
- obj := uncountedTerminatedPods {
1915
- succeeded : make (sets.Set [string ], len (in .Succeeded )),
1916
- failed : make (sets.Set [string ], len (in .Failed )),
1917
- }
1918
- for _ , v := range in .Succeeded {
1919
- obj .succeeded .Insert (string (v ))
1920
- }
1921
- for _ , v := range in .Failed {
1922
- obj .failed .Insert (string (v ))
1911
+ return & uncountedTerminatedPods {
1912
+ succeeded : sets .New (in .Succeeded ... ),
1913
+ failed : sets .New (in .Failed ... ),
1923
1914
}
1924
- return & obj
1925
1915
}
1926
1916
1927
- func (u * uncountedTerminatedPods ) Succeeded () sets.Set [string ] {
1917
+ func (u * uncountedTerminatedPods ) Succeeded () sets.Set [types. UID ] {
1928
1918
if u == nil {
1929
1919
return nil
1930
1920
}
1931
1921
return u .succeeded
1932
1922
}
1933
1923
1934
- func (u * uncountedTerminatedPods ) Failed () sets.Set [string ] {
1924
+ func (u * uncountedTerminatedPods ) Failed () sets.Set [types. UID ] {
1935
1925
if u == nil {
1936
1926
return nil
1937
1927
}
0 commit comments