Skip to content

Commit a78eaf1

Browse files
committed
Set default for DeploymentConfigSpec.RevisionHistoryLimit in apps/v1 to 10
1 parent 490f9e1 commit a78eaf1

File tree

13 files changed

+165
-31
lines changed

13 files changed

+165
-31
lines changed

api/protobuf-spec/github_com_openshift_origin_pkg_deploy_apis_apps_v1.proto

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/swagger-spec/oapi-v1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26392,7 +26392,7 @@
2639226392
"revisionHistoryLimit": {
2639326393
"type": "integer",
2639426394
"format": "int32",
26395-
"description": "RevisionHistoryLimit is the number of old ReplicationControllers to retain to allow for rollbacks. This field is a pointer to allow for differentiation between an explicit zero and not specified."
26395+
"description": "RevisionHistoryLimit is the number of old ReplicationControllers to retain to allow for rollbacks. This field is a pointer to allow for differentiation between an explicit zero and not specified. Defaults to 10. (This only applies to DeploymentConfigs created via the new group api resource, not the legacy resource.)"
2639626396
},
2639726397
"test": {
2639826398
"type": "boolean",

api/swagger-spec/openshift-openapi-spec.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96022,7 +96022,7 @@
9602296022
"format": "int32"
9602396023
},
9602496024
"revisionHistoryLimit": {
96025-
"description": "RevisionHistoryLimit is the number of old ReplicationControllers to retain to allow for rollbacks. This field is a pointer to allow for differentiation between an explicit zero and not specified.",
96025+
"description": "RevisionHistoryLimit is the number of old ReplicationControllers to retain to allow for rollbacks. This field is a pointer to allow for differentiation between an explicit zero and not specified. Defaults to 10. (This only applies to DeploymentConfigs created via the new group API resource, not the legacy resource.)",
9602696026
"type": "integer",
9602796027
"format": "int32"
9602896028
},

pkg/cmd/server/origin/legacy.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
buildconfig "github.com/openshift/origin/pkg/build/registry/buildconfig"
99
buildconfigetcd "github.com/openshift/origin/pkg/build/registry/buildconfig/etcd"
10+
"github.com/openshift/origin/pkg/deploy/registry/deployconfig"
1011
deploymentconfigetcd "github.com/openshift/origin/pkg/deploy/registry/deployconfig/etcd"
1112
routeregistry "github.com/openshift/origin/pkg/route/registry/route"
1213
routeetcd "github.com/openshift/origin/pkg/route/registry/route/etcd"
@@ -206,7 +207,8 @@ func LegacyStorage(storage map[schema.GroupVersion]map[string]rest.Storage) map[
206207
case "deploymentConfigs":
207208
restStorage := s.(*deploymentconfigetcd.REST)
208209
store := *restStorage.Store
209-
restStorage.DeleteStrategy = orphanByDefault(store.DeleteStrategy)
210+
store.CreateStrategy = deployconfig.LegacyStrategy
211+
store.DeleteStrategy = deployconfig.LegacyStrategy
210212
legacyStorage[resource] = &deploymentconfigetcd.REST{Store: &store}
211213
case "routes":
212214
restStorage := s.(*routeetcd.REST)
@@ -223,15 +225,3 @@ func LegacyStorage(storage map[schema.GroupVersion]map[string]rest.Storage) map[
223225
}
224226
return legacyStorage
225227
}
226-
227-
type orphaningDeleter struct {
228-
rest.RESTDeleteStrategy
229-
}
230-
231-
func (o orphaningDeleter) DefaultGarbageCollectionPolicy() rest.GarbageCollectionPolicy {
232-
return rest.OrphanDependents
233-
}
234-
235-
func orphanByDefault(in rest.RESTDeleteStrategy) rest.RESTDeleteStrategy {
236-
return orphaningDeleter{in}
237-
}

pkg/deploy/apis/apps/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ const (
2020
// This is set as the default value for ActiveDeadlineSeconds for the deployer pod.
2121
// Currently set to 6 hours.
2222
MaxDeploymentDurationSeconds int64 = 21600
23+
// DefaultRevisionHistoryLimit is the number of old ReplicationControllers to retain to allow for rollbacks.
24+
// This only applies to DeploymentConfigs created via the new group API resource, not the legacy resource.
25+
DefaultRevisionHistoryLimit int32 = 10
2326
)
2427

