Skip to content

Commit 061c311

Browse files
alexandearkannon92
authored andcommitted
Fix lint issues reported by gocritic (kubernetes-sigs#2000)
1 parent 805bdde commit 061c311

File tree

22 files changed

+59
-72
lines changed

22 files changed

+59
-72
lines changed

.golangci.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@ linters-settings:
66
gocritic:
77
enabled-checks:
88
- dupImport
9-
disabled-checks: # temporarily disabled checks, will fix them later
9+
disabled-checks:
1010
- appendAssign
11-
- assignOp
12-
- captLocal
13-
- commentFormatting
14-
- elseif
1511
- exitAfterDefer
16-
- ifElseChain
1712
goimports:
1813
local-prefixes: sigs.k8s.io/kueue
1914
govet:

cmd/importer/pod/check.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,8 @@ func Check(ctx context.Context, c client.Client, cache *util.ImportCache, jobs u
6363
var pv int32
6464
if pc, found := cache.PriorityClasses[p.Spec.PriorityClassName]; found {
6565
pv = pc.Value
66-
} else {
67-
if p.Spec.PriorityClassName != "" {
68-
return false, fmt.Errorf("%q: %w", p.Spec.PriorityClassName, util.ErrPCNotFound)
69-
}
66+
} else if p.Spec.PriorityClassName != "" {
67+
return false, fmt.Errorf("%q: %w", p.Spec.PriorityClassName, util.ErrPCNotFound)
7068
}
7169

7270
log.V(2).Info("Successfully checked", "clusterQueue", klog.KObj(cq), "resourceFalvor", klog.KObj(rf), "priority", pv)

cmd/importer/pod/import.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func Import(ctx context.Context, c client.Client, cache *util.ImportCache, jobs
8585
return false, fmt.Errorf("creating workload: %w", err)
8686
}
8787

88-
//make its admission and update its status
88+
// make its admission and update its status
8989
info := workload.NewInfo(wl)
9090
cq := cache.ClusterQueues[string(lq.Spec.ClusterQueue)]
9191
admission := kueue.Admission{

pkg/config/validation.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,12 @@ func validateIntegrations(c *configapi.Configuration, scheme *runtime.Scheme) fi
171171
}
172172
for idx, framework := range c.Integrations.ExternalFrameworks {
173173
gvk, _ := schema.ParseKindArg(framework)
174-
if gvk == nil {
174+
switch {
175+
case gvk == nil:
175176
allErrs = append(allErrs, field.Invalid(integrationsExternalFrameworkPath.Index(idx), framework, "must be format, 'Kind.version.group.com'"))
176-
} else if managedFrameworks.Has(gvk.String()) {
177+
case managedFrameworks.Has(gvk.String()):
177178
allErrs = append(allErrs, field.Duplicate(integrationsExternalFrameworkPath.Index(idx), framework))
178-
} else {
179+
default:
179180
managedFrameworks = managedFrameworks.Insert(gvk.String())
180181
}
181182
}

pkg/controller/admissionchecks/multikueue/admissioncheck.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,8 @@ func (a *ACReconciler) Reconcile(ctx context.Context, req reconcile.Request) (re
9797

9898
if err != nil {
9999
missingClusters = append(missingClusters, clusterName)
100-
} else {
101-
if !apimeta.IsStatusConditionTrue(cluster.Status.Conditions, kueuealpha.MultiKueueClusterActive) {
102-
inactiveClusters = append(inactiveClusters, clusterName)
103-
}
100+
} else if !apimeta.IsStatusConditionTrue(cluster.Status.Conditions, kueuealpha.MultiKueueClusterActive) {
101+
inactiveClusters = append(inactiveClusters, clusterName)
104102
}
105103
}
106104
unusableClustersCount := len(missingClusters) + len(inactiveClusters)

pkg/controller/admissionchecks/multikueue/multikueuecluster.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func (rc *remoteClient) startWatcher(ctx context.Context, kind string, w multiKu
219219
// If the context is not yet Done , queue a reconcile to attempt reconnection
220220
if ctx.Err() == nil {
221221
oldReconnect := rc.pendingReconnect.Swap(true)
222-
//reconnect if this is the first watch failing.
222+
// reconnect if this is the first watch failing.
223223
if !oldReconnect {
224224
log.V(2).Info("Queue reconcile for reconnect", "cluster", rc.clusterName)
225225
rc.queueWatchEndedEvent(ctx)
@@ -239,10 +239,8 @@ func (rc *remoteClient) queueWorkloadEvent(ctx context.Context, wlKey types.Name
239239
localWl := &kueue.Workload{}
240240
if err := rc.localClient.Get(ctx, wlKey, localWl); err == nil {
241241
rc.wlUpdateCh <- event.GenericEvent{Object: localWl}
242-
} else {
243-
if !apierrors.IsNotFound(err) {
244-
ctrl.LoggerFrom(ctx).Error(err, "reading local workload")
245-
}
242+
} else if !apierrors.IsNotFound(err) {
243+
ctrl.LoggerFrom(ctx).Error(err, "reading local workload")
246244
}
247245
}
248246

pkg/controller/admissionchecks/multikueue/workload_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ func TestWlReconcile(t *testing.T) {
467467
AdmissionCheck(kueue.AdmissionCheckState{
468468
Name: "ac1",
469469
State: kueue.CheckStateReady,
470-
LastTransitionTime: metav1.NewTime(time.Now().Add(-defaultWorkerLostTimeout / 2)), //50% of the timeout
470+
LastTransitionTime: metav1.NewTime(time.Now().Add(-defaultWorkerLostTimeout / 2)), // 50% of the timeout
471471
Message: `The workload got reservation on "worker1"`,
472472
}).
473473
ControllerReference(batchv1.SchemeGroupVersion.WithKind("Job"), "job1", "uid1").
@@ -605,7 +605,7 @@ func TestWlReconcile(t *testing.T) {
605605
*baseWorkloadBuilder.Clone().
606606
Label(kueuealpha.MultiKueueOriginLabel, defaultOrigin).
607607
ReserveQuota(utiltesting.MakeAdmission("q1").Obj()).
608-
QuotaReservedTime(time.Now().Add(-time.Minute)). //one minute ago
608+
QuotaReservedTime(time.Now().Add(-time.Minute)). // one minute ago
609609
Obj(),
610610
},
611611
worker2Jobs: []batchv1.Job{

pkg/controller/admissionchecks/provisioning/controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (c *Controller) Reconcile(ctx context.Context, req reconcile.Request) (reco
119119
}
120120

121121
if !workload.HasQuotaReservation(wl) || apimeta.IsStatusConditionTrue(wl.Status.Conditions, kueue.WorkloadFinished) {
122-
//1.2 workload has no reservation or is finished
122+
// 1.2 workload has no reservation or is finished
123123
log.V(5).Info("workload with no reservation, delete owned requests")
124124
return reconcile.Result{}, c.deleteOwnedProvisionRequests(ctx, req.Namespace, req.Name)
125125
}
@@ -222,7 +222,7 @@ func (c *Controller) syncOwnedProvisionRequest(ctx context.Context, wl *kueue.Wo
222222
log := ctrl.LoggerFrom(ctx)
223223
var requeAfter *time.Duration
224224
for _, checkName := range relevantChecks {
225-
//get the config
225+
// get the config
226226
prc, err := c.helper.ConfigForAdmissionCheck(ctx, checkName)
227227
if err != nil {
228228
// the check is not active
@@ -819,7 +819,7 @@ func remainingTime(prc *kueue.ProvisioningRequestConfig, failuresCount int32, la
819819
maxBackoff := 30 * time.Minute
820820
backoffDuration := defaultBackoff
821821
for i := 1; i < int(failuresCount); i++ {
822-
backoffDuration = backoffDuration * 2
822+
backoffDuration *= 2
823823
if backoffDuration >= maxBackoff {
824824
backoffDuration = maxBackoff
825825
break

pkg/controller/core/workload_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ func TestReconcile(t *testing.T) {
600600
Message: "The workload is deactivated",
601601
}).
602602
// The fake test not allow to save state with nil values when updating by Patch/Apply. So we are skipping this case.
603-
//RequeueState(ptr.To[int32](4), ptr.To(metav1.NewTime(testStartTime.Truncate(time.Second)))).
603+
// RequeueState(ptr.To[int32](4), ptr.To(metav1.NewTime(testStartTime.Truncate(time.Second)))).
604604
Obj(),
605605
wantWorkload: utiltesting.MakeWorkload("wl", "ns").
606606
Active(true).

pkg/controller/jobs/job/job_webhook.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,8 @@ func (w *JobWebhook) validatePartialAdmissionCreate(job *Job) field.ErrorList {
9898
v, err := strconv.Atoi(strVal)
9999
if err != nil {
100100
allErrs = append(allErrs, field.Invalid(minPodsCountAnnotationsPath, job.Annotations[JobMinParallelismAnnotation], err.Error()))
101-
} else {
102-
if int32(v) >= job.podsCount() || v <= 0 {
103-
allErrs = append(allErrs, field.Invalid(minPodsCountAnnotationsPath, v, fmt.Sprintf("should be between 0 and %d", job.podsCount()-1)))
104-
}
101+
} else if int32(v) >= job.podsCount() || v <= 0 {
102+
allErrs = append(allErrs, field.Invalid(minPodsCountAnnotationsPath, v, fmt.Sprintf("should be between 0 and %d", job.podsCount()-1)))
105103
}
106104
}
107105
if strVal, found := job.Annotations[JobCompletionsEqualParallelismAnnotation]; found {

0 commit comments

Comments
 (0)