Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Go 1.21 min/max builtins #125046

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions pkg/controller/podautoscaler/horizontal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1275,10 +1275,10 @@ func calculateScaleUpLimitWithScalingRules(currentReplicas int32, scaleUpEvents,
return currentReplicas // Scaling is disabled
} else if *scalingRules.SelectPolicy == autoscalingv2.MinChangePolicySelect {
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 {
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 {
replicasAddedInCurrentPeriod := getReplicasChangePerPeriod(policy.PeriodSeconds, scaleUpEvents)
Expand All @@ -1304,10 +1304,10 @@ func calculateScaleDownLimitWithBehaviors(currentReplicas int32, scaleUpEvents,
return currentReplicas // Scaling is disabled
} else if *scalingRules.SelectPolicy == autoscalingv2.MinChangePolicySelect {
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 {
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 {
replicasAddedInCurrentPeriod := getReplicasChangePerPeriod(policy.PeriodSeconds, scaleUpEvents)
Expand Down Expand Up @@ -1434,16 +1434,12 @@ func setConditionInList(inputList []autoscalingv2.HorizontalPodAutoscalerConditi
return resList
}

func max(a, b int32) int32 {
if a >= b {
return a
}
return b
// minInt32 is a wrapper around the min builtin to be used as a function value.
func minInt32(a, b int32) int32 {
return min(a, b)
}

func min(a, b int32) int32 {
if a <= b {
return a
}
return b
// maxInt32 is a wrapper around the max builtin to be used as a function value.
func maxInt32(a, b int32) int32 {
return max(a, b)
}
Original file line number Diff line number Diff line change
Expand Up @@ -937,10 +937,3 @@ func TestFilterOut(t *testing.T) {
})
}
}

func max(i, j int) int {
if i > j {
return i
}
return j
}
8 changes: 0 additions & 8 deletions staging/src/k8s.io/apimachinery/pkg/labels/selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
testcases := []struct {
s string
Expand Down