update decoder to use GroupVersion

This commit is contained in:
deads2k
2015-11-17 10:07:45 -05:00
parent 3bd23b185b
commit 6231404682
12 changed files with 78 additions and 47 deletions

View File

@@ -28,6 +28,8 @@ import (
type fakeCodec struct{}
var _ runtime.Decoder = fakeCodec{}
func (fakeCodec) Encode(runtime.Object) ([]byte, error) {
return []byte{}, nil
}
@@ -40,7 +42,7 @@ func (fakeCodec) Decode([]byte) (runtime.Object, error) {
return nil, nil
}
func (fakeCodec) DecodeToVersion([]byte, string) (runtime.Object, error) {
func (fakeCodec) DecodeToVersion([]byte, unversioned.GroupVersion) (runtime.Object, error) {
return nil, nil
}
@@ -48,7 +50,7 @@ func (fakeCodec) DecodeInto([]byte, runtime.Object) error {
return nil
}
func (fakeCodec) DecodeIntoWithSpecifiedVersionKind([]byte, runtime.Object, string, string) error {
func (fakeCodec) DecodeIntoWithSpecifiedVersionKind([]byte, runtime.Object, unversioned.GroupVersionKind) error {
return nil
}

View File

@@ -52,6 +52,11 @@ type GroupVersion struct {
// String puts "group" and "version" into a single "group/version" string. For the legacy v1
// it returns "v1".
func (gv GroupVersion) String() string {
// special case the internal apiVersion for kube
if len(gv.Group) == 0 && len(gv.Version) == 0 {
return ""
}
// special case of "v1" for backward compatibility
if gv.Group == "" && gv.Version == "v1" {
return gv.Version
@@ -63,6 +68,11 @@ func (gv GroupVersion) String() string {
// ParseGroupVersion turns "group/version" string into a GroupVersion struct. It reports error
// if it cannot parse the string.
func ParseGroupVersion(gv string) (GroupVersion, error) {
// this can be the internal version for kube
if (len(gv) == 0) || (gv == "/") {
return GroupVersion{}, nil
}
s := strings.Split(gv, "/")
// "v1" is the only special case. Otherwise GroupVersion is expected to contain
// one "/" dividing the string into two parts.