From 5ed14f30b0b9ff507828741d3ee0d3f070eb97ab Mon Sep 17 00:00:00 2001 From: whitewindmills Date: Mon, 24 Jun 2024 18:09:36 +0800 Subject: [PATCH] Fix the bug in interpreting the replicas of Job Signed-off-by: whitewindmills --- pkg/resourceinterpreter/default/native/replica.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/resourceinterpreter/default/native/replica.go b/pkg/resourceinterpreter/default/native/replica.go index fbbc77bd3647..53b2a60038fc 100644 --- a/pkg/resourceinterpreter/default/native/replica.go +++ b/pkg/resourceinterpreter/default/native/replica.go @@ -23,6 +23,7 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/klog/v2" + "k8s.io/utils/ptr" workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2" "github.com/karmada-io/karmada/pkg/util" @@ -86,6 +87,13 @@ func jobReplica(object *unstructured.Unstructured) (int32, *workv1alpha2.Replica if job.Spec.Parallelism != nil { replica = *job.Spec.Parallelism } + // For fixed completion count Jobs, the actual number of pods running in parallel will not exceed the number of remaining completions. + // Higher values of .spec.parallelism are effectively ignored. + // More info: https://kubernetes.io/docs/concepts/workloads/controllers/job/ + completions := ptr.Deref[int32](job.Spec.Completions, replica) + if replica > completions { + replica = completions + } requirement := helper.GenerateReplicaRequirements(&job.Spec.Template) return replica, requirement, nil