Do not crash when groupVersion doesn't have a group

This commit is contained in:
Antoine Pelisse 2017-10-13 14:55:20 -07:00
parent 97e002352f
commit f6b66c70bf

View File

@ -18,11 +18,12 @@ package parse
import ( import (
"fmt" "fmt"
"reflect"
"strings"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/kubernetes/pkg/kubectl/apply" "k8s.io/kubernetes/pkg/kubectl/apply"
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi" "k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
"reflect"
"strings"
) )
// nilSafeLookup returns the value from the map if the map is non-nil // nilSafeLookup returns the value from the map if the map is non-nil
@ -152,9 +153,11 @@ func getGroupVersionKind(config map[string]interface{}) (schema.GroupVersionKind
if !ok { if !ok {
return gvk, fmt.Errorf("Expected string for apiVersion, found %T", gv) return gvk, fmt.Errorf("Expected string for apiVersion, found %T", gv)
} }
groupversion := strings.Split(casted, "/") s := strings.Split(casted, "/")
gvk.Group = groupversion[0] if len(s) != 1 {
gvk.Version = groupversion[1] gvk.Group = s[0]
}
gvk.Version = s[len(s)-1]
} else { } else {
return gvk, fmt.Errorf("Missing apiVersion in Kind %v", config) return gvk, fmt.Errorf("Missing apiVersion in Kind %v", config)
} }