Skip to content

Commit

Permalink
Merge pull request #5903 from anujagrawal699/fix/default-history-limi…
Browse files Browse the repository at this point in the history
…t-constant

refactor: introduce DefaultHistoryLimit constant for CronFederatedHPA
  • Loading branch information
karmada-bot authored Dec 3, 2024
2 parents 064ccf1 + 47528b4 commit 3323935
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
7 changes: 5 additions & 2 deletions pkg/util/helper/cronfederatedhpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import (
autoscalingv1alpha1 "github.com/karmada-io/karmada/pkg/apis/autoscaling/v1alpha1"
)

// DefaultHistoryLimit defines the default number of history entries to keep
const DefaultHistoryLimit = 3

// IsCronFederatedHPARuleSuspend returns true if the CronFederatedHPA is suspended.
func IsCronFederatedHPARuleSuspend(rule autoscalingv1alpha1.CronFederatedHPARule) bool {
if rule.Suspend == nil {
Expand All @@ -33,15 +36,15 @@ func IsCronFederatedHPARuleSuspend(rule autoscalingv1alpha1.CronFederatedHPARule
// GetCronFederatedHPASuccessHistoryLimits returns the successful history limits of the CronFederatedHPA.
func GetCronFederatedHPASuccessHistoryLimits(rule autoscalingv1alpha1.CronFederatedHPARule) int {
if rule.SuccessfulHistoryLimit == nil {
return 3
return DefaultHistoryLimit
}
return int(*rule.SuccessfulHistoryLimit)
}

// GetCronFederatedHPAFailedHistoryLimits returns the failed history limits of the CronFederatedHPA.
func GetCronFederatedHPAFailedHistoryLimits(rule autoscalingv1alpha1.CronFederatedHPARule) int {
if rule.FailedHistoryLimit == nil {
return 3
return DefaultHistoryLimit
}
return int(*rule.FailedHistoryLimit)
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/util/helper/cronfederatedhpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@ func TestGetCronFederatedHPASuccessHistoryLimits(t *testing.T) {
expected int
}{
{
name: "successful history limit is nil",
name: "returns default limit when history limit is unspecified",
rule: autoscalingv1alpha1.CronFederatedHPARule{},
expected: 3,
expected: DefaultHistoryLimit,
},
{
name: "successful history limit is set to 5",
name: "returns custom limit when specified",
rule: autoscalingv1alpha1.CronFederatedHPARule{
SuccessfulHistoryLimit: ptr.To[int32](5),
},
expected: 5,
},
{
name: "successful history limit is set to 0",
name: "returns zero when limit is explicitly set to zero",
rule: autoscalingv1alpha1.CronFederatedHPARule{
SuccessfulHistoryLimit: ptr.To[int32](0),
},
Expand All @@ -103,19 +103,19 @@ func TestGetCronFederatedHPAFailedHistoryLimits(t *testing.T) {
expected int
}{
{
name: "failed history limit is nil",
name: "returns default limit when history limit is unspecified",
rule: autoscalingv1alpha1.CronFederatedHPARule{},
expected: 3,
expected: DefaultHistoryLimit,
},
{
name: "failed history limit is set to 5",
name: "returns custom limit when specified",
rule: autoscalingv1alpha1.CronFederatedHPARule{
FailedHistoryLimit: ptr.To[int32](5),
},
expected: 5,
},
{
name: "failed history limit is set to 0",
name: "returns zero when limit is explicitly set to zero",
rule: autoscalingv1alpha1.CronFederatedHPARule{
FailedHistoryLimit: ptr.To[int32](0),
},
Expand Down

0 comments on commit 3323935

Please sign in to comment.