Merge pull request #53765 from tanshanshan/fix-bug1

Automatic merge from submit-queue (batch tested with PRs 54529, 53765). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

fix  #53735, check whether  interface conversion is ok

**What this PR does / why we need it**:

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #

fix #53735

avoid interface conversion error 

**Special notes for your reviewer**:

**Release note**:

```release-note
```
This commit is contained in:
Kubernetes Submit Queue 2017-11-21 21:38:59 -08:00 committed by GitHub
commit 9a0bbd0aa9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -62,12 +62,15 @@ func (v *SchemaValidation) ValidateBytes(data []byte) error {
}
func (v *SchemaValidation) validateList(object interface{}) []error {
fields := object.(map[string]interface{})
if fields == nil {
fields, ok := object.(map[string]interface{})
if !ok || fields == nil {
return []error{errors.New("invalid object to validate")}
}
allErrors := []error{}
if _, ok := fields["items"].([]interface{}); !ok {
return []error{errors.New("invalid object to validate")}
}
for _, item := range fields["items"].([]interface{}) {
if gvk, errs := getObjectKind(item); errs != nil {
allErrors = append(allErrors, errs...)
@ -102,8 +105,8 @@ func parse(data []byte) (interface{}, error) {
func getObjectKind(object interface{}) (schema.GroupVersionKind, []error) {
var listErrors []error
fields := object.(map[string]interface{})
if fields == nil {
fields, ok := object.(map[string]interface{})
if !ok || fields == nil {
listErrors = append(listErrors, errors.New("invalid object to validate"))
return schema.GroupVersionKind{}, listErrors
}