Merge pull request #5095 from whitewindmills/jobs-replicas

Fix the bug in interpreting the replicas of Job
This commit is contained in:
karmada-bot 2024-06-26 17:37:51 +08:00 committed by GitHub
commit 4706dd8b54
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 0 deletions

View File

@ -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