Skip to content

Commit 586f0fa

Browse files
authored
Merge pull request kubernetes#125046 from tklauser/min-max-builtins
Use Go 1.21 min/max builtins
2 parents 2095380 + b01b016 commit 586f0fa

File tree

3 files changed

+10
-29
lines changed

3 files changed

+10
-29
lines changed

pkg/controller/podautoscaler/horizontal.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,10 +1275,10 @@ func calculateScaleUpLimitWithScalingRules(currentReplicas int32, scaleUpEvents,
12751275
return currentReplicas // Scaling is disabled
12761276
} else if *scalingRules.SelectPolicy == autoscalingv2.MinChangePolicySelect {
12771277
result = math.MaxInt32
1278-
selectPolicyFn = min // For scaling up, the lowest change ('min' policy) produces a minimum value
1278+
selectPolicyFn = minInt32 // For scaling up, the lowest change ('min' policy) produces a minimum value
12791279
} else {
12801280
result = math.MinInt32
1281-
selectPolicyFn = max // Use the default policy otherwise to produce a highest possible change
1281+
selectPolicyFn = maxInt32 // Use the default policy otherwise to produce a highest possible change
12821282
}
12831283
for _, policy := range scalingRules.Policies {
12841284
replicasAddedInCurrentPeriod := getReplicasChangePerPeriod(policy.PeriodSeconds, scaleUpEvents)
@@ -1304,10 +1304,10 @@ func calculateScaleDownLimitWithBehaviors(currentReplicas int32, scaleUpEvents,
13041304
return currentReplicas // Scaling is disabled
13051305
} else if *scalingRules.SelectPolicy == autoscalingv2.MinChangePolicySelect {
13061306
result = math.MinInt32
1307-
selectPolicyFn = max // For scaling down, the lowest change ('min' policy) produces a maximum value
1307+
selectPolicyFn = maxInt32 // For scaling down, the lowest change ('min' policy) produces a maximum value
13081308
} else {
13091309
result = math.MaxInt32
1310-
selectPolicyFn = min // Use the default policy otherwise to produce a highest possible change
1310+
selectPolicyFn = minInt32 // Use the default policy otherwise to produce a highest possible change
13111311
}
13121312
for _, policy := range scalingRules.Policies {
13131313
replicasAddedInCurrentPeriod := getReplicasChangePerPeriod(policy.PeriodSeconds, scaleUpEvents)
@@ -1434,16 +1434,12 @@ func setConditionInList(inputList []autoscalingv2.HorizontalPodAutoscalerConditi
14341434
return resList
14351435
}
14361436

1437-
func max(a, b int32) int32 {
1438-
if a >= b {
1439-
return a
1440-
}
1441-
return b
1437+
// minInt32 is a wrapper around the min builtin to be used as a function value.
1438+
func minInt32(a, b int32) int32 {
1439+
return min(a, b)
14421440
}
14431441

1444-
func min(a, b int32) int32 {
1445-
if a <= b {
1446-
return a
1447-
}
1448-
return b
1442+
// maxInt32 is a wrapper around the max builtin to be used as a function value.
1443+
func maxInt32(a, b int32) int32 {
1444+
return max(a, b)
14491445
}

staging/src/k8s.io/apiextensions-apiserver/pkg/controller/openapi/v2/conversion_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -937,10 +937,3 @@ func TestFilterOut(t *testing.T) {
937937
})
938938
}
939939
}
940-
941-
func max(i, j int) int {
942-
if i > j {
943-
return i
944-
}
945-
return j
946-
}

staging/src/k8s.io/apimachinery/pkg/labels/selector_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,6 @@ func TestLexer(t *testing.T) {
224224
}
225225
}
226226

227-
func min(l, r int) (m int) {
228-
m = r
229-
if l < r {
230-
m = l
231-
}
232-
return m
233-
}
234-
235227
func TestLexerSequence(t *testing.T) {
236228
testcases := []struct {
237229
s string

0 commit comments

Comments
 (0)