Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the bug in interpreting the replicas of Job #5095

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/resourceinterpreter/default/native/replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. In my local test, when parallelism > completions, only completions number of jobs will be generated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, we are trying to address the accuracy issue. Right?

Generally looks good to me, just a question need to confirm.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

if replica > completions {
replica = completions
}
requirement := helper.GenerateReplicaRequirements(&job.Spec.Template)

return replica, requirement, nil
Expand Down