mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 05:03:09 +00:00
Merge pull request #53919 from apelisse/fix-new-apply-crash
Automatic merge from submit-queue (batch tested with PRs 53694, 53919). 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>. Do not crash when groupVersion doesn't have a group **What this PR does / why we need it**: fixes a crash when the group is empty, because it assumes that split will return a two element array. Which it doesn't. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes kubernetes/kubectl#78 **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
commit
88975e98d6
@ -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)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user