Merge pull request #125046 from tklauser/min-max-builtins

Use Go 1.21 min/max builtins
This commit is contained in:
Kubernetes Prow Robot 2025-01-30 07:33:23 -08:00 committed by GitHub
commit 586f0fad5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 29 deletions

View File

@ -1275,10 +1275,10 @@ func calculateScaleUpLimitWithScalingRules(currentReplicas int32, scaleUpEvents,
return currentReplicas // Scaling is disabled return currentReplicas // Scaling is disabled
} else if *scalingRules.SelectPolicy == autoscalingv2.MinChangePolicySelect { } else if *scalingRules.SelectPolicy == autoscalingv2.MinChangePolicySelect {
result = math.MaxInt32 result = math.MaxInt32
selectPolicyFn = min // For scaling up, the lowest change ('min' policy) produces a minimum value selectPolicyFn = minInt32 // For scaling up, the lowest change ('min' policy) produces a minimum value
} else { } else {
result = math.MinInt32 result = math.MinInt32
selectPolicyFn = max // Use the default policy otherwise to produce a highest possible change selectPolicyFn = maxInt32 // Use the default policy otherwise to produce a highest possible change
} }
for _, policy := range scalingRules.Policies { for _, policy := range scalingRules.Policies {
replicasAddedInCurrentPeriod := getReplicasChangePerPeriod(policy.PeriodSeconds, scaleUpEvents) replicasAddedInCurrentPeriod := getReplicasChangePerPeriod(policy.PeriodSeconds, scaleUpEvents)
@ -1304,10 +1304,10 @@ func calculateScaleDownLimitWithBehaviors(currentReplicas int32, scaleUpEvents,
return currentReplicas // Scaling is disabled return currentReplicas // Scaling is disabled
} else if *scalingRules.SelectPolicy == autoscalingv2.MinChangePolicySelect { } else if *scalingRules.SelectPolicy == autoscalingv2.MinChangePolicySelect {
result = math.MinInt32 result = math.MinInt32
selectPolicyFn = max // For scaling down, the lowest change ('min' policy) produces a maximum value selectPolicyFn = maxInt32 // For scaling down, the lowest change ('min' policy) produces a maximum value
} else { } else {
result = math.MaxInt32 result = math.MaxInt32
selectPolicyFn = min // Use the default policy otherwise to produce a highest possible change selectPolicyFn = minInt32 // Use the default policy otherwise to produce a highest possible change
} }
for _, policy := range scalingRules.Policies { for _, policy := range scalingRules.Policies {
replicasAddedInCurrentPeriod := getReplicasChangePerPeriod(policy.PeriodSeconds, scaleUpEvents) replicasAddedInCurrentPeriod := getReplicasChangePerPeriod(policy.PeriodSeconds, scaleUpEvents)
@ -1434,16 +1434,12 @@ func setConditionInList(inputList []autoscalingv2.HorizontalPodAutoscalerConditi
return resList return resList
} }
func max(a, b int32) int32 { // minInt32 is a wrapper around the min builtin to be used as a function value.
if a >= b { func minInt32(a, b int32) int32 {
return a return min(a, b)
}
return b
} }
func min(a, b int32) int32 { // maxInt32 is a wrapper around the max builtin to be used as a function value.
if a <= b { func maxInt32(a, b int32) int32 {
return a return max(a, b)
}
return b
} }

View File

@ -937,10 +937,3 @@ func TestFilterOut(t *testing.T) {
}) })
} }
} }
func max(i, j int) int {
if i > j {
return i
}
return j
}

View File

@ -224,14 +224,6 @@ func TestLexer(t *testing.T) {
} }
} }
func min(l, r int) (m int) {
m = r
if l < r {
m = l
}
return m
}
func TestLexerSequence(t *testing.T) { func TestLexerSequence(t *testing.T) {
testcases := []struct { testcases := []struct {
s string s string