Skip to content

Commit

Permalink
CRD v1: limit 'default' use to v1
Browse files Browse the repository at this point in the history
  • Loading branch information
liggitt committed Aug 16, 2019
1 parent fec2d37 commit 1ca2eaf
Show file tree
Hide file tree
Showing 2 changed files with 325 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func ValidateCustomResourceDefinition(obj *apiextensions.CustomResourceDefinitio
}

opts := validationOptions{
allowDefaults: allowDefaults(requestGV),
allowDefaults: allowDefaults(requestGV, nil),
requireRecognizedConversionReviewVersion: true,
requireImmutableNames: false,
requireOpenAPISchema: requireOpenAPISchema(requestGV, nil),
Expand Down Expand Up @@ -92,7 +92,7 @@ type validationOptions struct {
// ValidateCustomResourceDefinitionUpdate statically validates
func ValidateCustomResourceDefinitionUpdate(obj, oldObj *apiextensions.CustomResourceDefinition, requestGV schema.GroupVersion) field.ErrorList {
opts := validationOptions{
allowDefaults: allowDefaults(requestGV) || specHasDefaults(&oldObj.Spec),
allowDefaults: allowDefaults(requestGV, &oldObj.Spec),
requireRecognizedConversionReviewVersion: oldObj.Spec.Conversion == nil || hasValidConversionReviewVersionOrEmpty(oldObj.Spec.Conversion.ConversionReviewVersions),
requireImmutableNames: apiextensions.IsCRDConditionTrue(oldObj, apiextensions.Established),
requireOpenAPISchema: requireOpenAPISchema(requestGV, &oldObj.Spec),
Expand Down Expand Up @@ -988,10 +988,17 @@ func allVersionsSpecifyOpenAPISchema(spec *apiextensions.CustomResourceDefinitio
}

// allowDefaults returns true if the defaulting feature is enabled and the request group version allows adding defaults
func allowDefaults(requestGV schema.GroupVersion) bool {
func allowDefaults(requestGV schema.GroupVersion, oldCRDSpec *apiextensions.CustomResourceDefinitionSpec) bool {
if oldCRDSpec != nil && specHasDefaults(oldCRDSpec) {
// don't tighten validation on existing persisted data
return true
}
if !utilfeature.DefaultFeatureGate.Enabled(apiextensionsfeatures.CustomResourceDefaulting) {
return false
}
if requestGV == v1beta1.SchemeGroupVersion {
return false
}
return true
}

Expand Down
Loading

0 comments on commit 1ca2eaf

Please sign in to comment.