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

refactor: introduce DefaultHistoryLimit constant for CronFederatedHPA #5903

Merged
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
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