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

fix: Incorrect conversion between integer types #446

Merged
merged 1 commit into from
Oct 6, 2023
Merged
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
23 changes: 16 additions & 7 deletions controllers/hpa/hpa_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ func getHPAMetrics(metadata metav1.ObjectMeta) []hpav2.MetricSpec {
resourceName := corev1.ResourceCPU

if value, ok := annotations[constants.TargetUtilizationPercentage]; ok {
utilizationInt, _ := strconv.Atoi(value)
utilization = int32(utilizationInt)
if valueInt, err := strconv.ParseInt(value, 10, 32); err != nil {
log.Error(err, "Could not parse TargetUtilizationPercentage", "value", value)
} else {
utilization = int32(valueInt)
}
}

if value, ok := annotations[constants.AutoscalerMetrics]; ok {
Expand Down Expand Up @@ -90,13 +93,19 @@ func createHPA(runtimeMeta metav1.ObjectMeta, mmDeploymentName string, mmNamespa
annotations := runtimeMeta.Annotations

if value, ok := annotations[mmcontstant.MinScaleAnnotationKey]; ok {
minReplicasInt, _ := strconv.Atoi(value)
minReplicas = int32(minReplicasInt)

if valueInt, err := strconv.ParseInt(value, 10, 32); err != nil {
log.Error(err, "Could not parse MinScaleAnnotationKey", "value", value)
} else {
minReplicas = int32(valueInt)
}
}

if value, ok := annotations[mmcontstant.MaxScaleAnnotationKey]; ok {
maxReplicasInt, _ := strconv.Atoi(value)
maxReplicas = int32(maxReplicasInt)
if valueInt, err := strconv.ParseInt(value, 10, 32); err != nil {
log.Error(err, "Could not parse MaxScaleAnnotationKey", "value", value)
} else {
maxReplicas = int32(valueInt)
}
}

if maxReplicas < minReplicas {
Expand Down