Skip to content

Commit

Permalink
Fix the bug in interpreting the replicas of Job
Browse files Browse the repository at this point in the history
Signed-off-by: whitewindmills <jayfantasyhjh@gmail.com>
  • Loading branch information
whitewindmills committed Jun 24, 2024
1 parent 1255a08 commit fe648e0
Showing 1 changed file with 8 additions and 0 deletions.
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/pointer"

Check failure on line 26 in pkg/resourceinterpreter/default/native/replica.go

View workflow job for this annotation

GitHub Actions / lint

SA1019: "k8s.io/utils/pointer" is deprecated: Use functions in k8s.io/utils/ptr instead: ptr.To to obtain a pointer, ptr.Deref to dereference a pointer, ptr.Equal to compare dereferenced pointers. (staticcheck)

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 := pointer.Int32Deref(job.Spec.Completions, replica)
if replica > completions {
replica = completions
}
requirement := helper.GenerateReplicaRequirements(&job.Spec.Template)

return replica, requirement, nil
Expand Down

0 comments on commit fe648e0

Please sign in to comment.