mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 18:54:06 +00:00
Use the Defer for pod replacement policy
This commit is contained in:
parent
115dc90633
commit
f84d643c20
@ -1921,7 +1921,7 @@ func (jm *Controller) cleanupPodFinalizers(job *batch.Job) {
|
||||
func recordJobPodsCreationTotal(job *batch.Job, jobCtx *syncJobCtx, succeeded, failed int32) {
|
||||
reason := metrics.PodCreateNew
|
||||
if feature.DefaultFeatureGate.Enabled(features.JobPodReplacementPolicy) {
|
||||
if *job.Spec.PodReplacementPolicy == batch.Failed && jobCtx.failed > 0 {
|
||||
if ptr.Deref(job.Spec.PodReplacementPolicy, batch.TerminatingOrFailed) == batch.Failed && jobCtx.failed > 0 {
|
||||
reason = metrics.PodRecreateFailed
|
||||
} else if jobCtx.failed > 0 || ptr.Deref(jobCtx.terminating, 0) > 0 {
|
||||
reason = metrics.PodRecreateTerminatingOrFailed
|
||||
|
@ -115,7 +115,7 @@ func newJobWithName(name string, parallelism, completions, backoffLimit int32, c
|
||||
j.Spec.Parallelism = nil
|
||||
}
|
||||
j.Spec.BackoffLimit = &backoffLimit
|
||||
defaultPodReplacementPolicy(j)
|
||||
|
||||
return j
|
||||
}
|
||||
|
||||
@ -3880,7 +3880,6 @@ func TestSyncJobWithJobBackoffLimitPerIndex(t *testing.T) {
|
||||
manager.podStoreSynced = alwaysReady
|
||||
manager.jobStoreSynced = alwaysReady
|
||||
job := &tc.job
|
||||
defaultPodReplacementPolicy(job)
|
||||
|
||||
actual := job
|
||||
manager.updateStatusHandler = func(ctx context.Context, job *batch.Job) (*batch.Job, error) {
|
||||
@ -5532,11 +5531,3 @@ func setDurationDuringTest(val *time.Duration, newVal time.Duration) func() {
|
||||
*val = origVal
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to simulate defaulting of the PodReplacementPolicy field in unit tests
|
||||
// as the job controller code assumes it is set by the kube-apiserver.
|
||||
func defaultPodReplacementPolicy(job *batch.Job) {
|
||||
if feature.DefaultFeatureGate.Enabled(features.JobPodReplacementPolicy) && job.Spec.PodReplacementPolicy == nil {
|
||||
job.Spec.PodReplacementPolicy = ptr.To(batch.TerminatingOrFailed)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user