Skip to content

Commit

Permalink
Merge pull request #3863 from jwcesign/add-validation-cronfhpa
Browse files Browse the repository at this point in the history
fix: fix bugs about validation of targetMinReplicas<=targetMaxReplicas and CronFederatedHPA status record
  • Loading branch information
karmada-bot authored Jul 31, 2023
2 parents fe0fc02 + 4da22c3 commit 9311a25
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/controllers/cronfederatedhpa/cronfederatedhpa_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pkg/webhook/cronfederatedhpa/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cronfederatedhpa
import (
"context"
"fmt"
"math"
"net/http"
"time"
_ "time/tzdata"
Expand Down Expand Up @@ -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"))
}
Expand Down

0 comments on commit 9311a25

Please sign in to comment.