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

add the unparam linter to golangci and fix those issues flagged #643

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ linters-settings:
linters:
enable:
- goimports
- unparam
19 changes: 6 additions & 13 deletions pkg/controllers/jobset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,11 +489,7 @@ func (r *JobSetReconciler) reconcileReplicatedJobs(ctx context.Context, js *jobs
startupPolicy := js.Spec.StartupPolicy

for _, replicatedJob := range js.Spec.ReplicatedJobs {
jobs, err := constructJobsFromTemplate(js, &replicatedJob, ownedJobs)
if err != nil {
return err
}

jobs := constructJobsFromTemplate(js, &replicatedJob, ownedJobs)
status := findReplicatedJobStatus(replicatedJobStatus, replicatedJob.Name)

// For startup policy, if the replicatedJob is started we can skip this loop.
Expand Down Expand Up @@ -639,23 +635,20 @@ func executeSuccessPolicy(js *jobset.JobSet, ownedJobs *childJobs, updateStatusO
return false
}

func constructJobsFromTemplate(js *jobset.JobSet, rjob *jobset.ReplicatedJob, ownedJobs *childJobs) ([]*batchv1.Job, error) {
func constructJobsFromTemplate(js *jobset.JobSet, rjob *jobset.ReplicatedJob, ownedJobs *childJobs) []*batchv1.Job {
var jobs []*batchv1.Job
for jobIdx := 0; jobIdx < int(rjob.Replicas); jobIdx++ {
jobName := placement.GenJobName(js.Name, rjob.Name, jobIdx)
if create := shouldCreateJob(jobName, ownedJobs); !create {
continue
}
job, err := constructJob(js, rjob, jobIdx)
if err != nil {
return nil, err
}
job := constructJob(js, rjob, jobIdx)
jobs = append(jobs, job)
}
return jobs, nil
return jobs
}

func constructJob(js *jobset.JobSet, rjob *jobset.ReplicatedJob, jobIdx int) (*batchv1.Job, error) {
func constructJob(js *jobset.JobSet, rjob *jobset.ReplicatedJob, jobIdx int) *batchv1.Job {
job := &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Labels: collections.CloneMap(rjob.Template.Labels),
Expand Down Expand Up @@ -689,7 +682,7 @@ func constructJob(js *jobset.JobSet, rjob *jobset.ReplicatedJob, jobIdx int) (*b
jobsetSuspended := jobSetSuspended(js)
job.Spec.Suspend = ptr.To(jobsetSuspended)

return job, nil
return job
}

func addTaintToleration(job *batchv1.Job) {
Expand Down
6 changes: 1 addition & 5 deletions pkg/controllers/jobset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,11 +688,7 @@ func TestConstructJobsFromTemplate(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
var got []*batchv1.Job
for _, rjob := range tc.js.Spec.ReplicatedJobs {
jobs, err := constructJobsFromTemplate(tc.js, &rjob, tc.ownedJobs)
if err != nil {
t.Errorf("constructJobsFromTemplate() error = %v", err)
return
}
jobs := constructJobsFromTemplate(tc.js, &rjob, tc.ownedJobs)
got = append(got, jobs...)
}

Expand Down