fix: fix bugs about validation of targetMinReplicas<=targetMaxReplicas and CronFederatedHPA status

Signed-off-by: jwcesign <jwcesign@gmail.com>
This commit is contained in:
jwcesign 2023-07-29 15:53:17 +08:00
parent ee3fa49ac0
commit 4da22c3f28
2 changed files with 4 additions and 3 deletions

View File

@ -268,7 +268,7 @@ func (c *CronFederatedHPAJob) addFailedExecutionHistory(
func (c *CronFederatedHPAJob) addSuccessExecutionHistory(
cronFHPA *autoscalingv1alpha1.CronFederatedHPA,
appliedReplicas, appliedMaxReplicas, appliedMinReplicas *int32) error {
appliedReplicas, appliedMinReplicas, appliedMaxReplicas *int32) error {
_, nextExecutionTime := c.scheduler.NextRun()
// Add success history record, return false if there is no such rule

View File

@ -16,6 +16,7 @@ package cronfederatedhpa
import (
"context"
"fmt"
"math"
"net/http"
"time"
_ "time/tzdata"
@ -140,11 +141,11 @@ func validateCronFederatedHPAScalingReplicas(rule autoscalingv1alpha1.CronFedera
errs = append(errs, field.Invalid(fldPath.Child("targetMinReplicas"), "",
"targetMinReplicas should be larger than 0"))
}
if pointer.Int32Deref(rule.TargetMaxReplicas, 1) <= 0 {
if pointer.Int32Deref(rule.TargetMaxReplicas, math.MaxInt32) <= 0 {
errs = append(errs, field.Invalid(fldPath.Child("targetMaxReplicas"), "",
"targetMaxReplicas should be larger than 0"))
}
if pointer.Int32Deref(rule.TargetMinReplicas, 1) > pointer.Int32Deref(rule.TargetMaxReplicas, 1) {
if pointer.Int32Deref(rule.TargetMinReplicas, 1) > pointer.Int32Deref(rule.TargetMaxReplicas, math.MaxInt32) {
errs = append(errs, field.Invalid(fldPath.Child("targetMinReplicas"), "",
"targetMaxReplicas should be larger than or equal to targetMinReplicas"))
}