mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 21:17:23 +00:00
Merge pull request #129323 from ardaguclu/automated-cherry-pick-of-#129301-upstream-release-1.31
Automated cherry pick of #129301: Do not attempt to truncate revision history if revisionHistoryLimit is negative
This commit is contained in:
commit
6f456a1908
@ -194,7 +194,7 @@ func (ssc *defaultStatefulSetControl) truncateHistory(
|
|||||||
}
|
}
|
||||||
historyLen := len(history)
|
historyLen := len(history)
|
||||||
historyLimit := int(*set.Spec.RevisionHistoryLimit)
|
historyLimit := int(*set.Spec.RevisionHistoryLimit)
|
||||||
if historyLen <= historyLimit {
|
if historyLimit < 0 || historyLen <= historyLimit {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// delete any non-live history to maintain the revision limit.
|
// delete any non-live history to maintain the revision limit.
|
||||||
|
@ -52,6 +52,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/controller"
|
"k8s.io/kubernetes/pkg/controller"
|
||||||
"k8s.io/kubernetes/pkg/controller/history"
|
"k8s.io/kubernetes/pkg/controller/history"
|
||||||
"k8s.io/kubernetes/pkg/features"
|
"k8s.io/kubernetes/pkg/features"
|
||||||
|
"k8s.io/utils/ptr"
|
||||||
)
|
)
|
||||||
|
|
||||||
type invariantFunc func(set *apps.StatefulSet, om *fakeObjectManager) error
|
type invariantFunc func(set *apps.StatefulSet, om *fakeObjectManager) error
|
||||||
@ -2009,6 +2010,13 @@ func TestStatefulSetControlLimitsHistory(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%s: %s", test.name, err)
|
t.Fatalf("%s: %s", test.name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *set.Spec.RevisionHistoryLimit < 0 {
|
||||||
|
// If the revisionHistoryLimit is negative value, we don't truncate
|
||||||
|
// the revision history and it is incremental.
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if len(revisions) > int(*set.Spec.RevisionHistoryLimit)+2 {
|
if len(revisions) > int(*set.Spec.RevisionHistoryLimit)+2 {
|
||||||
t.Fatalf("%s: %d greater than limit %d", test.name, len(revisions), *set.Spec.RevisionHistoryLimit)
|
t.Fatalf("%s: %d greater than limit %d", test.name, len(revisions), *set.Spec.RevisionHistoryLimit)
|
||||||
}
|
}
|
||||||
@ -2030,6 +2038,33 @@ func TestStatefulSetControlLimitsHistory(t *testing.T) {
|
|||||||
return burst(newStatefulSet(3))
|
return burst(newStatefulSet(3))
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "zero revisionHistoryLimit",
|
||||||
|
invariants: assertMonotonicInvariants,
|
||||||
|
initial: func() *apps.StatefulSet {
|
||||||
|
sts := newStatefulSet(3)
|
||||||
|
sts.Spec.RevisionHistoryLimit = ptr.To(int32(0))
|
||||||
|
return sts
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "negative revisionHistoryLimit",
|
||||||
|
invariants: assertMonotonicInvariants,
|
||||||
|
initial: func() *apps.StatefulSet {
|
||||||
|
sts := newStatefulSet(3)
|
||||||
|
sts.Spec.RevisionHistoryLimit = ptr.To(int32(-2))
|
||||||
|
return sts
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "positive revisionHistoryLimit",
|
||||||
|
invariants: assertMonotonicInvariants,
|
||||||
|
initial: func() *apps.StatefulSet {
|
||||||
|
sts := newStatefulSet(3)
|
||||||
|
sts.Spec.RevisionHistoryLimit = ptr.To(int32(5))
|
||||||
|
return sts
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for i := range tests {
|
for i := range tests {
|
||||||
testFn(t, &tests[i])
|
testFn(t, &tests[i])
|
||||||
|
Loading…
Reference in New Issue
Block a user