Skip to content

Commit a4b8a3b

Browse files
authored
Merge pull request kubernetes#129301 from ardaguclu/sts-revisionhistorylimit-negative
Do not attempt to truncate revision history if revisionHistoryLimit is negative
2 parents 4e4ea1b + a88e08c commit a4b8a3b

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

pkg/controller/statefulset/stateful_set_control.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func (ssc *defaultStatefulSetControl) truncateHistory(
194194
}
195195
historyLen := len(history)
196196
historyLimit := int(*set.Spec.RevisionHistoryLimit)
197-
if historyLen <= historyLimit {
197+
if historyLimit < 0 || historyLen <= historyLimit {
198198
return nil
199199
}
200200
// delete any non-live history to maintain the revision limit.

pkg/controller/statefulset/stateful_set_control_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import (
5353
"k8s.io/kubernetes/pkg/controller"
5454
"k8s.io/kubernetes/pkg/controller/history"
5555
"k8s.io/kubernetes/pkg/features"
56+
"k8s.io/utils/ptr"
5657
)
5758

5859
type invariantFunc func(set *apps.StatefulSet, om *fakeObjectManager) error
@@ -2031,6 +2032,13 @@ func TestStatefulSetControlLimitsHistory(t *testing.T) {
20312032
if err != nil {
20322033
t.Fatalf("%s: %s", test.name, err)
20332034
}
2035+
2036+
if *set.Spec.RevisionHistoryLimit < 0 {
2037+
// If the revisionHistoryLimit is negative value, we don't truncate
2038+
// the revision history and it is incremental.
2039+
continue
2040+
}
2041+
20342042
if len(revisions) > int(*set.Spec.RevisionHistoryLimit)+2 {
20352043
t.Fatalf("%s: %d greater than limit %d", test.name, len(revisions), *set.Spec.RevisionHistoryLimit)
20362044
}
@@ -2052,6 +2060,33 @@ func TestStatefulSetControlLimitsHistory(t *testing.T) {
20522060
return burst(newStatefulSet(3))
20532061
},
20542062
},
2063+
{
2064+
name: "zero revisionHistoryLimit",
2065+
invariants: assertMonotonicInvariants,
2066+
initial: func() *apps.StatefulSet {
2067+
sts := newStatefulSet(3)
2068+
sts.Spec.RevisionHistoryLimit = ptr.To(int32(0))
2069+
return sts
2070+
},
2071+
},
2072+
{
2073+
name: "negative revisionHistoryLimit",
2074+
invariants: assertMonotonicInvariants,
2075+
initial: func() *apps.StatefulSet {
2076+
sts := newStatefulSet(3)
2077+
sts.Spec.RevisionHistoryLimit = ptr.To(int32(-2))
2078+
return sts
2079+
},
2080+
},
2081+
{
2082+
name: "positive revisionHistoryLimit",
2083+
invariants: assertMonotonicInvariants,
2084+
initial: func() *apps.StatefulSet {
2085+
sts := newStatefulSet(3)
2086+
sts.Spec.RevisionHistoryLimit = ptr.To(int32(5))
2087+
return sts
2088+
},
2089+
},
20552090
}
20562091
for i := range tests {
20572092
testFn(t, &tests[i])

0 commit comments

Comments
 (0)