Merge pull request #5903 from anujagrawal699/fix/default-history-limit-constant
refactor: introduce DefaultHistoryLimit constant for CronFederatedHPA
This commit is contained in:
commit
3323935575
|
@ -22,6 +22,9 @@ import (
|
||||||
autoscalingv1alpha1 "github.com/karmada-io/karmada/pkg/apis/autoscaling/v1alpha1"
|
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.
|
// IsCronFederatedHPARuleSuspend returns true if the CronFederatedHPA is suspended.
|
||||||
func IsCronFederatedHPARuleSuspend(rule autoscalingv1alpha1.CronFederatedHPARule) bool {
|
func IsCronFederatedHPARuleSuspend(rule autoscalingv1alpha1.CronFederatedHPARule) bool {
|
||||||
if rule.Suspend == nil {
|
if rule.Suspend == nil {
|
||||||
|
@ -33,7 +36,7 @@ func IsCronFederatedHPARuleSuspend(rule autoscalingv1alpha1.CronFederatedHPARule
|
||||||
// GetCronFederatedHPASuccessHistoryLimits returns the successful history limits of the CronFederatedHPA.
|
// GetCronFederatedHPASuccessHistoryLimits returns the successful history limits of the CronFederatedHPA.
|
||||||
func GetCronFederatedHPASuccessHistoryLimits(rule autoscalingv1alpha1.CronFederatedHPARule) int {
|
func GetCronFederatedHPASuccessHistoryLimits(rule autoscalingv1alpha1.CronFederatedHPARule) int {
|
||||||
if rule.SuccessfulHistoryLimit == nil {
|
if rule.SuccessfulHistoryLimit == nil {
|
||||||
return 3
|
return DefaultHistoryLimit
|
||||||
}
|
}
|
||||||
return int(*rule.SuccessfulHistoryLimit)
|
return int(*rule.SuccessfulHistoryLimit)
|
||||||
}
|
}
|
||||||
|
@ -41,7 +44,7 @@ func GetCronFederatedHPASuccessHistoryLimits(rule autoscalingv1alpha1.CronFedera
|
||||||
// GetCronFederatedHPAFailedHistoryLimits returns the failed history limits of the CronFederatedHPA.
|
// GetCronFederatedHPAFailedHistoryLimits returns the failed history limits of the CronFederatedHPA.
|
||||||
func GetCronFederatedHPAFailedHistoryLimits(rule autoscalingv1alpha1.CronFederatedHPARule) int {
|
func GetCronFederatedHPAFailedHistoryLimits(rule autoscalingv1alpha1.CronFederatedHPARule) int {
|
||||||
if rule.FailedHistoryLimit == nil {
|
if rule.FailedHistoryLimit == nil {
|
||||||
return 3
|
return DefaultHistoryLimit
|
||||||
}
|
}
|
||||||
return int(*rule.FailedHistoryLimit)
|
return int(*rule.FailedHistoryLimit)
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,19 +68,19 @@ func TestGetCronFederatedHPASuccessHistoryLimits(t *testing.T) {
|
||||||
expected int
|
expected int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "successful history limit is nil",
|
name: "returns default limit when history limit is unspecified",
|
||||||
rule: autoscalingv1alpha1.CronFederatedHPARule{},
|
rule: autoscalingv1alpha1.CronFederatedHPARule{},
|
||||||
expected: 3,
|
expected: DefaultHistoryLimit,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "successful history limit is set to 5",
|
name: "returns custom limit when specified",
|
||||||
rule: autoscalingv1alpha1.CronFederatedHPARule{
|
rule: autoscalingv1alpha1.CronFederatedHPARule{
|
||||||
SuccessfulHistoryLimit: ptr.To[int32](5),
|
SuccessfulHistoryLimit: ptr.To[int32](5),
|
||||||
},
|
},
|
||||||
expected: 5,
|
expected: 5,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "successful history limit is set to 0",
|
name: "returns zero when limit is explicitly set to zero",
|
||||||
rule: autoscalingv1alpha1.CronFederatedHPARule{
|
rule: autoscalingv1alpha1.CronFederatedHPARule{
|
||||||
SuccessfulHistoryLimit: ptr.To[int32](0),
|
SuccessfulHistoryLimit: ptr.To[int32](0),
|
||||||
},
|
},
|
||||||
|
@ -103,19 +103,19 @@ func TestGetCronFederatedHPAFailedHistoryLimits(t *testing.T) {
|
||||||
expected int
|
expected int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "failed history limit is nil",
|
name: "returns default limit when history limit is unspecified",
|
||||||
rule: autoscalingv1alpha1.CronFederatedHPARule{},
|
rule: autoscalingv1alpha1.CronFederatedHPARule{},
|
||||||
expected: 3,
|
expected: DefaultHistoryLimit,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "failed history limit is set to 5",
|
name: "returns custom limit when specified",
|
||||||
rule: autoscalingv1alpha1.CronFederatedHPARule{
|
rule: autoscalingv1alpha1.CronFederatedHPARule{
|
||||||
FailedHistoryLimit: ptr.To[int32](5),
|
FailedHistoryLimit: ptr.To[int32](5),
|
||||||
},
|
},
|
||||||
expected: 5,
|
expected: 5,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "failed history limit is set to 0",
|
name: "returns zero when limit is explicitly set to zero",
|
||||||
rule: autoscalingv1alpha1.CronFederatedHPARule{
|
rule: autoscalingv1alpha1.CronFederatedHPARule{
|
||||||
FailedHistoryLimit: ptr.To[int32](0),
|
FailedHistoryLimit: ptr.To[int32](0),
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue