Skip to content

Commit 1e6f449

Browse files
committed
Revert "Merge pull request kubernetes#118990 from alexzielenski/apiserver/apiextensions/crd-validation-ratcheting"
This reverts commit c684de5, reversing changes made to 31d662e.
1 parent 656eb7e commit 1e6f449

File tree

13 files changed

+35
-2247
lines changed

13 files changed

+35
-2247
lines changed

pkg/features/kube_features.go

-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package features
1818

1919
import (
20-
apiextensionsfeatures "k8s.io/apiextensions-apiserver/pkg/features"
2120
"k8s.io/apimachinery/pkg/util/runtime"
2221
genericfeatures "k8s.io/apiserver/pkg/features"
2322
utilfeature "k8s.io/apiserver/pkg/util/feature"
@@ -1212,11 +1211,6 @@ var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureS
12121211

12131212
genericfeatures.UnauthenticatedHTTP2DOSMitigation: {Default: false, PreRelease: featuregate.Beta},
12141213

1215-
// inherited features from apiextensions-apiserver, relisted here to get a conflict if it is changed
1216-
// unintentionally on either side:
1217-
1218-
apiextensionsfeatures.CRDValidationRatcheting: {Default: false, PreRelease: featuregate.Alpha},
1219-
12201214
// features that enable backwards compatibility but are scheduled to be removed
12211215
// ...
12221216
HPAScaleToZero: {Default: false, PreRelease: featuregate.Alpha},

staging/src/k8s.io/apiextensions-apiserver/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ go 1.20
66

77
require (
88
github.com/emicklei/go-restful/v3 v3.9.0
9-
github.com/evanphx/json-patch v4.12.0+incompatible
109
github.com/gogo/protobuf v1.3.2
1110
github.com/google/cel-go v0.16.1
1211
github.com/google/gnostic-models v0.6.8
@@ -50,6 +49,7 @@ require (
5049
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
5150
github.com/davecgh/go-spew v1.1.1 // indirect
5251
github.com/dustin/go-humanize v1.0.1 // indirect
52+
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
5353
github.com/felixge/httpsnoop v1.0.3 // indirect
5454
github.com/fsnotify/fsnotify v1.6.0 // indirect
5555
github.com/go-logr/logr v1.2.4 // indirect

staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/validation/validation.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ func validateCustomResourceDefinitionValidation(ctx context.Context, customResou
831831

832832
// if validation passed otherwise, make sure we can actually construct a schema validator from this custom resource validation.
833833
if len(allErrs) == 0 {
834-
if _, _, err := apiservervalidation.NewSchemaValidator(customResourceValidation.OpenAPIV3Schema); err != nil {
834+
if _, _, err := apiservervalidation.NewSchemaValidator(customResourceValidation); err != nil {
835835
allErrs = append(allErrs, field.Invalid(fldPath, "", fmt.Sprintf("error building validator: %v", err)))
836836
}
837837
}

staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_handler.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ import (
7979
"k8s.io/klog/v2"
8080
"k8s.io/kube-openapi/pkg/spec3"
8181
"k8s.io/kube-openapi/pkg/validation/spec"
82+
"k8s.io/kube-openapi/pkg/validation/strfmt"
83+
"k8s.io/kube-openapi/pkg/validation/validate"
8284
)
8385

8486
// crdHandler serves the `/apis` endpoint.
@@ -737,22 +739,20 @@ func (r *crdHandler) getOrCreateServingInfoFor(uid types.UID, name string) (*crd
737739
utilruntime.HandleError(err)
738740
return nil, fmt.Errorf("the server could not properly serve the CR schema")
739741
}
740-
var internalSchemaProps *apiextensionsinternal.JSONSchemaProps
741742
var internalValidationSchema *apiextensionsinternal.CustomResourceValidation
742743
if validationSchema != nil {
743744
internalValidationSchema = &apiextensionsinternal.CustomResourceValidation{}
744745
if err := apiextensionsv1.Convert_v1_CustomResourceValidation_To_apiextensions_CustomResourceValidation(validationSchema, internalValidationSchema, nil); err != nil {
745746
return nil, fmt.Errorf("failed to convert CRD validation to internal version: %v", err)
746747
}
747-
internalSchemaProps = internalValidationSchema.OpenAPIV3Schema
748748
}
749-
validator, _, err := apiservervalidation.NewSchemaValidator(internalSchemaProps)
749+
validator, _, err := apiservervalidation.NewSchemaValidator(internalValidationSchema)
750750
if err != nil {
751751
return nil, err
752752
}
753753

754754
var statusSpec *apiextensionsinternal.CustomResourceSubresourceStatus
755-
var statusValidator apiservervalidation.SchemaValidator
755+
var statusValidator *validate.SchemaValidator
756756
subresources, err := apiextensionshelpers.GetSubresourcesForVersion(crd, v.Name)
757757
if err != nil {
758758
utilruntime.HandleError(err)
@@ -767,10 +767,11 @@ func (r *crdHandler) getOrCreateServingInfoFor(uid types.UID, name string) (*crd
767767
// for the status subresource, validate only against the status schema
768768
if internalValidationSchema != nil && internalValidationSchema.OpenAPIV3Schema != nil && internalValidationSchema.OpenAPIV3Schema.Properties != nil {
769769
if statusSchema, ok := internalValidationSchema.OpenAPIV3Schema.Properties["status"]; ok {
770-
statusValidator, _, err = apiservervalidation.NewSchemaValidator(&statusSchema)
771-
if err != nil {
770+
openapiSchema := &spec.Schema{}
771+
if err := apiservervalidation.ConvertJSONSchemaPropsWithPostProcess(&statusSchema, openapiSchema, apiservervalidation.StripUnsupportedFormatsPostProcess); err != nil {
772772
return nil, err
773773
}
774+
statusValidator = validate.NewSchemaValidator(openapiSchema, nil, "", strfmt.Default)
774775
}
775776
}
776777
}

0 commit comments

Comments
 (0)