@@ -8,11 +8,7 @@ import (
88 "fmt"
99 "sync"
1010
11- "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
12- "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/install"
1311 apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
14- "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
15- "k8s.io/apimachinery/pkg/runtime"
1612 "k8s.io/apimachinery/pkg/util/yaml"
1713)
1814
@@ -33,22 +29,15 @@ func (c crdFile) mustUnmarshal() *apiextensionsv1.CustomResourceDefinition {
3329 panic (fmt .Errorf ("unable to read crd file %s: %s" , path , err ))
3430 }
3531
36- u := & unstructured. Unstructured {}
32+ crd := & apiextensionsv1. CustomResourceDefinition {}
3733 reader := bytes .NewReader (data )
3834 decoder := yaml .NewYAMLOrJSONDecoder (reader , 30 )
39- if err = decoder .Decode (u ); err != nil {
40- panic (fmt .Errorf ("crd unmarshaling failed: %s" , err ))
41- }
42-
43- // Step through unversioned type to support v1beta1 -> v1
44- unversioned := & apiextensions.CustomResourceDefinition {}
45- if err = scheme .Convert (u , unversioned , nil ); err != nil {
46- panic (fmt .Errorf ("failed to convert crd: %s\n to v1: %s" , u , err ))
35+ if err = decoder .Decode (crd ); err != nil {
36+ panic (fmt .Errorf ("failed to unmarshal to crd: %s" , err ))
4737 }
4838
49- crd := & apiextensionsv1.CustomResourceDefinition {}
50- if err = scheme .Convert (unversioned , crd , nil ); err != nil {
51- panic (fmt .Errorf ("failed to convert crd: %s\n to v1: %s" , u , err ))
39+ if gvk := crd .GroupVersionKind (); gvk != supportedGVK {
40+ panic (fmt .Errorf ("%s not supported" , gvk ))
5241 }
5342
5443 return crd
@@ -59,15 +48,10 @@ var (
5948
6049 // loaded stores previously unmarshaled CustomResourceDefinitions indexed by their file descriptor.
6150 loaded = map [crdFile ]* apiextensionsv1.CustomResourceDefinition {}
62- // scheme provides conversions between type versions .
63- scheme = runtime . NewScheme ( )
51+ // supportedGVK is the version of CustomResourceDefinition supported for unmarshaling .
52+ supportedGVK = apiextensionsv1 . SchemeGroupVersion . WithKind ( "CustomResourceDefinition" )
6453)
6554
66- func init () {
67- // Add conversions between CRD versions
68- install .Install (scheme )
69- }
70-
7155// getCRD lazily loads and returns the CustomResourceDefinition unmarshaled from a file.
7256func getCRD (file crdFile ) * apiextensionsv1.CustomResourceDefinition {
7357 lock .Lock ()
0 commit comments