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

Default extensions/v1beta1 Deployment's RevisionHistoryLimit to MaxInt32 #66605

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/openapi-spec/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/swagger-spec/extensions_v1beta1.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/api-reference/extensions/v1beta1/definitions.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/apis/extensions/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ type DeploymentSpec struct {

// The number of old ReplicaSets to retain to allow rollback.
// This is a pointer to distinguish between explicit zero and not specified.
// This is set to the max value of int32 (i.e. 2147483647) by default, which means
// "retaining all old ReplicaSets".
// +optional
RevisionHistoryLimit *int32

Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/extensions/v1beta1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ func SetDefaults_Deployment(obj *extensionsv1beta1.Deployment) {
obj.Spec.ProgressDeadlineSeconds = new(int32)
*obj.Spec.ProgressDeadlineSeconds = math.MaxInt32
}
// Set extensionsv1beta1.DeploymentSpec.RevisionHistoryLimit to MaxInt32,
// which has the same meaning as unset.
if obj.Spec.RevisionHistoryLimit == nil {
obj.Spec.RevisionHistoryLimit = new(int32)
*obj.Spec.RevisionHistoryLimit = math.MaxInt32
}
}

func SetDefaults_ReplicaSet(obj *extensionsv1beta1.ReplicaSet) {
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/extensions/v1beta1/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ func TestSetDefaultDeployment(t *testing.T) {
},
Template: defaultTemplate,
ProgressDeadlineSeconds: utilpointer.Int32Ptr(math.MaxInt32),
RevisionHistoryLimit: utilpointer.Int32Ptr(math.MaxInt32),
},
},
},
Expand All @@ -217,6 +218,7 @@ func TestSetDefaultDeployment(t *testing.T) {
},
Template: defaultTemplate,
ProgressDeadlineSeconds: utilpointer.Int32Ptr(math.MaxInt32),
RevisionHistoryLimit: utilpointer.Int32Ptr(math.MaxInt32),
},
},
},
Expand All @@ -242,6 +244,7 @@ func TestSetDefaultDeployment(t *testing.T) {
},
Template: defaultTemplate,
ProgressDeadlineSeconds: utilpointer.Int32Ptr(math.MaxInt32),
RevisionHistoryLimit: utilpointer.Int32Ptr(math.MaxInt32),
},
},
},
Expand All @@ -262,6 +265,7 @@ func TestSetDefaultDeployment(t *testing.T) {
},
Template: defaultTemplate,
ProgressDeadlineSeconds: utilpointer.Int32Ptr(math.MaxInt32),
RevisionHistoryLimit: utilpointer.Int32Ptr(math.MaxInt32),
},
},
},
Expand All @@ -283,6 +287,7 @@ func TestSetDefaultDeployment(t *testing.T) {
},
Template: defaultTemplate,
ProgressDeadlineSeconds: utilpointer.Int32Ptr(30),
RevisionHistoryLimit: utilpointer.Int32Ptr(math.MaxInt32),
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/deployment/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ func (dc *DeploymentController) scaleReplicaSet(rs *apps.ReplicaSet, newScale in
// where N=d.Spec.RevisionHistoryLimit. Old replica sets are older versions of the podtemplate of a deployment kept
// around by default 1) for historical reasons and 2) for the ability to rollback a deployment.
func (dc *DeploymentController) cleanupDeployment(oldRSs []*apps.ReplicaSet, deployment *apps.Deployment) error {
if deployment.Spec.RevisionHistoryLimit == nil {
if !deploymentutil.HasRevisionHistoryLimit(deployment) {
return nil
}

Expand Down
12 changes: 12 additions & 0 deletions pkg/controller/deployment/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package deployment

import (
"math"
"testing"
"time"

Expand Down Expand Up @@ -393,6 +394,16 @@ func TestDeploymentController_cleanupDeployment(t *testing.T) {
revisionHistoryLimit: 0,
expectedDeletions: 0,
},
{
// with unlimited revisionHistoryLimit
oldRSs: []*apps.ReplicaSet{
newRSWithStatus("foo-1", 0, 0, selector),
newRSWithStatus("foo-2", 0, 0, selector),
newRSWithStatus("foo-3", 0, 0, selector),
},
revisionHistoryLimit: math.MaxInt32,
expectedDeletions: 0,
},
}

for i := range tests {
Expand All @@ -418,6 +429,7 @@ func TestDeploymentController_cleanupDeployment(t *testing.T) {
defer close(stopCh)
informers.Start(stopCh)

t.Logf(" &test.revisionHistoryLimit: %d", test.revisionHistoryLimit)
d := newDeployment("foo", 1, &test.revisionHistoryLimit, nil, nil, map[string]string{"foo": "bar"})
controller.cleanupDeployment(test.oldRSs, d)

Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/deployment/util/deployment_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,3 +886,6 @@ func ResolveFenceposts(maxSurge, maxUnavailable *intstrutil.IntOrString, desired
func HasProgressDeadline(d *apps.Deployment) bool {
return d.Spec.ProgressDeadlineSeconds != nil && *d.Spec.ProgressDeadlineSeconds != math.MaxInt32
}
func HasRevisionHistoryLimit(d *apps.Deployment) bool {
return d.Spec.RevisionHistoryLimit != nil && *d.Spec.RevisionHistoryLimit != math.MaxInt32
}
2 changes: 2 additions & 0 deletions staging/src/k8s.io/api/extensions/v1beta1/generated.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions staging/src/k8s.io/api/extensions/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ type DeploymentSpec struct {

// The number of old ReplicaSets to retain to allow rollback.
// This is a pointer to distinguish between explicit zero and not specified.
// This is set to the max value of int32 (i.e. 2147483647) by default, which
// means "retaining all old RelicaSets".
// +optional
RevisionHistoryLimit *int32 `json:"revisionHistoryLimit,omitempty" protobuf:"varint,6,opt,name=revisionHistoryLimit"`

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.