2528
// These constants represent keys used for correlating objects related to deployments.
@@ -156,6 +159,7 @@ type DeploymentConfigSpec struct {
156159

157160
// RevisionHistoryLimit is the number of old ReplicationControllers to retain to allow for rollbacks.
158161
// This field is a pointer to allow for differentiation between an explicit zero and not specified.
162+
// Defaults to 10. (This only applies to DeploymentConfigs created via the new group API resource, not the legacy resource.)
159163
RevisionHistoryLimit *int32
160164

161165
// Test ensures that this deployment config will have zero replicas except while a deployment is running. This allows the

pkg/deploy/apis/apps/v1/generated.proto

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/deploy/apis/apps/v1/swagger_doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ var map_DeploymentConfigSpec = map[string]string{
101101
"minReadySeconds": "MinReadySeconds is the minimum number of seconds for which a newly created pod should be ready without any of its container crashing, for it to be considered available. Defaults to 0 (pod will be considered available as soon as it is ready)",
102102
"triggers": "Triggers determine how updates to a DeploymentConfig result in new deployments. If no triggers are defined, a new deployment can only occur as a result of an explicit client update to the DeploymentConfig with a new LatestVersion. If null, defaults to having a config change trigger.",
103103
"replicas": "Replicas is the number of desired replicas.",
104-
"revisionHistoryLimit": "RevisionHistoryLimit is the number of old ReplicationControllers to retain to allow for rollbacks. This field is a pointer to allow for differentiation between an explicit zero and not specified.",
104+
"revisionHistoryLimit": "RevisionHistoryLimit is the number of old ReplicationControllers to retain to allow for rollbacks. This field is a pointer to allow for differentiation between an explicit zero and not specified. Defaults to 10. (This only applies to DeploymentConfigs created via the new group API resource, not the legacy resource.)",
105105
"test": "Test ensures that this deployment config will have zero replicas except while a deployment is running. This allows the deployment config to be used as a continuous deployment test - triggering on images, running the deployment, and then succeeding or failing. Post strategy hooks and After actions can be used to integrate successful deployment with an action.",
106106
"paused": "Paused indicates that the deployment config is paused resulting in no new deployments on template changes or changes in the template caused by other triggers.",
107107
"selector": "Selector is a label query over pods that should match the Replicas count.",

pkg/deploy/apis/apps/v1/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type DeploymentConfigSpec struct {
5151

5252
// RevisionHistoryLimit is the number of old ReplicationControllers to retain to allow for rollbacks.
5353
// This field is a pointer to allow for differentiation between an explicit zero and not specified.
54+
// Defaults to 10. (This only applies to DeploymentConfigs created via the new group API resource, not the legacy resource.)
5455
RevisionHistoryLimit *int32 `json:"revisionHistoryLimit,omitempty" protobuf:"varint,4,opt,name=revisionHistoryLimit"`
5556

5657
// Test ensures that this deployment config will have zero replicas except while a deployment is running. This allows the

pkg/deploy/registry/deployconfig/etcd/etcd.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ func NewREST(optsGetter restoptions.Getter) (*REST, *StatusREST, *ScaleREST, err
3737
PredicateFunc: deployconfig.Matcher,
3838
QualifiedResource: deployapi.Resource("deploymentconfigs"),
3939

40-
CreateStrategy: deployconfig.Strategy,
41-
UpdateStrategy: deployconfig.Strategy,
42-
DeleteStrategy: deployconfig.Strategy,
40+
CreateStrategy: deployconfig.GroupStrategy,
41+
UpdateStrategy: deployconfig.GroupStrategy,
42+
DeleteStrategy: deployconfig.GroupStrategy,
4343
}
4444

4545
options := &generic.StoreOptions{RESTOptions: optsGetter, AttrFunc: deployconfig.GetAttrs}

pkg/deploy/registry/deployconfig/strategy.go

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"k8s.io/apimachinery/pkg/runtime"
1111
"k8s.io/apimachinery/pkg/util/validation/field"
1212
apirequest "k8s.io/apiserver/pkg/endpoints/request"
13+
"k8s.io/apiserver/pkg/registry/rest"
1314
kstorage "k8s.io/apiserver/pkg/storage"
1415
"k8s.io/apiserver/pkg/storage/names"
1516
kapi "k8s.io/kubernetes/pkg/api"
@@ -24,8 +25,16 @@ type strategy struct {
2425
names.NameGenerator
2526
}
2627

27-
// Strategy is the default logic that applies when creating and updating DeploymentConfig objects.
28-
var Strategy = strategy{kapi.Scheme, names.SimpleNameGenerator}
28+
// CommonStrategy is the default logic that applies when creating and updating DeploymentConfig objects.
29+
var CommonStrategy = strategy{kapi.Scheme, names.SimpleNameGenerator}
30+
31+
// LegacyStrategy is the logic that applies when creating and updating DeploymentConfig objects in the legacy API.
32+
// An example would be setting different defaults depending on API group
33+
var LegacyStrategy = legacyStrategy{CommonStrategy}
34+
35+
// GroupStrategy is the logic that applies when creating and updating DeploymentConfig objects in the group API.
36+
// An example would be setting different defaults depending on API group
37+
var GroupStrategy = groupStrategy{CommonStrategy}
2938

3039
// NamespaceScoped is true for DeploymentConfig objects.
3140
func (strategy) NamespaceScoped() bool {
@@ -105,12 +114,44 @@ func (strategy) CheckGracefulDelete(obj runtime.Object, options *metav1.DeleteOp
105114
return false
106115
}
107116

117+
// legacyStrategy implements behavior for DeploymentConfig objects in the legacy API
118+
type legacyStrategy struct {
119+
strategy
120+
}
121+
122+
// PrepareForCreate delegates to the common strategy.
123+
func (s legacyStrategy) PrepareForCreate(ctx apirequest.Context, obj runtime.Object) {
124+
s.strategy.PrepareForCreate(ctx, obj)
125+
}
126+
127+
// DefaultGarbageCollectionPolicy for legacy DeploymentConfigs will orphan dependents.
128+
func (s legacyStrategy) DefaultGarbageCollectionPolicy() rest.GarbageCollectionPolicy {
129+
return rest.OrphanDependents
130+
}
131+
132+
// groupStrategy implements behavior for DeploymentConfig objects in the Group API
133+
type groupStrategy struct {
134+
strategy
135+
}
136+
137+
// PrepareForCreate delegates to the common strategy and sets defaults applicable only to Group API
138+
func (s groupStrategy) PrepareForCreate(ctx apirequest.Context, obj runtime.Object) {
139+
s.strategy.PrepareForCreate(ctx, obj)
140+
141+
dc := obj.(*deployapi.DeploymentConfig)
142+
143+
if dc.Spec.RevisionHistoryLimit == nil {
144+
v := deployapi.DefaultRevisionHistoryLimit
145+
dc.Spec.RevisionHistoryLimit = &v
146+
}
147+
}
148+
108149
// statusStrategy implements behavior for DeploymentConfig status updates.
109150
type statusStrategy struct {
110151
strategy
111152
}
112153

113-
var StatusStrategy = statusStrategy{Strategy}
154+
var StatusStrategy = statusStrategy{CommonStrategy}
114155

115156
// PrepareForUpdate clears fields that are not allowed to be set by end users on update of status.
116157
func (statusStrategy) PrepareForUpdate(ctx apirequest.Context, obj, old runtime.Object) {

pkg/deploy/registry/deployconfig/strategy_test.go

Lines changed: 103 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,56 @@ import (
66

77
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
88
"k8s.io/apimachinery/pkg/runtime"
9+
"k8s.io/apimachinery/pkg/util/diff"
910
apirequest "k8s.io/apiserver/pkg/endpoints/request"
11+
"k8s.io/apiserver/pkg/registry/rest"
1012

1113
deployapi "github.com/openshift/origin/pkg/deploy/apis/apps"
1214
deploytest "github.com/openshift/origin/pkg/deploy/apis/apps/test"
1315
)
1416

17+
var (
18+
nonDefaultRevisionHistoryLimit = deployapi.DefaultRevisionHistoryLimit + 42
19+
)
20+
21+
func int32ptr(v int32) *int32 {
22+
return &v
23+
}
24+
1525
func TestDeploymentConfigStrategy(t *testing.T) {
1626
ctx := apirequest.NewDefaultContext()
17-
if !Strategy.NamespaceScoped() {
27+
if !CommonStrategy.NamespaceScoped() {
1828
t.Errorf("DeploymentConfig is namespace scoped")
1929
}
20-
if Strategy.AllowCreateOnUpdate() {
30+
if CommonStrategy.AllowCreateOnUpdate() {
2131
t.Errorf("DeploymentConfig should not allow create on update")
2232
}
2333
deploymentConfig := &deployapi.DeploymentConfig{
2434
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"},
2535
Spec: deploytest.OkDeploymentConfigSpec(),
2636
}
27-
Strategy.PrepareForCreate(ctx, deploymentConfig)
28-
errs := Strategy.Validate(ctx, deploymentConfig)
37+
CommonStrategy.PrepareForCreate(ctx, deploymentConfig)
38+
errs := CommonStrategy.Validate(ctx, deploymentConfig)
2939
if len(errs) != 0 {
3040
t.Errorf("Unexpected error validating %v", errs)
3141
}
3242
updatedDeploymentConfig := &deployapi.DeploymentConfig{
3343
ObjectMeta: metav1.ObjectMeta{Name: "bar", Namespace: "default", Generation: 1},
3444
Spec: deploytest.OkDeploymentConfigSpec(),
3545
}
36-
errs = Strategy.ValidateUpdate(ctx, updatedDeploymentConfig, deploymentConfig)
46+
errs = CommonStrategy.ValidateUpdate(ctx, updatedDeploymentConfig, deploymentConfig)
3747
if len(errs) == 0 {
3848
t.Errorf("Expected error validating")
3949
}
4050
// name must match, and resource version must be provided
4151
updatedDeploymentConfig.Name = "foo"
4252
updatedDeploymentConfig.ResourceVersion = "1"
43-
errs = Strategy.ValidateUpdate(ctx, updatedDeploymentConfig, deploymentConfig)
53+
errs = CommonStrategy.ValidateUpdate(ctx, updatedDeploymentConfig, deploymentConfig)
4454
if len(errs) != 0 {
4555
t.Errorf("Unexpected error validating %v", errs)
4656
}
4757
invalidDeploymentConfig := &deployapi.DeploymentConfig{}
48-
errs = Strategy.Validate(ctx, invalidDeploymentConfig)
58+
errs = CommonStrategy.Validate(ctx, invalidDeploymentConfig)
4959
if len(errs) == 0 {
5060
t.Errorf("Expected error validating")
5161
}
@@ -119,3 +129,89 @@ func expectedAfterVersionBump() *deployapi.DeploymentConfig {
119129
dc.Generation++
120130
return dc
121131
}
132+
133+
func setRevisionHistoryLimit(v *int32, dc *deployapi.DeploymentConfig) *deployapi.DeploymentConfig {
134+
dc.Spec.RevisionHistoryLimit = v
135+
return dc
136+
}
137+
138+
func okDeploymentConfig(generation int64) *deployapi.DeploymentConfig {
139+
dc := deploytest.OkDeploymentConfig(0)
140+
dc.ObjectMeta.Generation = generation
141+
return dc
142+
}
143+
144+
func TestLegacyStrategy_PrepareForCreate(t *testing.T) {
145+
nonDefaultRevisionHistoryLimit := deployapi.DefaultRevisionHistoryLimit + 42
146+
tt := []struct {
147+
obj *deployapi.DeploymentConfig
148+
expected *deployapi.DeploymentConfig
149+
}{
150+
{
151+
obj: setRevisionHistoryLimit(nil, okDeploymentConfig(0)),
152+
// Legacy API shall not default RevisionHistoryLimit to maintain backwards compatibility
153+
expected: setRevisionHistoryLimit(nil, okDeploymentConfig(1)),
154+
},
155+
{
156+
obj: setRevisionHistoryLimit(&nonDefaultRevisionHistoryLimit, okDeploymentConfig(0)),
157+
expected: setRevisionHistoryLimit(&nonDefaultRevisionHistoryLimit, okDeploymentConfig(1)),
158+
},
159+
}
160+
161+
ctx := apirequest.NewDefaultContext()
162+
163+
for _, tc := range tt {
164+
t.Run("", func(t *testing.T) {
165+
LegacyStrategy.PrepareForCreate(ctx, tc.obj)
166+
if !reflect.DeepEqual(tc.obj, tc.expected) {
167+
t.Fatalf("LegacyStrategy.PrepareForCreate failed:%s", diff.ObjectReflectDiff(tc.obj, tc.expected))
168+
}
169+
170+
errs := LegacyStrategy.Validate(ctx, tc.obj)
171+
if len(errs) != 0 {
172+
t.Errorf("Unexpected error validating DeploymentConfig: %v", errs)
173+
}
174+
})
175+
}
176+
}
177+
178+
func TestLegacyStrategy_DefaultGarbageCollectionPolicy(t *testing.T) {
179+
expected := rest.OrphanDependents
180+
got := LegacyStrategy.DefaultGarbageCollectionPolicy()
181+
if got != expected {
182+
t.Fatalf("Default garbage collection policy for DeploymentConfigs should be %q (not %q)", expected, got)
183+
}
184+
}
185+
186+
func TestGroupStrategy_PrepareForCreate(t *testing.T) {
187+
tt := []struct {
188+
obj *deployapi.DeploymentConfig
189+
expected *deployapi.DeploymentConfig
190+
}{
191+
{
192+
obj: setRevisionHistoryLimit(nil, okDeploymentConfig(0)),
193+
// Group API should default RevisionHistoryLimit
194+
expected: setRevisionHistoryLimit(int32ptr(deployapi.DefaultRevisionHistoryLimit), okDeploymentConfig(1)),
195+
},
196+
{
197+
obj: setRevisionHistoryLimit(&nonDefaultRevisionHistoryLimit, okDeploymentConfig(0)),
198+
expected: setRevisionHistoryLimit(&nonDefaultRevisionHistoryLimit, okDeploymentConfig(1)),
199+
},
200+
}
201+
202+
ctx := apirequest.NewDefaultContext()
203+
204+
for _, tc := range tt {
205+
t.Run("", func(t *testing.T) {
206+
GroupStrategy.PrepareForCreate(ctx, tc.obj)
207+
if !reflect.DeepEqual(tc.obj, tc.expected) {
208+
t.Fatalf("GroupStrategy.PrepareForCreate failed:%s", diff.ObjectReflectDiff(tc.obj, tc.expected))
209+
}
210+
211+
errs := GroupStrategy.Validate(ctx, tc.obj)
212+
if len(errs) != 0 {
213+
t.Errorf("Unexpected error validating DeploymentConfig: %v", errs)
214+
}
215+
})
216+
}
217+
}

pkg/oc/cli/cmd/exporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func (e *DefaultExporter) Export(obj runtime.Object, exact bool) error {
146146
t.Secrets = newMountableSecrets
147147

148148
case *deployapi.DeploymentConfig:
149-
return deployrest.Strategy.Export(ctx, obj, exact)
149+
return deployrest.CommonStrategy.Export(ctx, obj, exact)
150150

151151
case *buildapi.BuildConfig:
152152
// Use the legacy strategy to avoid setting prune defaults if

pkg/openapi/zz_generated.openapi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4669,7 +4669,7 @@ func GetOpenAPIDefinitions(ref openapi.ReferenceCallback) map[string]openapi.Ope
46694669
},
46704670
"revisionHistoryLimit": {
46714671
SchemaProps: spec.SchemaProps{
4672-
Description: "RevisionHistoryLimit is the number of old ReplicationControllers to retain to allow for rollbacks. This field is a pointer to allow for differentiation between an explicit zero and not specified.",
4672+
Description: "RevisionHistoryLimit is the number of old ReplicationControllers to retain to allow for rollbacks. This field is a pointer to allow for differentiation between an explicit zero and not specified. Defaults to 10. (This only applies to DeploymentConfigs created via the new group API resource, not the legacy resource.)",
46734673
Type: []string{"integer"},
46744674
Format: "int32",
46754675
},

0 commit comments

Comments
 (0)