Skip to content

Commit eaa43d3

Browse files
authored
Refactor variable names according to Go style guide (#2202)
1 parent 90689f6 commit eaa43d3

File tree

15 files changed

+61
-57
lines changed

15 files changed

+61
-57
lines changed

‎.golangci.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ linters-settings:
1818
enable-all-rules: false
1919
rules:
2020
- name: empty-lines
21+
- name: var-naming
2122

2223
# Settings for enabling and disabling linters
2324
linters:

‎apis/config/v1beta1/defaults.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ func getOperatorNamespace() string {
6060
}
6161

6262
// SetDefaults_Configuration sets default values for ComponentConfig.
63+
//
64+
//nolint:revive // format required by generated code for defaulting
6365
func SetDefaults_Configuration(cfg *Configuration) {
6466
if cfg.Namespace == nil {
6567
cfg.Namespace = ptr.To(getOperatorNamespace())

‎apis/visibility/v1alpha1/defaults.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func addDefaultingFuncs(scheme *runtime.Scheme) error {
3030
return RegisterDefaults(scheme)
3131
}
3232

33+
//nolint:revive // format required by generated code for defaulting
3334
func SetDefaults_PendingWorkloadOptions(obj *PendingWorkloadOptions) {
3435
if obj.Limit == 0 {
3536
obj.Limit = constants.DefaultPendingWorkloadsLimit

‎cmd/importer/pod/import.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ func Import(ctx context.Context, c client.Client, cache *util.ImportCache, jobs
135135
}
136136

137137
func checkError(err error) (retry, reload bool, timeout time.Duration) {
138-
retry_seconds, retry := apierrors.SuggestsClientDelay(err)
138+
retrySeconds, retry := apierrors.SuggestsClientDelay(err)
139139
if retry {
140-
return true, false, time.Duration(retry_seconds) * time.Second
140+
return true, false, time.Duration(retrySeconds) * time.Second
141141
}
142142

143143
if apierrors.IsConflict(err) {

‎pkg/controller/admissionchecks/multikueue/fswatch.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,16 @@ func (w *KubeConfigFSWatcher) remove(cluster string) {
150150
kcPath := w.clusterToFile[cluster]
151151
dir := path.Dir(kcPath)
152152

153-
file_removed := false
153+
fileRemoved := false
154154
if s, found := w.fileToClusters[kcPath]; found {
155155
s.Delete(cluster)
156156
if s.Len() == 0 {
157157
delete(w.fileToClusters, kcPath)
158-
file_removed = true
158+
fileRemoved = true
159159
}
160160
}
161161

162-
if file_removed {
162+
if fileRemoved {
163163
if s, found := w.parentDirToFiles[dir]; found {
164164
s.Delete(kcPath)
165165
if s.Len() == 0 {

‎pkg/controller/jobframework/reconciler.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -888,14 +888,14 @@ func (r *JobReconciler) constructWorkload(ctx context.Context, job GenericJob, o
888888
if wl.Labels == nil {
889889
wl.Labels = make(map[string]string)
890890
}
891-
jobUid := string(job.Object().GetUID())
892-
if errs := validation.IsValidLabelValue(jobUid); len(errs) == 0 {
893-
wl.Labels[controllerconsts.JobUIDLabel] = jobUid
891+
jobUID := string(job.Object().GetUID())
892+
if errs := validation.IsValidLabelValue(jobUID); len(errs) == 0 {
893+
wl.Labels[controllerconsts.JobUIDLabel] = jobUID
894894
} else {
895895
log.V(2).Info(
896896
"Validation of the owner job UID label has failed. Creating workload without the label.",
897897
"ValidationErrors", errs,
898-
"LabelValue", jobUid,
898+
"LabelValue", jobUID,
899899
)
900900
}
901901

‎pkg/controller/jobs/job/job_controller.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ func (j *Job) ReclaimablePods() ([]kueue.ReclaimablePod, error) {
214214
var (
215215
// the legacy names are no longer defined in the api, only in k/2/apis/batch
216216
legacyJobNameLabel = "job-name"
217-
legacyControllerUidLabel = "controller-uid"
218-
ManagedLabels = []string{legacyJobNameLabel, legacyControllerUidLabel, batchv1.JobNameLabel, batchv1.ControllerUidLabel}
217+
legacyControllerUIDLabel = "controller-uid"
218+
ManagedLabels = []string{legacyJobNameLabel, legacyControllerUIDLabel, batchv1.JobNameLabel, batchv1.ControllerUidLabel}
219219
)
220220

221221
func cleanManagedLabels(pt *corev1.PodTemplateSpec) *corev1.PodTemplateSpec {

‎pkg/controller/jobs/pod/pod_controller.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -588,13 +588,13 @@ func getRoleHash(p corev1.Pod) (string, error) {
588588
},
589589
}
590590

591-
shapeJson, err := json.Marshal(shape)
591+
shapeJSON, err := json.Marshal(shape)
592592
if err != nil {
593593
return "", err
594594
}
595595

596596
// Trim hash to 8 characters and return
597-
return fmt.Sprintf("%x", sha256.Sum256(shapeJson))[:8], nil
597+
return fmt.Sprintf("%x", sha256.Sum256(shapeJSON))[:8], nil
598598
}
599599

600600
// Load loads all pods in the group
@@ -951,14 +951,14 @@ func (p *Pod) ConstructComposableWorkload(ctx context.Context, c client.Client,
951951
wl.Spec.PodSets = p.PodSets()
952952

953953
wl.Name = jobframework.GetWorkloadNameForOwnerWithGVK(p.pod.GetName(), p.pod.GetUID(), p.GVK())
954-
jobUid := string(object.GetUID())
955-
if errs := validation.IsValidLabelValue(jobUid); len(errs) == 0 {
956-
wl.Labels[controllerconsts.JobUIDLabel] = jobUid
954+
jobUID := string(object.GetUID())
955+
if errs := validation.IsValidLabelValue(jobUID); len(errs) == 0 {
956+
wl.Labels[controllerconsts.JobUIDLabel] = jobUID
957957
} else {
958958
log.V(2).Info(
959959
"Validation of the owner job UID label has failed. Creating workload without the label.",
960960
"ValidationErrors", errs,
961-
"LabelValue", jobUid,
961+
"LabelValue", jobUID,
962962
)
963963
}
964964

‎pkg/scheduler/flavorassigner/flavorassigner.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ func (a *Assignment) append(requests workload.Requests, psAssignment *PodSetAssi
380380
// reasons or failure.
381381
func (a *FlavorAssigner) findFlavorForPodSetResource(
382382
log logr.Logger,
383-
psId int,
383+
psID int,
384384
requests workload.Requests,
385385
resName corev1.ResourceName,
386386
assignmentUsage cache.FlavorResourceQuantities,
@@ -394,15 +394,15 @@ func (a *FlavorAssigner) findFlavorForPodSetResource(
394394

395395
status := &Status{}
396396
requests = filterRequestedResources(requests, resourceGroup.CoveredResources)
397-
podSpec := &a.wl.Obj.Spec.PodSets[psId].Template.Spec
397+
podSpec := &a.wl.Obj.Spec.PodSets[psID].Template.Spec
398398

399399
var bestAssignment ResourceAssignment
400400
bestAssignmentMode := NoFit
401401

402402
// We will only check against the flavors' labels for the resource.
403403
selector := flavorSelector(podSpec, resourceGroup.LabelKeys)
404404
assignedFlavorIdx := -1
405-
idx := a.wl.LastAssignment.NextFlavorToTryForPodSetResource(psId, resName)
405+
idx := a.wl.LastAssignment.NextFlavorToTryForPodSetResource(psID, resName)
406406
for ; idx < len(resourceGroup.Flavors); idx++ {
407407
flvQuotas := resourceGroup.Flavors[idx]
408408
flavor, exist := a.resourceFlavors[flvQuotas.Name]

‎pkg/scheduler/scheduler_test.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,7 +1967,7 @@ func TestLastSchedulingContext(t *testing.T) {
19671967
Resource(corev1.ResourceCPU, "100", "0").Obj(),
19681968
).Obj(),
19691969
}
1970-
clusterQueue_cohort := []kueue.ClusterQueue{
1970+
clusterQueueCohort := []kueue.ClusterQueue{
19711971
*utiltesting.MakeClusterQueue("eng-cohort-alpha").
19721972
Cohort("cohort").
19731973
QueueingStrategy(kueue.StrictFIFO).
@@ -2118,7 +2118,7 @@ func TestLastSchedulingContext(t *testing.T) {
21182118
},
21192119
{
21202120
name: "borrow before next flavor",
2121-
cqs: clusterQueue_cohort,
2121+
cqs: clusterQueueCohort,
21222122
admittedWorkloads: []kueue.Workload{
21232123
*utiltesting.MakeWorkload("placeholder", "default").
21242124
Request(corev1.ResourceCPU, "50").
@@ -2150,7 +2150,7 @@ func TestLastSchedulingContext(t *testing.T) {
21502150
},
21512151
{
21522152
name: "borrow after all flavors",
2153-
cqs: clusterQueue_cohort,
2153+
cqs: clusterQueueCohort,
21542154
admittedWorkloads: []kueue.Workload{
21552155
*utiltesting.MakeWorkload("placeholder", "default").
21562156
Request(corev1.ResourceCPU, "50").
@@ -2182,7 +2182,7 @@ func TestLastSchedulingContext(t *testing.T) {
21822182
},
21832183
{
21842184
name: "when the next flavor is full, but can borrow on first",
2185-
cqs: clusterQueue_cohort,
2185+
cqs: clusterQueueCohort,
21862186
admittedWorkloads: []kueue.Workload{
21872187
*utiltesting.MakeWorkload("placeholder", "default").
21882188
Request(corev1.ResourceCPU, "40").
@@ -2220,7 +2220,7 @@ func TestLastSchedulingContext(t *testing.T) {
22202220
},
22212221
{
22222222
name: "when the next flavor is full, but can preempt on first",
2223-
cqs: clusterQueue_cohort,
2223+
cqs: clusterQueueCohort,
22242224
admittedWorkloads: []kueue.Workload{
22252225
*utiltesting.MakeWorkload("placeholder-alpha", "default").
22262226
Priority(-1).

0 commit comments

Comments
 (0)