kubectl stops rendering List as suffix kind name for CRD resources

This commit is contained in:
Di Xu 2018-04-13 10:46:38 +08:00
parent 44ede98e94
commit 82cc3b5d59
2 changed files with 13 additions and 2 deletions

View File

@ -18,7 +18,6 @@ package validation
import ( import (
"errors" "errors"
"strings"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
utilerrors "k8s.io/apimachinery/pkg/util/errors" utilerrors "k8s.io/apimachinery/pkg/util/errors"
@ -54,7 +53,7 @@ func (v *SchemaValidation) ValidateBytes(data []byte) error {
return utilerrors.NewAggregate(errs) return utilerrors.NewAggregate(errs)
} }
if strings.HasSuffix(gvk.Kind, "List") { if (gvk == schema.GroupVersionKind{Version: "v1", Kind: "List"}) {
return utilerrors.NewAggregate(v.validateList(obj)) return utilerrors.NewAggregate(v.validateList(obj))
} }

View File

@ -394,4 +394,16 @@ items:
`)) `))
Expect(err.Error()).To(Equal("[kind not set, apiVersion not set]")) Expect(err.Error()).To(Equal("[kind not set, apiVersion not set]"))
}) })
It("is fine with crd resource with List as a suffix kind name, which may not be a list of resources", func() {
err := validator.ValidateBytes([]byte(`
apiVersion: fake.com/v1
kind: FakeList
metadata:
name: fake
spec:
foo: bar
`))
Expect(err).To(BeNil())
})
}) })