Skip to content

Commit 4706dd8

Browse files
authored
Merge pull request #5095 from whitewindmills/jobs-replicas
Fix the bug in interpreting the replicas of Job
2 parents ef87b38 + bf9eaf0 commit 4706dd8

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pkg/resourceinterpreter/default/native/replica.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2424
"k8s.io/apimachinery/pkg/runtime/schema"
2525
"k8s.io/klog/v2"
26+
"k8s.io/utils/ptr"
2627

2728
workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2"
2829
"github.com/karmada-io/karmada/pkg/util"
@@ -86,6 +87,13 @@ func jobReplica(object *unstructured.Unstructured) (int32, *workv1alpha2.Replica
8687
if job.Spec.Parallelism != nil {
8788
replica = *job.Spec.Parallelism
8889
}
90+
// For fixed completion count Jobs, the actual number of pods running in parallel will not exceed the number of remaining completions.
91+
// Higher values of .spec.parallelism are effectively ignored.
92+
// More info: https://kubernetes.io/docs/concepts/workloads/controllers/job/
93+
completions := ptr.Deref[int32](job.Spec.Completions, replica)
94+
if replica > completions {
95+
replica = completions
96+
}
8997
requirement := helper.GenerateReplicaRequirements(&job.Spec.Template)
9098

9199
return replica, requirement, nil

0 commit comments

Comments
 (0)