Skip to content

Commit 499f7ba

Browse files
committed
resolved lint errors
This commit resolves the lint errors caused during the checks for previous commit.
1 parent 5b73737 commit 499f7ba

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

internal/contract/version.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func GetLatestContractAndAPIVersionFromContract(metadata metav1.Object, currentC
124124

125125
sortedCompatibleContractVersions := kubeAwareAPIVersions(GetCompatibleVersions(currentContractVersion).UnsortedList())
126126
slices.SortFunc(sortedCompatibleContractVersions, func(i, j string) int {
127-
return sortedCompatibleContractVersions.SortFunc(i, j, DESCENDING)
127+
return sortedCompatibleContractVersions.SortFunc(i, j, descending)
128128
})
129129

130130
for _, contractVersion := range sortedCompatibleContractVersions {
@@ -139,7 +139,7 @@ func GetLatestContractAndAPIVersionFromContract(metadata metav1.Object, currentC
139139
// Pick the latest version in the slice and validate it.
140140
kubeVersions := kubeAwareAPIVersions(strings.Split(supportedVersions, "_"))
141141
slices.SortFunc(kubeVersions, func(i, j string) int {
142-
return kubeVersions.SortFunc(i, j, ASCENDING)
142+
return kubeVersions.SortFunc(i, j, ascending)
143143
})
144144
return contractVersion, kubeVersions[len(kubeVersions)-1], nil
145145
}
@@ -192,19 +192,23 @@ func GetGKMetadata(ctx context.Context, c client.Reader, gk schema.GroupKind) (*
192192
// versions. e.g. v2, v1, v1beta2, v1beta1, v1alpha1.
193193
type kubeAwareAPIVersions []string
194194

195+
// SortFunc uses these constants to determine the order of sorting
195196
const (
196-
ASCENDING = iota
197-
DESCENDING
197+
// Used to sort in ascending order of occurance
198+
ascending = iota
199+
200+
// Used to sort in descending order of occurance
201+
descending
198202
)
199203

200204
func (k kubeAwareAPIVersions) SortFunc(i, j string, order int) int {
201205
if k8sversion.CompareKubeAwareVersionStrings(i, j) < 0 {
202-
if order == ASCENDING {
206+
if order == ascending {
203207
return -1
204208
}
205209
return 1
206210
}
207-
if order == ASCENDING {
211+
if order == ascending {
208212
return 1
209213
}
210214
return -1

internal/controllers/machinedeployment/machinedeployment_sync.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,11 @@ func (r *Reconciler) scale(ctx context.Context, deployment *clusterv1.MachineDep
425425
switch {
426426
case deploymentReplicasToAdd > 0:
427427
slices.SortFunc(allMSs, func(a, b *clusterv1.MachineSet) int {
428-
return mdutil.SortBySize(a, b, mdutil.NEW_TO_OLD)
428+
return mdutil.SortBySize(a, b, mdutil.DESCENDING)
429429
})
430430
case deploymentReplicasToAdd < 0:
431431
slices.SortFunc(allMSs, func(a, b *clusterv1.MachineSet) int {
432-
return mdutil.SortBySize(a, b, mdutil.OLD_TO_NEW)
432+
return mdutil.SortBySize(a, b, mdutil.ASCENDING)
433433
})
434434
}
435435

internal/controllers/machinedeployment/mdutil/util.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,18 @@ import (
4242
"sigs.k8s.io/cluster-api/util/conversion"
4343
)
4444

45+
// Sort functions in this file, use these constants to determine the sorting order
4546
const (
47+
// Used to sort elements in Ascending order
48+
// Also used in cases, where the order is from older to newer occurances
4649
ASCENDING = iota
50+
51+
// Used to sort elements in Descending order
52+
// Also used in cases, where the order is from newer to older occurances
4753
DESCENDING
48-
OLD_TO_NEW
49-
NEW_TO_OLD
5054
)
5155

52-
// MachineSetsByCreationTimestamp sorts a list of MachineSet by creation timestamp, using their names as a tie breaker.
53-
// type MachineSetsByCreationTimestamp []*clusterv1.MachineSet
56+
// SortByCreationTimestamp sorts a list of MachineSet by creation timestamp, using their names as a tie breaker.
5457
func SortByCreationTimestamp(a, b *clusterv1.MachineSet, order int) int {
5558
if b.CreationTimestamp.Equal(&a.CreationTimestamp) {
5659
if b.Name > a.Name {
@@ -81,28 +84,27 @@ func SortByCreationTimestamp(a, b *clusterv1.MachineSet, order int) int {
8184
}
8285

8386
// SortBySize sorts a list of MachineSet by size in descending order, using their creation timestamp or name as a tie breaker.
84-
// By using the creation timestamp, this sorts from old to new machine sets if order is OLD_TO_NEW or new to old machine sets if order is NEW_TO_OLD.
87+
// By using the creation timestamp, this sorts from old to new machine sets if order is ASCENDING or new to old machine sets if order is DESCENDING.
8588
func SortBySize(a, b *clusterv1.MachineSet, order int) int {
8689
if *(a.Spec.Replicas) == *(b.Spec.Replicas) {
87-
if order == OLD_TO_NEW {
90+
if order == ASCENDING {
8891
if a.CreationTimestamp.Before(&b.CreationTimestamp) {
8992
return -1
9093
}
9194
return 1
92-
} else {
93-
if b.CreationTimestamp.Before(&a.CreationTimestamp) {
94-
return -1
95-
}
96-
return 1
9795
}
96+
if b.CreationTimestamp.Before(&a.CreationTimestamp) {
97+
return -1
98+
}
99+
return 1
98100
}
99101
if *(a.Spec.Replicas) > *(b.Spec.Replicas) {
100102
return -1
101103
}
102104
return 1
103105
}
104106

105-
// MachineSetsByDecreasingReplicas sorts the list of MachineSets in decreasing order of replicas,
107+
// SortByDecreasingReplicas sorts the list of MachineSets in decreasing order of replicas,
106108
// using creation time (ascending order) and name (alphabetical) as tie breakers.
107109
func SortByDecreasingReplicas(a, b *clusterv1.MachineSet) int {
108110
if a.Spec.Replicas == nil {

0 commit comments

Comments
 (0)