Skip to content

Commit d7a720f

Browse files
authored
Merge pull request kubernetes#130819 from jpbetz/fix-subresource-disablement
Guard declarative validation code to only validate spec since subresources are not yet supported
2 parents 8e14736 + 5a98d4d commit d7a720f

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pkg/registry/core/replicationcontroller/strategy.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ func (rcStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorL
130130
allErrs := corevalidation.ValidateReplicationController(controller, opts)
131131

132132
// If DeclarativeValidation feature gate is enabled, also run declarative validation
133-
if utilfeature.DefaultFeatureGate.Enabled(features.DeclarativeValidation) {
133+
// FIXME: isSpecRequest(ctx) limits Declarative validation to the spec until subresource support is introduced.
134+
if utilfeature.DefaultFeatureGate.Enabled(features.DeclarativeValidation) && isSpecRequest(ctx) {
134135
// Determine if takeover is enabled
135136
takeover := utilfeature.DefaultFeatureGate.Enabled(features.DeclarativeValidationTakeover)
136137

@@ -175,7 +176,6 @@ func (rcStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) f
175176
newRc := obj.(*api.ReplicationController)
176177

177178
opts := pod.GetValidationOptionsFromPodTemplate(newRc.Spec.Template, oldRc.Spec.Template)
178-
// FIXME: Calling both validator functions here results in redundant calls to ValidateReplicationControllerSpec.
179179
// This should be fixed to avoid the redundant calls, but carefully.
180180
validationErrorList := corevalidation.ValidateReplicationController(newRc, opts)
181181
updateErrorList := corevalidation.ValidateReplicationControllerUpdate(newRc, oldRc, opts)
@@ -199,7 +199,8 @@ func (rcStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) f
199199
}
200200

201201
// If DeclarativeValidation feature gate is enabled, also run declarative validation
202-
if utilfeature.DefaultFeatureGate.Enabled(features.DeclarativeValidation) {
202+
// FIXME: This limits Declarative validation to the spec until subresource support is introduced.
203+
if utilfeature.DefaultFeatureGate.Enabled(features.DeclarativeValidation) && isSpecRequest(ctx) {
203204
// Determine if takeover is enabled
204205
takeover := utilfeature.DefaultFeatureGate.Enabled(features.DeclarativeValidationTakeover)
205206

@@ -218,6 +219,13 @@ func (rcStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) f
218219
return errs
219220
}
220221

222+
func isSpecRequest(ctx context.Context) bool {
223+
if requestInfo, found := genericapirequest.RequestInfoFrom(ctx); found {
224+
return len(requestInfo.Subresource) == 0
225+
}
226+
return false
227+
}
228+
221229
// WarningsOnUpdate returns warnings for the given update.
222230
func (rcStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
223231
var warnings []string

0 commit comments

Comments
 (0)