@@ -20,7 +20,6 @@ import (
2020 "fmt"
2121
2222 "github.com/getkin/kin-openapi/openapi3"
23- "github.com/santhosh-tekuri/jsonschema/v5"
2423 apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2524 "sigs.k8s.io/yaml"
2625
@@ -31,9 +30,8 @@ import (
3130// translator implements Translator to translate from a given CRD to and from
3231// a given SDK version using the same upstream OpenAPI schema
3332type translator struct {
34- majorVersion string
35- validationSchema * jsonschema.Schema
36- mappingSchema * openapi3.SchemaRef
33+ majorVersion string
34+ mappingSchema * openapi3.SchemaRef
3735}
3836
3937// Annotation returns the annotation value from the pinned translated schema
@@ -60,16 +58,6 @@ func (tr *translator) MajorVersion() string {
6058 return tr .majorVersion
6159}
6260
63- // Validate would return any errors of the given unstructured object against the
64- // pinned schema version being translated, or nil if the object is compliant
65- func (tr * translator ) Validate (unstructuredObj map [string ]any ) error {
66- // This correctly uses the validator from crds.CompileCRDSchema
67- if err := tr .validationSchema .Validate (unstructuredObj ); err != nil {
68- return fmt .Errorf ("object validation failed against CRD schema: %w" , err )
69- }
70- return nil
71- }
72-
7361// NewTranslator creates a translator for a particular CRD version. It is also
7462// locked into a particular API majorVersion.
7563//
@@ -88,10 +76,6 @@ func NewTranslator(crd *apiextensionsv1.CustomResourceDefinition, crdVersion str
8876 if err := crds .AssertMajorVersion (specVersion , crd .Spec .Names .Kind , majorVersion ); err != nil {
8977 return nil , fmt .Errorf ("failed to assert major version %s in CRD: %w" , majorVersion , err )
9078 }
91- validationSchema , err := crds .CompileCRDSchema (specVersion .Schema .OpenAPIV3Schema )
92- if err != nil {
93- return nil , fmt .Errorf ("failed to compile schema for validation: %w" , err )
94- }
9579 var mappingSchema openapi3.Schema
9680 mappingString , ok := crd .Annotations ["api-mappings" ]
9781 if ok && mappingString != "" {
@@ -105,8 +89,7 @@ func NewTranslator(crd *apiextensionsv1.CustomResourceDefinition, crdVersion str
10589 }
10690
10791 return & translator {
108- majorVersion : majorVersion ,
109- validationSchema : validationSchema ,
110- mappingSchema : & openapi3.SchemaRef {Value : & mappingSchema },
92+ majorVersion : majorVersion ,
93+ mappingSchema : & openapi3.SchemaRef {Value : & mappingSchema },
11194 }, nil
11295}
0 commit comments