From 537caf5551e473bd5754f4735bf913e0040c7a6a Mon Sep 17 00:00:00 2001 From: Vu Dinh Date: Thu, 21 May 2020 11:52:45 -0400 Subject: [PATCH] fix(validation): Fix CRD v1beta int-float conversion error During bundle content validation, manifest files are converted to `unstructured` type and then convert back to CRD type which causes conversion error between int to float. Shouldn't use `unstructured` type as an intermediate type. Signed-off-by: Vu Dinh --- .../etcdclusters.etcd.database.coreos.com.crd.yaml | 10 ++++++++++ pkg/lib/bundle/validate.go | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/lib/bundle/testdata/validate/valid_bundle/manifests/etcdclusters.etcd.database.coreos.com.crd.yaml b/pkg/lib/bundle/testdata/validate/valid_bundle/manifests/etcdclusters.etcd.database.coreos.com.crd.yaml index 01111e5c5..c0515b4de 100644 --- a/pkg/lib/bundle/testdata/validate/valid_bundle/manifests/etcdclusters.etcd.database.coreos.com.crd.yaml +++ b/pkg/lib/bundle/testdata/validate/valid_bundle/manifests/etcdclusters.etcd.database.coreos.com.crd.yaml @@ -14,3 +14,13 @@ spec: singular: etcdcluster scope: Namespaced version: v1beta2 + validation: + openAPIV3Schema: + properties: + spec: + type: object + properties: + test: + type: integer + minimum: 1 + maximum: 32767 diff --git a/pkg/lib/bundle/validate.go b/pkg/lib/bundle/validate.go index 470403ed8..0579f15b3 100644 --- a/pkg/lib/bundle/validate.go +++ b/pkg/lib/bundle/validate.go @@ -313,10 +313,11 @@ func (i imageValidator) ValidateBundleContent(manifestDir string) error { } } } else if gvk.Kind == CRDKind { + dec := k8syaml.NewYAMLOrJSONDecoder(strings.NewReader(string(data)), 30) switch gv := gvk.GroupVersion().String(); gv { case v1CRDapiVersion: crd := &apiextensionsv1.CustomResourceDefinition{} - err := runtime.DefaultUnstructuredConverter.FromUnstructured(k8sFile.Object, crd) + err := dec.Decode(crd) if err != nil { validationErrors = append(validationErrors, err) continue @@ -330,7 +331,7 @@ func (i imageValidator) ValidateBundleContent(manifestDir string) error { } case v1beta1CRDapiVersion: crd := &apiextensionsv1beta1.CustomResourceDefinition{} - err := runtime.DefaultUnstructuredConverter.FromUnstructured(k8sFile.Object, crd) + err := dec.Decode(crd) if err != nil { validationErrors = append(validationErrors, err) continue