mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 02:09:56 +00:00
Merge pull request #121011 from kannon92/job-pod-replacement-policy-feature-on-but-api-specified
Fix panic when enablement of pod replacement policy is skewed
This commit is contained in:
commit
27ff547a14
@ -1875,7 +1875,10 @@ func countReadyPods(pods []*v1.Pod) int32 {
|
||||
// PodReplacementPolicy controls when we recreate pods if they are marked as terminating
|
||||
// Failed means that we recreate only once the pod has terminated.
|
||||
func onlyReplaceFailedPods(job *batch.Job) bool {
|
||||
if feature.DefaultFeatureGate.Enabled(features.JobPodReplacementPolicy) && *job.Spec.PodReplacementPolicy == batch.Failed {
|
||||
// We check both PodReplacementPolicy for nil and failed
|
||||
// because it is possible that `PodReplacementPolicy` is not defaulted,
|
||||
// when the `JobPodReplacementPolicy` feature gate is disabled for API server.
|
||||
if feature.DefaultFeatureGate.Enabled(features.JobPodReplacementPolicy) && job.Spec.PodReplacementPolicy != nil && *job.Spec.PodReplacementPolicy == batch.Failed {
|
||||
return true
|
||||
}
|
||||
return feature.DefaultFeatureGate.Enabled(features.JobPodFailurePolicy) && job.Spec.PodFailurePolicy != nil
|
||||
|
@ -366,6 +366,19 @@ func TestControllerSyncJob(t *testing.T) {
|
||||
expectedDeletions: 1,
|
||||
expectedFailed: 1,
|
||||
},
|
||||
"WQ job: turn on PodReplacementPolicy but not set PodReplacementPolicy": {
|
||||
parallelism: 1,
|
||||
completions: 1,
|
||||
backoffLimit: 6,
|
||||
activePods: 1,
|
||||
failedPods: 1,
|
||||
jobPodReplacementPolicy: true,
|
||||
expectedTerminating: ptr.To[int32](1),
|
||||
terminatingPods: 1,
|
||||
expectedActive: 1,
|
||||
expectedPodPatches: 2,
|
||||
expectedFailed: 2,
|
||||
},
|
||||
"WQ job: recreate pods when terminating or failed": {
|
||||
parallelism: 1,
|
||||
completions: -1,
|
||||
|
Loading…
Reference in New Issue
Block a user