Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
c6961d6f
Unverified
Commit
c6961d6f
authored
May 21, 2016
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove runtime.Typer, reduce to ObjectKinds(1) (3)
Remove the unnecessary variants, which avoids allocations in several core paths.
parent
a2493635
Hide whitespace changes
Inline
Side-by-side
Showing
38 changed files
with
159 additions
and
210 deletions
+159
-210
ref.go
pkg/api/ref.go
+2
-2
ref_test.go
pkg/api/ref_test.go
+1
-1
create.go
pkg/api/rest/create.go
+2
-2
serialization_proto_test.go
pkg/api/serialization_proto_test.go
+2
-2
testapi.go
pkg/api/testapi/testapi.go
+2
-1
api_installer.go
pkg/apiserver/api_installer.go
+13
-5
resthandler.go
pkg/apiserver/resthandler.go
+2
-1
fixture.go
pkg/client/testing/core/fixture.go
+2
-2
dynamic_util.go
pkg/client/typed/dynamic/dynamic_util.go
+4
-29
latest.go
pkg/client/unversioned/clientcmd/api/latest/latest.go
+1
-1
fixture.go
pkg/client/unversioned/testclient/fixture.go
+2
-2
simple_testclient.go
...client/unversioned/testclient/simple/simple_testclient.go
+2
-2
cmd_test.go
pkg/kubectl/cmd/cmd_test.go
+2
-2
create.go
pkg/kubectl/cmd/create.go
+5
-1
rollingupdate.go
pkg/kubectl/cmd/rollingupdate.go
+4
-4
run.go
pkg/kubectl/cmd/run.go
+2
-1
factory.go
pkg/kubectl/cmd/util/factory.go
+16
-16
mapper.go
pkg/kubectl/resource/mapper.go
+1
-1
result.go
pkg/kubectl/resource/result.go
+1
-1
resource_printer.go
pkg/kubectl/resource_printer.go
+5
-7
resource_printer_test.go
pkg/kubectl/resource_printer_test.go
+1
-1
etcd.go
pkg/registry/registrytest/etcd.go
+2
-1
codec.go
pkg/runtime/codec.go
+9
-7
helper.go
pkg/runtime/helper.go
+2
-43
interfaces.go
pkg/runtime/interfaces.go
+4
-19
scheme.go
pkg/runtime/scheme.go
+24
-20
scheme_test.go
pkg/runtime/scheme_test.go
+2
-1
codec_factory.go
pkg/runtime/serializer/codec_factory.go
+3
-3
json.go
pkg/runtime/serializer/json/json.go
+5
-4
json_test.go
pkg/runtime/serializer/json/json_test.go
+10
-3
protobuf.go
pkg/runtime/serializer/protobuf/protobuf.go
+11
-11
protobuf_test.go
pkg/runtime/serializer/protobuf/protobuf_test.go
+1
-1
protobuf_extension.go
pkg/runtime/serializer/protobuf_extension.go
+2
-2
recognizer_test.go
pkg/runtime/serializer/recognizer/recognizer_test.go
+2
-2
versioning.go
pkg/runtime/serializer/versioning/versioning.go
+6
-5
versioning_test.go
pkg/runtime/serializer/versioning/versioning_test.go
+1
-1
latest.go
plugin/pkg/scheduler/api/latest/latest.go
+1
-1
serializer.go
test/integration/framework/serializer.go
+2
-2
No files found.
pkg/api/ref.go
View file @
c6961d6f
...
@@ -57,11 +57,11 @@ func GetReference(obj runtime.Object) (*ObjectReference, error) {
...
@@ -57,11 +57,11 @@ func GetReference(obj runtime.Object) (*ObjectReference, error) {
kind
:=
gvk
.
Kind
kind
:=
gvk
.
Kind
if
len
(
kind
)
==
0
{
if
len
(
kind
)
==
0
{
// TODO: this is wrong
// TODO: this is wrong
gvk
,
err
:=
Scheme
.
ObjectKind
(
obj
)
gvk
s
,
_
,
err
:=
Scheme
.
ObjectKinds
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
kind
=
gvk
.
Kind
kind
=
gvk
s
[
0
]
.
Kind
}
}
// if the object referenced is actually persisted, we can also get version from meta
// if the object referenced is actually persisted, we can also get version from meta
...
...
pkg/api/ref_test.go
View file @
c6961d6f
...
@@ -40,7 +40,7 @@ func TestGetReference(t *testing.T) {
...
@@ -40,7 +40,7 @@ func TestGetReference(t *testing.T) {
// when vendoring kube, if you don't force the set of registered versions (like this hack/test-go.sh does)
// when vendoring kube, if you don't force the set of registered versions (like this hack/test-go.sh does)
// then you run into trouble because the types aren't registered in the scheme by anything. This does the
// then you run into trouble because the types aren't registered in the scheme by anything. This does the
// register manually to allow unit test execution
// register manually to allow unit test execution
if
_
,
err
:=
Scheme
.
ObjectKind
(
&
Pod
{});
err
!=
nil
{
if
_
,
_
,
err
:=
Scheme
.
ObjectKinds
(
&
Pod
{});
err
!=
nil
{
AddToScheme
(
Scheme
)
AddToScheme
(
Scheme
)
}
}
...
...
pkg/api/rest/create.go
View file @
c6961d6f
...
@@ -112,11 +112,11 @@ func objectMetaAndKind(typer runtime.ObjectTyper, obj runtime.Object) (*api.Obje
...
@@ -112,11 +112,11 @@ func objectMetaAndKind(typer runtime.ObjectTyper, obj runtime.Object) (*api.Obje
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
unversioned
.
GroupVersionKind
{},
errors
.
NewInternalError
(
err
)
return
nil
,
unversioned
.
GroupVersionKind
{},
errors
.
NewInternalError
(
err
)
}
}
kind
,
err
:=
typer
.
ObjectKind
(
obj
)
kind
s
,
_
,
err
:=
typer
.
ObjectKinds
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
unversioned
.
GroupVersionKind
{},
errors
.
NewInternalError
(
err
)
return
nil
,
unversioned
.
GroupVersionKind
{},
errors
.
NewInternalError
(
err
)
}
}
return
objectMeta
,
kind
,
nil
return
objectMeta
,
kind
s
[
0
]
,
nil
}
}
// NamespaceScopedStrategy has a method to tell if the object must be in a namespace.
// NamespaceScopedStrategy has a method to tell if the object must be in a namespace.
...
...
pkg/api/serialization_proto_test.go
View file @
c6961d6f
...
@@ -37,7 +37,7 @@ import (
...
@@ -37,7 +37,7 @@ import (
func
init
()
{
func
init
()
{
codecsToTest
=
append
(
codecsToTest
,
func
(
version
unversioned
.
GroupVersion
,
item
runtime
.
Object
)
(
runtime
.
Codec
,
error
)
{
codecsToTest
=
append
(
codecsToTest
,
func
(
version
unversioned
.
GroupVersion
,
item
runtime
.
Object
)
(
runtime
.
Codec
,
error
)
{
s
:=
protobuf
.
NewSerializer
(
api
.
Scheme
,
runtime
.
ObjectTyperToTyper
(
api
.
Scheme
)
,
"application/arbitrary.content.type"
)
s
:=
protobuf
.
NewSerializer
(
api
.
Scheme
,
api
.
Scheme
,
"application/arbitrary.content.type"
)
return
api
.
Codecs
.
CodecForVersions
(
s
,
s
,
testapi
.
ExternalGroupVersions
(),
nil
),
nil
return
api
.
Codecs
.
CodecForVersions
(
s
,
s
,
testapi
.
ExternalGroupVersions
(),
nil
),
nil
})
})
}
}
...
@@ -138,7 +138,7 @@ func BenchmarkEncodeProtobufGeneratedMarshal(b *testing.B) {
...
@@ -138,7 +138,7 @@ func BenchmarkEncodeProtobufGeneratedMarshal(b *testing.B) {
func
BenchmarkDecodeCodecToInternalProtobuf
(
b
*
testing
.
B
)
{
func
BenchmarkDecodeCodecToInternalProtobuf
(
b
*
testing
.
B
)
{
items
:=
benchmarkItems
()
items
:=
benchmarkItems
()
width
:=
len
(
items
)
width
:=
len
(
items
)
s
:=
protobuf
.
NewSerializer
(
api
.
Scheme
,
runtime
.
ObjectTyperToTyper
(
api
.
Scheme
)
,
"application/arbitrary.content.type"
)
s
:=
protobuf
.
NewSerializer
(
api
.
Scheme
,
api
.
Scheme
,
"application/arbitrary.content.type"
)
encoder
:=
api
.
Codecs
.
EncoderForVersion
(
s
,
v1
.
SchemeGroupVersion
)
encoder
:=
api
.
Codecs
.
EncoderForVersion
(
s
,
v1
.
SchemeGroupVersion
)
var
encoded
[][]
byte
var
encoded
[][]
byte
for
i
:=
range
items
{
for
i
:=
range
items
{
...
...
pkg/api/testapi/testapi.go
View file @
c6961d6f
...
@@ -354,10 +354,11 @@ func ExternalGroupVersions() []unversioned.GroupVersion {
...
@@ -354,10 +354,11 @@ func ExternalGroupVersions() []unversioned.GroupVersion {
// Get codec based on runtime.Object
// Get codec based on runtime.Object
func
GetCodecForObject
(
obj
runtime
.
Object
)
(
runtime
.
Codec
,
error
)
{
func
GetCodecForObject
(
obj
runtime
.
Object
)
(
runtime
.
Codec
,
error
)
{
kind
,
err
:=
api
.
Scheme
.
ObjectKind
(
obj
)
kind
s
,
_
,
err
:=
api
.
Scheme
.
ObjectKinds
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"unexpected encoding error: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"unexpected encoding error: %v"
,
err
)
}
}
kind
:=
kinds
[
0
]
for
_
,
group
:=
range
Groups
{
for
_
,
group
:=
range
Groups
{
if
group
.
GroupVersion
()
.
Group
!=
kind
.
Group
{
if
group
.
GroupVersion
()
.
Group
!=
kind
.
Group
{
...
...
pkg/apiserver/api_installer.go
View file @
c6961d6f
...
@@ -118,7 +118,7 @@ func (a *APIInstaller) getResourceKind(path string, storage rest.Storage) (unver
...
@@ -118,7 +118,7 @@ func (a *APIInstaller) getResourceKind(path string, storage rest.Storage) (unver
}
}
object
:=
storage
.
New
()
object
:=
storage
.
New
()
fqKinds
,
err
:=
a
.
group
.
Typer
.
ObjectKinds
(
object
)
fqKinds
,
_
,
err
:=
a
.
group
.
Typer
.
ObjectKinds
(
object
)
if
err
!=
nil
{
if
err
!=
nil
{
return
unversioned
.
GroupVersionKind
{},
err
return
unversioned
.
GroupVersionKind
{},
err
}
}
...
@@ -233,8 +233,11 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
...
@@ -233,8 +233,11 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
var
versionedList
interface
{}
var
versionedList
interface
{}
if
isLister
{
if
isLister
{
list
:=
lister
.
NewList
()
list
:=
lister
.
NewList
()
listGVK
,
err
:=
a
.
group
.
Typer
.
ObjectKind
(
list
)
listGVKs
,
_
,
err
:=
a
.
group
.
Typer
.
ObjectKinds
(
list
)
versionedListPtr
,
err
:=
a
.
group
.
Creater
.
New
(
a
.
group
.
GroupVersion
.
WithKind
(
listGVK
.
Kind
))
if
err
!=
nil
{
return
nil
,
err
}
versionedListPtr
,
err
:=
a
.
group
.
Creater
.
New
(
a
.
group
.
GroupVersion
.
WithKind
(
listGVKs
[
0
]
.
Kind
))
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -272,10 +275,11 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
...
@@ -272,10 +275,11 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
)
)
if
isGetterWithOptions
{
if
isGetterWithOptions
{
getOptions
,
getSubpath
,
_
=
getterWithOptions
.
NewGetOptions
()
getOptions
,
getSubpath
,
_
=
getterWithOptions
.
NewGetOptions
()
getOptionsInternalKind
,
err
=
a
.
group
.
Typer
.
ObjectKind
(
getOptions
)
getOptionsInternalKind
s
,
_
,
err
:=
a
.
group
.
Typer
.
ObjectKinds
(
getOptions
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
getOptionsInternalKind
=
getOptionsInternalKinds
[
0
]
versionedGetOptions
,
err
=
a
.
group
.
Creater
.
New
(
optionsExternalVersion
.
WithKind
(
getOptionsInternalKind
.
Kind
))
versionedGetOptions
,
err
=
a
.
group
.
Creater
.
New
(
optionsExternalVersion
.
WithKind
(
getOptionsInternalKind
.
Kind
))
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -300,12 +304,16 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
...
@@ -300,12 +304,16 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
if
isConnecter
{
if
isConnecter
{
connectOptions
,
connectSubpath
,
_
=
connecter
.
NewConnectOptions
()
connectOptions
,
connectSubpath
,
_
=
connecter
.
NewConnectOptions
()
if
connectOptions
!=
nil
{
if
connectOptions
!=
nil
{
connectOptionsInternalKind
,
err
=
a
.
group
.
Typer
.
ObjectKind
(
connectOptions
)
connectOptionsInternalKind
s
,
_
,
err
:=
a
.
group
.
Typer
.
ObjectKinds
(
connectOptions
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
connectOptionsInternalKind
=
connectOptionsInternalKinds
[
0
]
versionedConnectOptions
,
err
=
a
.
group
.
Creater
.
New
(
optionsExternalVersion
.
WithKind
(
connectOptionsInternalKind
.
Kind
))
versionedConnectOptions
,
err
=
a
.
group
.
Creater
.
New
(
optionsExternalVersion
.
WithKind
(
connectOptionsInternalKind
.
Kind
))
if
err
!=
nil
{
return
nil
,
err
}
}
}
}
}
...
...
pkg/apiserver/resthandler.go
View file @
c6961d6f
...
@@ -939,10 +939,11 @@ func finishRequest(timeout time.Duration, fn resultFunc) (result runtime.Object,
...
@@ -939,10 +939,11 @@ func finishRequest(timeout time.Duration, fn resultFunc) (result runtime.Object,
// transformDecodeError adds additional information when a decode fails.
// transformDecodeError adds additional information when a decode fails.
func
transformDecodeError
(
typer
runtime
.
ObjectTyper
,
baseErr
error
,
into
runtime
.
Object
,
gvk
*
unversioned
.
GroupVersionKind
,
body
[]
byte
)
error
{
func
transformDecodeError
(
typer
runtime
.
ObjectTyper
,
baseErr
error
,
into
runtime
.
Object
,
gvk
*
unversioned
.
GroupVersionKind
,
body
[]
byte
)
error
{
objGVK
,
err
:=
typer
.
ObjectKind
(
into
)
objGVK
s
,
_
,
err
:=
typer
.
ObjectKinds
(
into
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
objGVK
:=
objGVKs
[
0
]
if
gvk
!=
nil
&&
len
(
gvk
.
Kind
)
>
0
{
if
gvk
!=
nil
&&
len
(
gvk
.
Kind
)
>
0
{
return
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"%s in version %q cannot be handled as a %s: %v"
,
gvk
.
Kind
,
gvk
.
Version
,
objGVK
.
Kind
,
baseErr
))
return
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"%s in version %q cannot be handled as a %s: %v"
,
gvk
.
Kind
,
gvk
.
Version
,
objGVK
.
Kind
,
baseErr
))
}
}
...
...
pkg/client/testing/core/fixture.go
View file @
c6961d6f
...
@@ -210,11 +210,11 @@ func (o objects) Kind(kind unversioned.GroupVersionKind, name string) (runtime.O
...
@@ -210,11 +210,11 @@ func (o objects) Kind(kind unversioned.GroupVersionKind, name string) (runtime.O
}
}
func
(
o
objects
)
Add
(
obj
runtime
.
Object
)
error
{
func
(
o
objects
)
Add
(
obj
runtime
.
Object
)
error
{
gvk
,
err
:=
o
.
scheme
.
ObjectKind
(
obj
)
gvk
s
,
_
,
err
:=
o
.
scheme
.
ObjectKinds
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
kind
:=
gvk
.
Kind
kind
:=
gvk
s
[
0
]
.
Kind
switch
{
switch
{
case
meta
.
IsListType
(
obj
)
:
case
meta
.
IsListType
(
obj
)
:
...
...
pkg/client/typed/dynamic/dynamic_util.go
View file @
c6961d6f
...
@@ -76,28 +76,15 @@ func NewObjectTyper(resources []*unversioned.APIResourceList) (runtime.ObjectTyp
...
@@ -76,28 +76,15 @@ func NewObjectTyper(resources []*unversioned.APIResourceList) (runtime.ObjectTyp
return
ot
,
nil
return
ot
,
nil
}
}
// ObjectKind returns the group,version,kind of the provided object,
// or an error if the object in not *runtime.Unstructured or has no
// group,version,kind information.
func
(
ot
*
ObjectTyper
)
ObjectKind
(
obj
runtime
.
Object
)
(
unversioned
.
GroupVersionKind
,
error
)
{
if
_
,
ok
:=
obj
.
(
*
runtime
.
Unstructured
);
!
ok
{
return
unversioned
.
GroupVersionKind
{},
fmt
.
Errorf
(
"type %T is invalid for dynamic object typer"
,
obj
)
}
return
obj
.
GetObjectKind
()
.
GroupVersionKind
(),
nil
}
// ObjectKinds returns a slice of one element with the
// ObjectKinds returns a slice of one element with the
// group,version,kind of the provided object, or an error if the
// group,version,kind of the provided object, or an error if the
// object is not *runtime.Unstructured or has no group,version,kind
// object is not *runtime.Unstructured or has no group,version,kind
// information.
// information.
func
(
ot
*
ObjectTyper
)
ObjectKinds
(
obj
runtime
.
Object
)
([]
unversioned
.
GroupVersionKind
,
error
)
{
func
(
ot
*
ObjectTyper
)
ObjectKinds
(
obj
runtime
.
Object
)
([]
unversioned
.
GroupVersionKind
,
bool
,
error
)
{
gvk
,
err
:=
ot
.
ObjectKind
(
obj
)
if
_
,
ok
:=
obj
.
(
*
runtime
.
Unstructured
);
!
ok
{
if
err
!=
nil
{
return
nil
,
false
,
fmt
.
Errorf
(
"type %T is invalid for dynamic object typer"
,
obj
)
return
nil
,
err
}
}
return
[]
unversioned
.
GroupVersionKind
{
obj
.
GetObjectKind
()
.
GroupVersionKind
()},
false
,
nil
return
[]
unversioned
.
GroupVersionKind
{
gvk
},
nil
}
}
// Recognizes returns true if the provided group,version,kind was in
// Recognizes returns true if the provided group,version,kind was in
...
@@ -105,15 +92,3 @@ func (ot *ObjectTyper) ObjectKinds(obj runtime.Object) ([]unversioned.GroupVersi
...
@@ -105,15 +92,3 @@ func (ot *ObjectTyper) ObjectKinds(obj runtime.Object) ([]unversioned.GroupVersi
func
(
ot
*
ObjectTyper
)
Recognizes
(
gvk
unversioned
.
GroupVersionKind
)
bool
{
func
(
ot
*
ObjectTyper
)
Recognizes
(
gvk
unversioned
.
GroupVersionKind
)
bool
{
return
ot
.
registered
[
gvk
]
return
ot
.
registered
[
gvk
]
}
}
// IsUnversioned returns false always because *runtime.Unstructured
// objects should always have group,version,kind information set. ok
// will be true if the object's group,version,kind is registered.
func
(
ot
*
ObjectTyper
)
IsUnversioned
(
obj
runtime
.
Object
)
(
unversioned
bool
,
ok
bool
)
{
gvk
,
err
:=
ot
.
ObjectKind
(
obj
)
if
err
!=
nil
{
return
false
,
false
}
return
false
,
ot
.
registered
[
gvk
]
}
pkg/client/unversioned/clientcmd/api/latest/latest.go
View file @
c6961d6f
...
@@ -43,7 +43,7 @@ var Versions = []string{"v1"}
...
@@ -43,7 +43,7 @@ var Versions = []string{"v1"}
var
Codec
runtime
.
Codec
var
Codec
runtime
.
Codec
func
init
()
{
func
init
()
{
yamlSerializer
:=
json
.
NewYAMLSerializer
(
json
.
DefaultMetaFactory
,
api
.
Scheme
,
runtime
.
ObjectTyperToTyper
(
api
.
Scheme
)
)
yamlSerializer
:=
json
.
NewYAMLSerializer
(
json
.
DefaultMetaFactory
,
api
.
Scheme
,
api
.
Scheme
)
Codec
=
versioning
.
NewCodecForScheme
(
Codec
=
versioning
.
NewCodecForScheme
(
api
.
Scheme
,
api
.
Scheme
,
yamlSerializer
,
yamlSerializer
,
...
...
pkg/client/unversioned/testclient/fixture.go
View file @
c6961d6f
...
@@ -204,11 +204,11 @@ func (o objects) Kind(kind unversioned.GroupVersionKind, name string) (runtime.O
...
@@ -204,11 +204,11 @@ func (o objects) Kind(kind unversioned.GroupVersionKind, name string) (runtime.O
}
}
func
(
o
objects
)
Add
(
obj
runtime
.
Object
)
error
{
func
(
o
objects
)
Add
(
obj
runtime
.
Object
)
error
{
gvk
,
err
:=
o
.
scheme
.
ObjectKind
(
obj
)
gvk
s
,
_
,
err
:=
o
.
scheme
.
ObjectKinds
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
kind
:=
gvk
.
Kind
kind
:=
gvk
s
[
0
]
.
Kind
switch
{
switch
{
case
meta
.
IsListType
(
obj
)
:
case
meta
.
IsListType
(
obj
)
:
...
...
pkg/client/unversioned/testclient/simple/simple_testclient.go
View file @
c6961d6f
...
@@ -220,11 +220,11 @@ func validateFields(a, b string) bool {
...
@@ -220,11 +220,11 @@ func validateFields(a, b string) bool {
func
(
c
*
Client
)
body
(
t
*
testing
.
T
,
obj
runtime
.
Object
,
raw
*
string
)
*
string
{
func
(
c
*
Client
)
body
(
t
*
testing
.
T
,
obj
runtime
.
Object
,
raw
*
string
)
*
string
{
if
obj
!=
nil
{
if
obj
!=
nil
{
fqKind
,
err
:=
api
.
Scheme
.
ObjectKind
(
obj
)
fqKind
s
,
_
,
err
:=
api
.
Scheme
.
ObjectKinds
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected encoding error: %v"
,
err
)
t
.
Errorf
(
"unexpected encoding error: %v"
,
err
)
}
}
groupName
:=
fqKind
.
GroupVersion
()
.
Group
groupName
:=
fqKind
s
[
0
]
.
GroupVersion
()
.
Group
if
c
.
ResourceGroup
!=
""
{
if
c
.
ResourceGroup
!=
""
{
groupName
=
c
.
ResourceGroup
groupName
=
c
.
ResourceGroup
}
}
...
...
pkg/kubectl/cmd/cmd_test.go
View file @
c6961d6f
...
@@ -320,11 +320,11 @@ func NewAPIFactory() (*cmdutil.Factory, *testFactory, runtime.Codec) {
...
@@ -320,11 +320,11 @@ func NewAPIFactory() (*cmdutil.Factory, *testFactory, runtime.Codec) {
}
}
return
c
.
Pods
(
t
.
Namespace
)
.
GetLogs
(
t
.
Name
,
opts
),
nil
return
c
.
Pods
(
t
.
Namespace
)
.
GetLogs
(
t
.
Name
,
opts
),
nil
default
:
default
:
fqKind
,
err
:=
api
.
Scheme
.
ObjectKind
(
object
)
fqKind
s
,
_
,
err
:=
api
.
Scheme
.
ObjectKinds
(
object
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
nil
,
fmt
.
Errorf
(
"cannot get the logs from %v"
,
fqKind
)
return
nil
,
fmt
.
Errorf
(
"cannot get the logs from %v"
,
fqKind
s
[
0
]
)
}
}
},
},
}
}
...
...
pkg/kubectl/cmd/create.go
View file @
c6961d6f
...
@@ -225,7 +225,11 @@ func RunCreateSubcommand(f *cmdutil.Factory, cmd *cobra.Command, out io.Writer,
...
@@ -225,7 +225,11 @@ func RunCreateSubcommand(f *cmdutil.Factory, cmd *cobra.Command, out io.Writer,
return
err
return
err
}
}
mapper
,
typer
:=
f
.
Object
(
cmdutil
.
GetIncludeThirdPartyAPIs
(
cmd
))
mapper
,
typer
:=
f
.
Object
(
cmdutil
.
GetIncludeThirdPartyAPIs
(
cmd
))
gvk
,
err
:=
typer
.
ObjectKind
(
obj
)
gvks
,
_
,
err
:=
typer
.
ObjectKinds
(
obj
)
if
err
!=
nil
{
return
err
}
gvk
:=
gvks
[
0
]
mapping
,
err
:=
mapper
.
RESTMapping
(
unversioned
.
GroupKind
{
Group
:
gvk
.
Group
,
Kind
:
gvk
.
Kind
},
gvk
.
Version
)
mapping
,
err
:=
mapper
.
RESTMapping
(
unversioned
.
GroupKind
{
Group
:
gvk
.
Group
,
Kind
:
gvk
.
Kind
},
gvk
.
Version
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
pkg/kubectl/cmd/rollingupdate.go
View file @
c6961d6f
...
@@ -221,8 +221,8 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
...
@@ -221,8 +221,8 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
}
}
newRc
,
ok
=
obj
.
(
*
api
.
ReplicationController
)
newRc
,
ok
=
obj
.
(
*
api
.
ReplicationController
)
if
!
ok
{
if
!
ok
{
if
gvk
,
err
:=
typer
.
ObjectKind
(
obj
);
err
==
nil
{
if
gvk
s
,
_
,
err
:=
typer
.
ObjectKinds
(
obj
);
err
==
nil
{
return
cmdutil
.
UsageError
(
cmd
,
"%s contains a %v not a ReplicationController"
,
filename
,
gvk
)
return
cmdutil
.
UsageError
(
cmd
,
"%s contains a %v not a ReplicationController"
,
filename
,
gvk
s
[
0
]
)
}
}
glog
.
V
(
4
)
.
Infof
(
"Object %#v is not a ReplicationController"
,
obj
)
glog
.
V
(
4
)
.
Infof
(
"Object %#v is not a ReplicationController"
,
obj
)
return
cmdutil
.
UsageError
(
cmd
,
"%s does not specify a valid ReplicationController"
,
filename
)
return
cmdutil
.
UsageError
(
cmd
,
"%s does not specify a valid ReplicationController"
,
filename
)
...
@@ -377,11 +377,11 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
...
@@ -377,11 +377,11 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
if
outputFormat
!=
""
{
if
outputFormat
!=
""
{
return
f
.
PrintObject
(
cmd
,
mapper
,
newRc
,
out
)
return
f
.
PrintObject
(
cmd
,
mapper
,
newRc
,
out
)
}
}
kind
,
err
:=
api
.
Scheme
.
ObjectKind
(
newRc
)
kind
s
,
_
,
err
:=
api
.
Scheme
.
ObjectKinds
(
newRc
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
_
,
res
:=
meta
.
KindToResource
(
kind
)
_
,
res
:=
meta
.
KindToResource
(
kind
s
[
0
]
)
cmdutil
.
PrintSuccess
(
mapper
,
false
,
out
,
res
.
Resource
,
oldName
,
message
)
cmdutil
.
PrintSuccess
(
mapper
,
false
,
out
,
res
.
Resource
,
oldName
,
message
)
return
nil
return
nil
}
}
...
...
pkg/kubectl/cmd/run.go
View file @
c6961d6f
...
@@ -443,10 +443,11 @@ func createGeneratedObject(f *cmdutil.Factory, cmd *cobra.Command, generator kub
...
@@ -443,10 +443,11 @@ func createGeneratedObject(f *cmdutil.Factory, cmd *cobra.Command, generator kub
}
}
mapper
,
typer
:=
f
.
Object
(
cmdutil
.
GetIncludeThirdPartyAPIs
(
cmd
))
mapper
,
typer
:=
f
.
Object
(
cmdutil
.
GetIncludeThirdPartyAPIs
(
cmd
))
groupVersionKind
,
err
:=
typer
.
ObjectKind
(
obj
)
groupVersionKind
s
,
_
,
err
:=
typer
.
ObjectKinds
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
""
,
nil
,
nil
,
err
return
nil
,
""
,
nil
,
nil
,
err
}
}
groupVersionKind
:=
groupVersionKinds
[
0
]
if
len
(
overrides
)
>
0
{
if
len
(
overrides
)
>
0
{
codec
:=
runtime
.
NewCodec
(
f
.
JSONEncoder
(),
f
.
Decoder
(
true
))
codec
:=
runtime
.
NewCodec
(
f
.
JSONEncoder
(),
f
.
Decoder
(
true
))
...
...
pkg/kubectl/cmd/util/factory.go
View file @
c6961d6f
...
@@ -419,11 +419,11 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -419,11 +419,11 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
}
}
return
kubectl
.
MakeLabels
(
t
.
Spec
.
Selector
.
MatchLabels
),
nil
return
kubectl
.
MakeLabels
(
t
.
Spec
.
Selector
.
MatchLabels
),
nil
default
:
default
:
gvk
,
err
:=
api
.
Scheme
.
ObjectKind
(
object
)
gvk
s
,
_
,
err
:=
api
.
Scheme
.
ObjectKinds
(
object
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
return
""
,
fmt
.
Errorf
(
"cannot extract pod selector from %v"
,
gvk
)
return
""
,
fmt
.
Errorf
(
"cannot extract pod selector from %v"
,
gvk
s
[
0
]
)
}
}
},
},
PortsForObject
:
func
(
object
runtime
.
Object
)
([]
string
,
error
)
{
PortsForObject
:
func
(
object
runtime
.
Object
)
([]
string
,
error
)
{
...
@@ -440,11 +440,11 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -440,11 +440,11 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
case
*
extensions
.
ReplicaSet
:
case
*
extensions
.
ReplicaSet
:
return
getPorts
(
t
.
Spec
.
Template
.
Spec
),
nil
return
getPorts
(
t
.
Spec
.
Template
.
Spec
),
nil
default
:
default
:
gvk
,
err
:=
api
.
Scheme
.
ObjectKind
(
object
)
gvk
s
,
_
,
err
:=
api
.
Scheme
.
ObjectKinds
(
object
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
nil
,
fmt
.
Errorf
(
"cannot extract ports from %v"
,
gvk
)
return
nil
,
fmt
.
Errorf
(
"cannot extract ports from %v"
,
gvk
s
[
0
]
)
}
}
},
},
ProtocolsForObject
:
func
(
object
runtime
.
Object
)
(
map
[
string
]
string
,
error
)
{
ProtocolsForObject
:
func
(
object
runtime
.
Object
)
(
map
[
string
]
string
,
error
)
{
...
@@ -461,11 +461,11 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -461,11 +461,11 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
case
*
extensions
.
ReplicaSet
:
case
*
extensions
.
ReplicaSet
:
return
getProtocols
(
t
.
Spec
.
Template
.
Spec
),
nil
return
getProtocols
(
t
.
Spec
.
Template
.
Spec
),
nil
default
:
default
:
gvk
,
err
:=
api
.
Scheme
.
ObjectKind
(
object
)
gvk
s
,
_
,
err
:=
api
.
Scheme
.
ObjectKinds
(
object
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
nil
,
fmt
.
Errorf
(
"cannot extract protocols from %v"
,
gvk
)
return
nil
,
fmt
.
Errorf
(
"cannot extract protocols from %v"
,
gvk
s
[
0
]
)
}
}
},
},
LabelsForObject
:
func
(
object
runtime
.
Object
)
(
map
[
string
]
string
,
error
)
{
LabelsForObject
:
func
(
object
runtime
.
Object
)
(
map
[
string
]
string
,
error
)
{
...
@@ -523,11 +523,11 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -523,11 +523,11 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
return
c
.
Pods
(
pod
.
Namespace
)
.
GetLogs
(
pod
.
Name
,
opts
),
nil
return
c
.
Pods
(
pod
.
Namespace
)
.
GetLogs
(
pod
.
Name
,
opts
),
nil
default
:
default
:
gvk
,
err
:=
api
.
Scheme
.
ObjectKind
(
object
)
gvk
s
,
_
,
err
:=
api
.
Scheme
.
ObjectKinds
(
object
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
nil
,
fmt
.
Errorf
(
"cannot get the logs from %v"
,
gvk
)
return
nil
,
fmt
.
Errorf
(
"cannot get the logs from %v"
,
gvk
s
[
0
]
)
}
}
},
},
PauseObject
:
func
(
object
runtime
.
Object
)
(
bool
,
error
)
{
PauseObject
:
func
(
object
runtime
.
Object
)
(
bool
,
error
)
{
...
@@ -545,11 +545,11 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -545,11 +545,11 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
_
,
err
:=
c
.
Extensions
()
.
Deployments
(
t
.
Namespace
)
.
Update
(
t
)
_
,
err
:=
c
.
Extensions
()
.
Deployments
(
t
.
Namespace
)
.
Update
(
t
)
return
false
,
err
return
false
,
err
default
:
default
:
gvk
,
err
:=
api
.
Scheme
.
ObjectKind
(
object
)
gvk
s
,
_
,
err
:=
api
.
Scheme
.
ObjectKinds
(
object
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
}
}
return
false
,
fmt
.
Errorf
(
"cannot pause %v"
,
gvk
)
return
false
,
fmt
.
Errorf
(
"cannot pause %v"
,
gvk
s
[
0
]
)
}
}
},
},
ResumeObject
:
func
(
object
runtime
.
Object
)
(
bool
,
error
)
{
ResumeObject
:
func
(
object
runtime
.
Object
)
(
bool
,
error
)
{
...
@@ -567,11 +567,11 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -567,11 +567,11 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
_
,
err
:=
c
.
Extensions
()
.
Deployments
(
t
.
Namespace
)
.
Update
(
t
)
_
,
err
:=
c
.
Extensions
()
.
Deployments
(
t
.
Namespace
)
.
Update
(
t
)
return
false
,
err
return
false
,
err
default
:
default
:
gvk
,
err
:=
api
.
Scheme
.
ObjectKind
(
object
)
gvk
s
,
_
,
err
:=
api
.
Scheme
.
ObjectKinds
(
object
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
}
}
return
false
,
fmt
.
Errorf
(
"cannot resume %v"
,
gvk
)
return
false
,
fmt
.
Errorf
(
"cannot resume %v"
,
gvk
s
[
0
]
)
}
}
},
},
Scaler
:
func
(
mapping
*
meta
.
RESTMapping
)
(
kubectl
.
Scaler
,
error
)
{
Scaler
:
func
(
mapping
*
meta
.
RESTMapping
)
(
kubectl
.
Scaler
,
error
)
{
...
@@ -704,11 +704,11 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -704,11 +704,11 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
case
*
api
.
Pod
:
case
*
api
.
Pod
:
return
t
,
nil
return
t
,
nil
default
:
default
:
gvk
,
err
:=
api
.
Scheme
.
ObjectKind
(
object
)
gvk
s
,
_
,
err
:=
api
.
Scheme
.
ObjectKinds
(
object
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
nil
,
fmt
.
Errorf
(
"cannot attach to %v: not implemented"
,
gvk
)
return
nil
,
fmt
.
Errorf
(
"cannot attach to %v: not implemented"
,
gvk
s
[
0
]
)
}
}
},
},
// UpdatePodSpecForObject update the pod specification for the provided object
// UpdatePodSpecForObject update the pod specification for the provided object
...
@@ -1087,12 +1087,12 @@ func DefaultClientConfig(flags *pflag.FlagSet) clientcmd.ClientConfig {
...
@@ -1087,12 +1087,12 @@ func DefaultClientConfig(flags *pflag.FlagSet) clientcmd.ClientConfig {
// PrintObject prints an api object given command line flags to modify the output format
// PrintObject prints an api object given command line flags to modify the output format
func
(
f
*
Factory
)
PrintObject
(
cmd
*
cobra
.
Command
,
mapper
meta
.
RESTMapper
,
obj
runtime
.
Object
,
out
io
.
Writer
)
error
{
func
(
f
*
Factory
)
PrintObject
(
cmd
*
cobra
.
Command
,
mapper
meta
.
RESTMapper
,
obj
runtime
.
Object
,
out
io
.
Writer
)
error
{
gvk
,
err
:=
api
.
Scheme
.
ObjectKind
(
obj
)
gvk
s
,
_
,
err
:=
api
.
Scheme
.
ObjectKinds
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
mapping
,
err
:=
mapper
.
RESTMapping
(
gvk
.
GroupKind
())
mapping
,
err
:=
mapper
.
RESTMapping
(
gvk
s
[
0
]
.
GroupKind
())
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
pkg/kubectl/resource/mapper.go
View file @
c6961d6f
...
@@ -96,7 +96,7 @@ func (m *Mapper) InfoForData(data []byte, source string) (*Info, error) {
...
@@ -96,7 +96,7 @@ func (m *Mapper) InfoForData(data []byte, source string) (*Info, error) {
// if the object cannot be introspected. Name and namespace will be set into Info
// if the object cannot be introspected. Name and namespace will be set into Info
// if the mapping's MetadataAccessor can retrieve them.
// if the mapping's MetadataAccessor can retrieve them.
func
(
m
*
Mapper
)
InfoForObject
(
obj
runtime
.
Object
,
preferredGVKs
[]
unversioned
.
GroupVersionKind
)
(
*
Info
,
error
)
{
func
(
m
*
Mapper
)
InfoForObject
(
obj
runtime
.
Object
,
preferredGVKs
[]
unversioned
.
GroupVersionKind
)
(
*
Info
,
error
)
{
groupVersionKinds
,
err
:=
m
.
ObjectKinds
(
obj
)
groupVersionKinds
,
_
,
err
:=
m
.
ObjectKinds
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"unable to get type info from the object %q: %v"
,
reflect
.
TypeOf
(
obj
),
err
)
return
nil
,
fmt
.
Errorf
(
"unable to get type info from the object %q: %v"
,
reflect
.
TypeOf
(
obj
),
err
)
}
}
...
...
pkg/kubectl/resource/result.go
View file @
c6961d6f
...
@@ -251,7 +251,7 @@ func AsVersionedObjects(infos []*Info, version unversioned.GroupVersion, encoder
...
@@ -251,7 +251,7 @@ func AsVersionedObjects(infos []*Info, version unversioned.GroupVersion, encoder
// objects that are not part of api.Scheme must be converted to JSON
// objects that are not part of api.Scheme must be converted to JSON
// TODO: convert to map[string]interface{}, attach to runtime.Unknown?
// TODO: convert to map[string]interface{}, attach to runtime.Unknown?
if
!
version
.
IsEmpty
()
{
if
!
version
.
IsEmpty
()
{
if
_
,
err
:=
api
.
Scheme
.
ObjectKind
(
info
.
Object
);
runtime
.
IsNotRegisteredError
(
err
)
{
if
_
,
_
,
err
:=
api
.
Scheme
.
ObjectKinds
(
info
.
Object
);
runtime
.
IsNotRegisteredError
(
err
)
{
// TODO: ideally this would encode to version, but we don't expose multiple codecs here.
// TODO: ideally this would encode to version, but we don't expose multiple codecs here.
data
,
err
:=
runtime
.
Encode
(
encoder
,
info
.
Object
)
data
,
err
:=
runtime
.
Encode
(
encoder
,
info
.
Object
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/kubectl/resource_printer.go
View file @
c6961d6f
...
@@ -69,7 +69,8 @@ func GetPrinter(format, formatArgument string) (ResourcePrinter, bool, error) {
...
@@ -69,7 +69,8 @@ func GetPrinter(format, formatArgument string) (ResourcePrinter, bool, error) {
printer
=
&
YAMLPrinter
{}
printer
=
&
YAMLPrinter
{}
case
"name"
:
case
"name"
:
printer
=
&
NamePrinter
{
printer
=
&
NamePrinter
{
Typer
:
runtime
.
ObjectTyperToTyper
(
api
.
Scheme
),
// TODO: this is wrong, these should be provided as an argument to GetPrinter
Typer
:
api
.
Scheme
,
Decoder
:
api
.
Codecs
.
UniversalDecoder
(),
Decoder
:
api
.
Codecs
.
UniversalDecoder
(),
}
}
case
"template"
,
"go-template"
:
case
"template"
,
"go-template"
:
...
@@ -203,14 +204,12 @@ func (p *VersionedPrinter) HandledResources() []string {
...
@@ -203,14 +204,12 @@ func (p *VersionedPrinter) HandledResources() []string {
// NamePrinter is an implementation of ResourcePrinter which outputs "resource/name" pair of an object.
// NamePrinter is an implementation of ResourcePrinter which outputs "resource/name" pair of an object.
type
NamePrinter
struct
{
type
NamePrinter
struct
{
Decoder
runtime
.
Decoder
Decoder
runtime
.
Decoder
Typer
runtime
.
Typer
Typer
runtime
.
Object
Typer
}
}
// PrintObj is an implementation of ResourcePrinter.PrintObj which decodes the object
// PrintObj is an implementation of ResourcePrinter.PrintObj which decodes the object
// and print "resource/name" pair. If the object is a List, print all items in it.
// and print "resource/name" pair. If the object is a List, print all items in it.
func
(
p
*
NamePrinter
)
PrintObj
(
obj
runtime
.
Object
,
w
io
.
Writer
)
error
{
func
(
p
*
NamePrinter
)
PrintObj
(
obj
runtime
.
Object
,
w
io
.
Writer
)
error
{
gvk
,
_
,
_
:=
p
.
Typer
.
ObjectKind
(
obj
)
if
meta
.
IsListType
(
obj
)
{
if
meta
.
IsListType
(
obj
)
{
items
,
err
:=
meta
.
ExtractList
(
obj
)
items
,
err
:=
meta
.
ExtractList
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -236,10 +235,9 @@ func (p *NamePrinter) PrintObj(obj runtime.Object, w io.Writer) error {
...
@@ -236,10 +235,9 @@ func (p *NamePrinter) PrintObj(obj runtime.Object, w io.Writer) error {
}
}
}
}
if
gvk
!
=
nil
{
if
gvk
s
,
_
,
err
:=
p
.
Typer
.
ObjectKinds
(
obj
);
err
=
=
nil
{
// TODO: this is wrong, it assumes that meta knows about all Kinds - should take a RESTMapper
// TODO: this is wrong, it assumes that meta knows about all Kinds - should take a RESTMapper
_
,
resource
:=
meta
.
KindToResource
(
*
gvk
)
_
,
resource
:=
meta
.
KindToResource
(
gvks
[
0
])
fmt
.
Fprintf
(
w
,
"%s/%s
\n
"
,
resource
.
Resource
,
name
)
fmt
.
Fprintf
(
w
,
"%s/%s
\n
"
,
resource
.
Resource
,
name
)
}
else
{
}
else
{
fmt
.
Fprintf
(
w
,
"<unknown>/%s
\n
"
,
name
)
fmt
.
Fprintf
(
w
,
"<unknown>/%s
\n
"
,
name
)
...
...
pkg/kubectl/resource_printer_test.go
View file @
c6961d6f
...
@@ -466,7 +466,7 @@ func TestPrinters(t *testing.T) {
...
@@ -466,7 +466,7 @@ func TestPrinters(t *testing.T) {
"template2"
:
templatePrinter2
,
"template2"
:
templatePrinter2
,
"jsonpath"
:
jsonpathPrinter
,
"jsonpath"
:
jsonpathPrinter
,
"name"
:
&
NamePrinter
{
"name"
:
&
NamePrinter
{
Typer
:
runtime
.
ObjectTyperToTyper
(
api
.
Scheme
)
,
Typer
:
api
.
Scheme
,
Decoder
:
api
.
Codecs
.
UniversalDecoder
(),
Decoder
:
api
.
Codecs
.
UniversalDecoder
(),
},
},
}
}
...
...
pkg/registry/registrytest/etcd.go
View file @
c6961d6f
...
@@ -152,10 +152,11 @@ func (t *Tester) TestWatch(valid runtime.Object, labelsPass, labelsFail []labels
...
@@ -152,10 +152,11 @@ func (t *Tester) TestWatch(valid runtime.Object, labelsPass, labelsFail []labels
// =============================================================================
// =============================================================================
// get codec based on runtime.Object
// get codec based on runtime.Object
func
getCodec
(
obj
runtime
.
Object
)
(
runtime
.
Codec
,
error
)
{
func
getCodec
(
obj
runtime
.
Object
)
(
runtime
.
Codec
,
error
)
{
fqKind
,
err
:=
api
.
Scheme
.
ObjectKind
(
obj
)
fqKind
s
,
_
,
err
:=
api
.
Scheme
.
ObjectKinds
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"unexpected encoding error: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"unexpected encoding error: %v"
,
err
)
}
}
fqKind
:=
fqKinds
[
0
]
// TODO: caesarxuchao: we should detect which group an object belongs to
// TODO: caesarxuchao: we should detect which group an object belongs to
// by using the version returned by Schem.ObjectVersionAndKind() once we
// by using the version returned by Schem.ObjectVersionAndKind() once we
// split the schemes for internal objects.
// split the schemes for internal objects.
...
...
pkg/runtime/codec.go
View file @
c6961d6f
...
@@ -78,13 +78,13 @@ func EncodeOrDie(e Encoder, obj Object) string {
...
@@ -78,13 +78,13 @@ func EncodeOrDie(e Encoder, obj Object) string {
// UseOrCreateObject returns obj if the canonical ObjectKind returned by the provided typer matches gvk, or
// UseOrCreateObject returns obj if the canonical ObjectKind returned by the provided typer matches gvk, or
// invokes the ObjectCreator to instantiate a new gvk. Returns an error if the typer cannot find the object.
// invokes the ObjectCreator to instantiate a new gvk. Returns an error if the typer cannot find the object.
func
UseOrCreateObject
(
t
Typer
,
c
ObjectCreater
,
gvk
unversioned
.
GroupVersionKind
,
obj
Object
)
(
Object
,
error
)
{
func
UseOrCreateObject
(
t
Object
Typer
,
c
ObjectCreater
,
gvk
unversioned
.
GroupVersionKind
,
obj
Object
)
(
Object
,
error
)
{
if
obj
!=
nil
{
if
obj
!=
nil
{
into
,
_
,
err
:=
t
.
ObjectKind
(
obj
)
into
,
_
,
err
:=
t
.
ObjectKind
s
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
if
gvk
==
*
into
{
if
gvk
==
into
[
0
]
{
return
obj
,
nil
return
obj
,
nil
}
}
}
}
...
@@ -116,7 +116,7 @@ func (n NoopDecoder) Decode(data []byte, gvk *unversioned.GroupVersionKind, into
...
@@ -116,7 +116,7 @@ func (n NoopDecoder) Decode(data []byte, gvk *unversioned.GroupVersionKind, into
// NewParameterCodec creates a ParameterCodec capable of transforming url values into versioned objects and back.
// NewParameterCodec creates a ParameterCodec capable of transforming url values into versioned objects and back.
func
NewParameterCodec
(
scheme
*
Scheme
)
ParameterCodec
{
func
NewParameterCodec
(
scheme
*
Scheme
)
ParameterCodec
{
return
&
parameterCodec
{
return
&
parameterCodec
{
typer
:
ObjectTyperToTyper
(
scheme
)
,
typer
:
scheme
,
convertor
:
scheme
,
convertor
:
scheme
,
creator
:
scheme
,
creator
:
scheme
,
}
}
...
@@ -124,7 +124,7 @@ func NewParameterCodec(scheme *Scheme) ParameterCodec {
...
@@ -124,7 +124,7 @@ func NewParameterCodec(scheme *Scheme) ParameterCodec {
// parameterCodec implements conversion to and from query parameters and objects.
// parameterCodec implements conversion to and from query parameters and objects.
type
parameterCodec
struct
{
type
parameterCodec
struct
{
typer
Typer
typer
Object
Typer
convertor
ObjectConvertor
convertor
ObjectConvertor
creator
ObjectCreater
creator
ObjectCreater
}
}
...
@@ -137,10 +137,11 @@ func (c *parameterCodec) DecodeParameters(parameters url.Values, from unversione
...
@@ -137,10 +137,11 @@ func (c *parameterCodec) DecodeParameters(parameters url.Values, from unversione
if
len
(
parameters
)
==
0
{
if
len
(
parameters
)
==
0
{
return
nil
return
nil
}
}
targetGVK
,
_
,
err
:=
c
.
typer
.
ObjectKind
(
into
)
targetGVK
s
,
_
,
err
:=
c
.
typer
.
ObjectKinds
(
into
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
targetGVK
:=
targetGVKs
[
0
]
if
targetGVK
.
GroupVersion
()
==
from
{
if
targetGVK
.
GroupVersion
()
==
from
{
return
c
.
convertor
.
Convert
(
&
parameters
,
into
)
return
c
.
convertor
.
Convert
(
&
parameters
,
into
)
}
}
...
@@ -157,10 +158,11 @@ func (c *parameterCodec) DecodeParameters(parameters url.Values, from unversione
...
@@ -157,10 +158,11 @@ func (c *parameterCodec) DecodeParameters(parameters url.Values, from unversione
// EncodeParameters converts the provided object into the to version, then converts that object to url.Values.
// EncodeParameters converts the provided object into the to version, then converts that object to url.Values.
// Returns an error if conversion is not possible.
// Returns an error if conversion is not possible.
func
(
c
*
parameterCodec
)
EncodeParameters
(
obj
Object
,
to
unversioned
.
GroupVersion
)
(
url
.
Values
,
error
)
{
func
(
c
*
parameterCodec
)
EncodeParameters
(
obj
Object
,
to
unversioned
.
GroupVersion
)
(
url
.
Values
,
error
)
{
gvk
,
_
,
err
:=
c
.
typer
.
ObjectKind
(
obj
)
gvk
s
,
_
,
err
:=
c
.
typer
.
ObjectKinds
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
gvk
:=
gvks
[
0
]
if
to
!=
gvk
.
GroupVersion
()
{
if
to
!=
gvk
.
GroupVersion
()
{
out
,
err
:=
c
.
convertor
.
ConvertToVersion
(
obj
,
to
)
out
,
err
:=
c
.
convertor
.
ConvertToVersion
(
obj
,
to
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/runtime/helper.go
View file @
c6961d6f
...
@@ -26,28 +26,6 @@ import (
...
@@ -26,28 +26,6 @@ import (
"k8s.io/kubernetes/pkg/util/errors"
"k8s.io/kubernetes/pkg/util/errors"
)
)
type
objectTyperToTyper
struct
{
typer
ObjectTyper
}
func
(
t
objectTyperToTyper
)
ObjectKind
(
obj
Object
)
(
*
unversioned
.
GroupVersionKind
,
bool
,
error
)
{
gvk
,
err
:=
t
.
typer
.
ObjectKind
(
obj
)
if
err
!=
nil
{
return
nil
,
false
,
err
}
unversionedType
,
ok
:=
t
.
typer
.
IsUnversioned
(
obj
)
if
!
ok
{
// ObjectTyper violates its contract
return
nil
,
false
,
fmt
.
Errorf
(
"typer returned a kind for %v, but then reported it was not in the scheme with IsUnversioned"
,
reflect
.
TypeOf
(
obj
))
}
return
&
gvk
,
unversionedType
,
nil
}
// ObjectTyperToTyper casts the old typer interface to the new typer interface
func
ObjectTyperToTyper
(
typer
ObjectTyper
)
Typer
{
return
objectTyperToTyper
{
typer
:
typer
}
}
// unsafeObjectConvertor implements ObjectConvertor using the unsafe conversion path.
// unsafeObjectConvertor implements ObjectConvertor using the unsafe conversion path.
type
unsafeObjectConvertor
struct
{
type
unsafeObjectConvertor
struct
{
*
Scheme
*
Scheme
...
@@ -195,19 +173,9 @@ type MultiObjectTyper []ObjectTyper
...
@@ -195,19 +173,9 @@ type MultiObjectTyper []ObjectTyper
var
_
ObjectTyper
=
MultiObjectTyper
{}
var
_
ObjectTyper
=
MultiObjectTyper
{}
func
(
m
MultiObjectTyper
)
ObjectKind
(
obj
Object
)
(
gvk
unversioned
.
GroupVersionKind
,
err
error
)
{
func
(
m
MultiObjectTyper
)
ObjectKinds
(
obj
Object
)
(
gvks
[]
unversioned
.
GroupVersionKind
,
unversionedType
bool
,
err
error
)
{
for
_
,
t
:=
range
m
{
gvk
,
err
=
t
.
ObjectKind
(
obj
)
if
err
==
nil
{
return
}
}
return
}
func
(
m
MultiObjectTyper
)
ObjectKinds
(
obj
Object
)
(
gvks
[]
unversioned
.
GroupVersionKind
,
err
error
)
{
for
_
,
t
:=
range
m
{
for
_
,
t
:=
range
m
{
gvks
,
err
=
t
.
ObjectKinds
(
obj
)
gvks
,
unversionedType
,
err
=
t
.
ObjectKinds
(
obj
)
if
err
==
nil
{
if
err
==
nil
{
return
return
}
}
...
@@ -224,15 +192,6 @@ func (m MultiObjectTyper) Recognizes(gvk unversioned.GroupVersionKind) bool {
...
@@ -224,15 +192,6 @@ func (m MultiObjectTyper) Recognizes(gvk unversioned.GroupVersionKind) bool {
return
false
return
false
}
}
func
(
m
MultiObjectTyper
)
IsUnversioned
(
obj
Object
)
(
bool
,
bool
)
{
for
_
,
t
:=
range
m
{
if
unversioned
,
ok
:=
t
.
IsUnversioned
(
obj
);
ok
{
return
unversioned
,
true
}
}
return
false
,
false
}
// SetZeroValue would set the object of objPtr to zero value of its type.
// SetZeroValue would set the object of objPtr to zero value of its type.
func
SetZeroValue
(
objPtr
Object
)
error
{
func
SetZeroValue
(
objPtr
Object
)
error
{
v
,
err
:=
conversion
.
EnforcePtr
(
objPtr
)
v
,
err
:=
conversion
.
EnforcePtr
(
objPtr
)
...
...
pkg/runtime/interfaces.go
View file @
c6961d6f
...
@@ -30,15 +30,6 @@ const (
...
@@ -30,15 +30,6 @@ const (
APIVersionInternal
=
"__internal"
APIVersionInternal
=
"__internal"
)
)
// Typer retrieves information about an object's group, version, and kind.
type
Typer
interface
{
// ObjectKind returns the version and kind of the provided object, or an
// error if the object is not recognized (IsNotRegisteredError will return true).
// It returns whether the object is considered unversioned at the same time.
// TODO: align the signature of ObjectTyper with this interface
ObjectKind
(
Object
)
(
*
unversioned
.
GroupVersionKind
,
bool
,
error
)
}
type
Encoder
interface
{
type
Encoder
interface
{
// EncodeToStream writes an object to a stream. Override versions may be provided for each group
// EncodeToStream writes an object to a stream. Override versions may be provided for each group
// that enforce a certain versioning. Implementations may return errors if the versions are incompatible,
// that enforce a certain versioning. Implementations may return errors if the versions are incompatible,
...
@@ -178,20 +169,14 @@ type ObjectConvertor interface {
...
@@ -178,20 +169,14 @@ type ObjectConvertor interface {
// ObjectTyper contains methods for extracting the APIVersion and Kind
// ObjectTyper contains methods for extracting the APIVersion and Kind
// of objects.
// of objects.
type
ObjectTyper
interface
{
type
ObjectTyper
interface
{
// ObjectKind returns the default group,version,kind of the provided object, or an
// ObjectKinds returns the all possible group,version,kind of the provided object, true if
// error if the object is not recognized (IsNotRegisteredError will return true).
// the object is unversioned, or an error if the object is not recognized
ObjectKind
(
Object
)
(
unversioned
.
GroupVersionKind
,
error
)
// (IsNotRegisteredError will return true).
// ObjectKinds returns the all possible group,version,kind of the provided object, or an
ObjectKinds
(
Object
)
([]
unversioned
.
GroupVersionKind
,
bool
,
error
)
// error if the object is not recognized (IsNotRegisteredError will return true).
ObjectKinds
(
Object
)
([]
unversioned
.
GroupVersionKind
,
error
)
// Recognizes returns true if the scheme is able to handle the provided version and kind,
// Recognizes returns true if the scheme is able to handle the provided version and kind,
// or more precisely that the provided version is a possible conversion or decoding
// or more precisely that the provided version is a possible conversion or decoding
// target.
// target.
Recognizes
(
gvk
unversioned
.
GroupVersionKind
)
bool
Recognizes
(
gvk
unversioned
.
GroupVersionKind
)
bool
// IsUnversioned returns true if the provided object is considered unversioned and thus
// should have Version and Group suppressed in the output. If the object is not recognized
// in the scheme, ok is false.
IsUnversioned
(
Object
)
(
unversioned
bool
,
ok
bool
)
}
}
// ObjectCreater contains methods for instantiating an object by kind and version.
// ObjectCreater contains methods for instantiating an object by kind and version.
...
...
pkg/runtime/scheme.go
View file @
c6961d6f
...
@@ -211,31 +211,32 @@ func (s *Scheme) KnownTypes(gv unversioned.GroupVersion) map[string]reflect.Type
...
@@ -211,31 +211,32 @@ func (s *Scheme) KnownTypes(gv unversioned.GroupVersion) map[string]reflect.Type
return
types
return
types
}
}
// ObjectKind returns the group,version,kind of the go object
,
// ObjectKind returns the group,version,kind of the go object
and true if this object
// or an error if it's not a pointer or is unregistered.
//
is considered unversioned,
or an error if it's not a pointer or is unregistered.
func
(
s
*
Scheme
)
ObjectKind
(
obj
Object
)
(
unversioned
.
GroupVersionKind
,
error
)
{
func
(
s
*
Scheme
)
ObjectKind
(
obj
Object
)
(
unversioned
.
GroupVersionKind
,
bool
,
error
)
{
gvks
,
err
:=
s
.
ObjectKinds
(
obj
)
gvks
,
unversionedType
,
err
:=
s
.
ObjectKinds
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
unversioned
.
GroupVersionKind
{},
err
return
unversioned
.
GroupVersionKind
{},
false
,
err
}
}
return
gvks
[
0
],
nil
return
gvks
[
0
],
unversionedType
,
nil
}
}
// ObjectKinds returns all possible group,version,kind of the go object,
// ObjectKinds returns all possible group,version,kind of the go object,
true if the
// or an error if it's not a pointer or is unregistered.
// o
bject is considered unversioned, o
r an error if it's not a pointer or is unregistered.
func
(
s
*
Scheme
)
ObjectKinds
(
obj
Object
)
([]
unversioned
.
GroupVersionKind
,
error
)
{
func
(
s
*
Scheme
)
ObjectKinds
(
obj
Object
)
([]
unversioned
.
GroupVersionKind
,
bool
,
error
)
{
v
,
err
:=
conversion
.
EnforcePtr
(
obj
)
v
,
err
:=
conversion
.
EnforcePtr
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
t
:=
v
.
Type
()
t
:=
v
.
Type
()
gvks
,
ok
:=
s
.
typeToGVK
[
t
]
gvks
,
ok
:=
s
.
typeToGVK
[
t
]
if
!
ok
{
if
!
ok
{
return
nil
,
&
notRegisteredErr
{
t
:
t
}
return
nil
,
false
,
&
notRegisteredErr
{
t
:
t
}
}
}
_
,
unversionedType
:=
s
.
unversionedTypes
[
t
]
return
gvks
,
nil
return
gvks
,
unversionedType
,
nil
}
}
// Recognizes returns true if the scheme is able to handle the provided group,version,kind
// Recognizes returns true if the scheme is able to handle the provided group,version,kind
...
@@ -439,13 +440,13 @@ func (s *Scheme) Convert(in, out interface{}) error {
...
@@ -439,13 +440,13 @@ func (s *Scheme) Convert(in, out interface{}) error {
inVersion
:=
unversioned
.
GroupVersion
{
Group
:
"unknown"
,
Version
:
"unknown"
}
inVersion
:=
unversioned
.
GroupVersion
{
Group
:
"unknown"
,
Version
:
"unknown"
}
outVersion
:=
unversioned
.
GroupVersion
{
Group
:
"unknown"
,
Version
:
"unknown"
}
outVersion
:=
unversioned
.
GroupVersion
{
Group
:
"unknown"
,
Version
:
"unknown"
}
if
inObj
,
ok
:=
in
.
(
Object
);
ok
{
if
inObj
,
ok
:=
in
.
(
Object
);
ok
{
if
gvk
,
err
:=
s
.
ObjectKind
(
inObj
);
err
==
nil
{
if
gvk
s
,
_
,
err
:=
s
.
ObjectKinds
(
inObj
);
err
==
nil
{
inVersion
=
gvk
.
GroupVersion
()
inVersion
=
gvk
s
[
0
]
.
GroupVersion
()
}
}
}
}
if
outObj
,
ok
:=
out
.
(
Object
);
ok
{
if
outObj
,
ok
:=
out
.
(
Object
);
ok
{
if
gvk
,
err
:=
s
.
ObjectKind
(
outObj
);
err
==
nil
{
if
gvk
s
,
_
,
err
:=
s
.
ObjectKinds
(
outObj
);
err
==
nil
{
outVersion
=
gvk
.
GroupVersion
()
outVersion
=
gvk
s
[
0
]
.
GroupVersion
()
}
}
}
}
flags
,
meta
:=
s
.
generateConvertMeta
(
inVersion
,
outVersion
,
in
)
flags
,
meta
:=
s
.
generateConvertMeta
(
inVersion
,
outVersion
,
in
)
...
@@ -504,7 +505,7 @@ func (s *Scheme) ConvertToVersion(in Object, outVersion unversioned.GroupVersion
...
@@ -504,7 +505,7 @@ func (s *Scheme) ConvertToVersion(in Object, outVersion unversioned.GroupVersion
outKind
:=
outVersion
.
WithKind
(
kind
.
Kind
)
outKind
:=
outVersion
.
WithKind
(
kind
.
Kind
)
inKind
,
err
:=
s
.
ObjectKind
(
in
)
inKind
s
,
_
,
err
:=
s
.
ObjectKinds
(
in
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -514,7 +515,7 @@ func (s *Scheme) ConvertToVersion(in Object, outVersion unversioned.GroupVersion
...
@@ -514,7 +515,7 @@ func (s *Scheme) ConvertToVersion(in Object, outVersion unversioned.GroupVersion
return
nil
,
err
return
nil
,
err
}
}
flags
,
meta
:=
s
.
generateConvertMeta
(
inKind
.
GroupVersion
(),
outVersion
,
in
)
flags
,
meta
:=
s
.
generateConvertMeta
(
inKind
s
[
0
]
.
GroupVersion
(),
outVersion
,
in
)
if
err
:=
s
.
converter
.
Convert
(
in
,
out
,
flags
,
meta
);
err
!=
nil
{
if
err
:=
s
.
converter
.
Convert
(
in
,
out
,
flags
,
meta
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -603,8 +604,11 @@ func setTargetVersion(obj Object, raw *Scheme, gv unversioned.GroupVersion) {
...
@@ -603,8 +604,11 @@ func setTargetVersion(obj Object, raw *Scheme, gv unversioned.GroupVersion) {
obj
.
GetObjectKind
()
.
SetGroupVersionKind
(
unversioned
.
GroupVersionKind
{})
obj
.
GetObjectKind
()
.
SetGroupVersionKind
(
unversioned
.
GroupVersionKind
{})
return
return
}
}
gvk
,
_
:=
raw
.
ObjectKind
(
obj
)
if
gvks
,
_
,
_
:=
raw
.
ObjectKinds
(
obj
);
len
(
gvks
)
>
0
{
obj
.
GetObjectKind
()
.
SetGroupVersionKind
(
unversioned
.
GroupVersionKind
{
Group
:
gv
.
Group
,
Version
:
gv
.
Version
,
Kind
:
gvk
.
Kind
})
obj
.
GetObjectKind
()
.
SetGroupVersionKind
(
unversioned
.
GroupVersionKind
{
Group
:
gv
.
Group
,
Version
:
gv
.
Version
,
Kind
:
gvks
[
0
]
.
Kind
})
}
else
{
obj
.
GetObjectKind
()
.
SetGroupVersionKind
(
unversioned
.
GroupVersionKind
{
Group
:
gv
.
Group
,
Version
:
gv
.
Version
})
}
}
}
// setTargetKind sets the kind on an object, taking into account whether the target kind is the internal version.
// setTargetKind sets the kind on an object, taking into account whether the target kind is the internal version.
...
...
pkg/runtime/scheme_test.go
View file @
c6961d6f
...
@@ -354,10 +354,11 @@ func TestUnversionedTypes(t *testing.T) {
...
@@ -354,10 +354,11 @@ func TestUnversionedTypes(t *testing.T) {
t
.
Fatalf
(
"type not unversioned and in scheme: %t %t"
,
unv
,
ok
)
t
.
Fatalf
(
"type not unversioned and in scheme: %t %t"
,
unv
,
ok
)
}
}
kind
,
err
:=
scheme
.
ObjectKind
(
&
InternalSimple
{})
kind
s
,
_
,
err
:=
scheme
.
ObjectKinds
(
&
InternalSimple
{})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
kind
:=
kinds
[
0
]
if
kind
!=
externalGV
.
WithKind
(
"InternalSimple"
)
{
if
kind
!=
externalGV
.
WithKind
(
"InternalSimple"
)
{
t
.
Fatalf
(
"unexpected: %#v"
,
kind
)
t
.
Fatalf
(
"unexpected: %#v"
,
kind
)
}
}
...
...
pkg/runtime/serializer/codec_factory.go
View file @
c6961d6f
...
@@ -58,9 +58,9 @@ type serializerType struct {
...
@@ -58,9 +58,9 @@ type serializerType struct {
}
}
func
newSerializersForScheme
(
scheme
*
runtime
.
Scheme
,
mf
json
.
MetaFactory
)
[]
serializerType
{
func
newSerializersForScheme
(
scheme
*
runtime
.
Scheme
,
mf
json
.
MetaFactory
)
[]
serializerType
{
jsonSerializer
:=
json
.
NewSerializer
(
mf
,
scheme
,
runtime
.
ObjectTyperToTyper
(
scheme
)
,
false
)
jsonSerializer
:=
json
.
NewSerializer
(
mf
,
scheme
,
scheme
,
false
)
jsonPrettySerializer
:=
json
.
NewSerializer
(
mf
,
scheme
,
runtime
.
ObjectTyperToTyper
(
scheme
)
,
true
)
jsonPrettySerializer
:=
json
.
NewSerializer
(
mf
,
scheme
,
scheme
,
true
)
yamlSerializer
:=
json
.
NewYAMLSerializer
(
mf
,
scheme
,
runtime
.
ObjectTyperToTyper
(
scheme
)
)
yamlSerializer
:=
json
.
NewYAMLSerializer
(
mf
,
scheme
,
scheme
)
serializers
:=
[]
serializerType
{
serializers
:=
[]
serializerType
{
{
{
...
...
pkg/runtime/serializer/json/json.go
View file @
c6961d6f
...
@@ -31,7 +31,7 @@ import (
...
@@ -31,7 +31,7 @@ import (
// NewSerializer creates a JSON serializer that handles encoding versioned objects into the proper JSON form. If typer
// NewSerializer creates a JSON serializer that handles encoding versioned objects into the proper JSON form. If typer
// is not nil, the object has the group, version, and kind fields set.
// is not nil, the object has the group, version, and kind fields set.
func
NewSerializer
(
meta
MetaFactory
,
creater
runtime
.
ObjectCreater
,
typer
runtime
.
Typer
,
pretty
bool
)
*
Serializer
{
func
NewSerializer
(
meta
MetaFactory
,
creater
runtime
.
ObjectCreater
,
typer
runtime
.
Object
Typer
,
pretty
bool
)
*
Serializer
{
return
&
Serializer
{
return
&
Serializer
{
meta
:
meta
,
meta
:
meta
,
creater
:
creater
,
creater
:
creater
,
...
@@ -44,7 +44,7 @@ func NewSerializer(meta MetaFactory, creater runtime.ObjectCreater, typer runtim
...
@@ -44,7 +44,7 @@ func NewSerializer(meta MetaFactory, creater runtime.ObjectCreater, typer runtim
// NewYAMLSerializer creates a YAML serializer that handles encoding versioned objects into the proper YAML form. If typer
// NewYAMLSerializer creates a YAML serializer that handles encoding versioned objects into the proper YAML form. If typer
// is not nil, the object has the group, version, and kind fields set. This serializer supports only the subset of YAML that
// is not nil, the object has the group, version, and kind fields set. This serializer supports only the subset of YAML that
// matches JSON, and will error if constructs are used that do not serialize to JSON.
// matches JSON, and will error if constructs are used that do not serialize to JSON.
func
NewYAMLSerializer
(
meta
MetaFactory
,
creater
runtime
.
ObjectCreater
,
typer
runtime
.
Typer
)
*
Serializer
{
func
NewYAMLSerializer
(
meta
MetaFactory
,
creater
runtime
.
ObjectCreater
,
typer
runtime
.
Object
Typer
)
*
Serializer
{
return
&
Serializer
{
return
&
Serializer
{
meta
:
meta
,
meta
:
meta
,
creater
:
creater
,
creater
:
creater
,
...
@@ -56,7 +56,7 @@ func NewYAMLSerializer(meta MetaFactory, creater runtime.ObjectCreater, typer ru
...
@@ -56,7 +56,7 @@ func NewYAMLSerializer(meta MetaFactory, creater runtime.ObjectCreater, typer ru
type
Serializer
struct
{
type
Serializer
struct
{
meta
MetaFactory
meta
MetaFactory
creater
runtime
.
ObjectCreater
creater
runtime
.
ObjectCreater
typer
runtime
.
Typer
typer
runtime
.
Object
Typer
yaml
bool
yaml
bool
pretty
bool
pretty
bool
}
}
...
@@ -116,7 +116,7 @@ func (s *Serializer) Decode(originalData []byte, gvk *unversioned.GroupVersionKi
...
@@ -116,7 +116,7 @@ func (s *Serializer) Decode(originalData []byte, gvk *unversioned.GroupVersionKi
}
}
if
into
!=
nil
{
if
into
!=
nil
{
type
d
,
_
,
err
:=
s
.
typer
.
ObjectKind
(
into
)
type
s
,
_
,
err
:=
s
.
typer
.
ObjectKinds
(
into
)
switch
{
switch
{
case
runtime
.
IsNotRegisteredError
(
err
)
:
case
runtime
.
IsNotRegisteredError
(
err
)
:
if
err
:=
codec
.
NewDecoderBytes
(
data
,
new
(
codec
.
JsonHandle
))
.
Decode
(
into
);
err
!=
nil
{
if
err
:=
codec
.
NewDecoderBytes
(
data
,
new
(
codec
.
JsonHandle
))
.
Decode
(
into
);
err
!=
nil
{
...
@@ -126,6 +126,7 @@ func (s *Serializer) Decode(originalData []byte, gvk *unversioned.GroupVersionKi
...
@@ -126,6 +126,7 @@ func (s *Serializer) Decode(originalData []byte, gvk *unversioned.GroupVersionKi
case
err
!=
nil
:
case
err
!=
nil
:
return
nil
,
actual
,
err
return
nil
,
actual
,
err
default
:
default
:
typed
:=
types
[
0
]
if
len
(
actual
.
Kind
)
==
0
{
if
len
(
actual
.
Kind
)
==
0
{
actual
.
Kind
=
typed
.
Kind
actual
.
Kind
=
typed
.
Kind
}
}
...
...
pkg/runtime/serializer/json/json_test.go
View file @
c6961d6f
...
@@ -41,7 +41,7 @@ func (d *testDecodable) GroupVersionKind() unversioned.GroupVersionKind {
...
@@ -41,7 +41,7 @@ func (d *testDecodable) GroupVersionKind() unversioned.GroupVersionKind {
func
TestDecode
(
t
*
testing
.
T
)
{
func
TestDecode
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
testCases
:=
[]
struct
{
creater
runtime
.
ObjectCreater
creater
runtime
.
ObjectCreater
typer
runtime
.
Typer
typer
runtime
.
Object
Typer
yaml
bool
yaml
bool
pretty
bool
pretty
bool
...
@@ -260,6 +260,13 @@ type mockTyper struct {
...
@@ -260,6 +260,13 @@ type mockTyper struct {
err
error
err
error
}
}
func
(
t
*
mockTyper
)
ObjectKind
(
obj
runtime
.
Object
)
(
*
unversioned
.
GroupVersionKind
,
bool
,
error
)
{
func
(
t
*
mockTyper
)
ObjectKinds
(
obj
runtime
.
Object
)
([]
unversioned
.
GroupVersionKind
,
bool
,
error
)
{
return
t
.
gvk
,
false
,
t
.
err
if
t
.
gvk
==
nil
{
return
nil
,
false
,
t
.
err
}
return
[]
unversioned
.
GroupVersionKind
{
*
t
.
gvk
},
false
,
t
.
err
}
func
(
t
*
mockTyper
)
Recognizes
(
_
unversioned
.
GroupVersionKind
)
bool
{
return
false
}
}
pkg/runtime/serializer/protobuf/protobuf.go
View file @
c6961d6f
...
@@ -59,7 +59,7 @@ func IsNotMarshalable(err error) bool {
...
@@ -59,7 +59,7 @@ func IsNotMarshalable(err error) bool {
// as-is (any type info passed with the object will be used).
// as-is (any type info passed with the object will be used).
//
//
// This encoding scheme is experimental, and is subject to change at any time.
// This encoding scheme is experimental, and is subject to change at any time.
func
NewSerializer
(
creater
runtime
.
ObjectCreater
,
typer
runtime
.
Typer
,
defaultContentType
string
)
*
Serializer
{
func
NewSerializer
(
creater
runtime
.
ObjectCreater
,
typer
runtime
.
Object
Typer
,
defaultContentType
string
)
*
Serializer
{
return
&
Serializer
{
return
&
Serializer
{
prefix
:
protoEncodingPrefix
,
prefix
:
protoEncodingPrefix
,
creater
:
creater
,
creater
:
creater
,
...
@@ -71,7 +71,7 @@ func NewSerializer(creater runtime.ObjectCreater, typer runtime.Typer, defaultCo
...
@@ -71,7 +71,7 @@ func NewSerializer(creater runtime.ObjectCreater, typer runtime.Typer, defaultCo
type
Serializer
struct
{
type
Serializer
struct
{
prefix
[]
byte
prefix
[]
byte
creater
runtime
.
ObjectCreater
creater
runtime
.
ObjectCreater
typer
runtime
.
Typer
typer
runtime
.
Object
Typer
contentType
string
contentType
string
}
}
...
@@ -131,7 +131,7 @@ func (s *Serializer) Decode(originalData []byte, gvk *unversioned.GroupVersionKi
...
@@ -131,7 +131,7 @@ func (s *Serializer) Decode(originalData []byte, gvk *unversioned.GroupVersionKi
}
}
if
into
!=
nil
{
if
into
!=
nil
{
type
d
,
_
,
err
:=
s
.
typer
.
ObjectKind
(
into
)
type
s
,
_
,
err
:=
s
.
typer
.
ObjectKinds
(
into
)
switch
{
switch
{
case
runtime
.
IsNotRegisteredError
(
err
)
:
case
runtime
.
IsNotRegisteredError
(
err
)
:
pb
,
ok
:=
into
.
(
proto
.
Message
)
pb
,
ok
:=
into
.
(
proto
.
Message
)
...
@@ -145,12 +145,12 @@ func (s *Serializer) Decode(originalData []byte, gvk *unversioned.GroupVersionKi
...
@@ -145,12 +145,12 @@ func (s *Serializer) Decode(originalData []byte, gvk *unversioned.GroupVersionKi
case
err
!=
nil
:
case
err
!=
nil
:
return
nil
,
&
actual
,
err
return
nil
,
&
actual
,
err
default
:
default
:
copyKindDefaults
(
&
actual
,
typed
)
copyKindDefaults
(
&
actual
,
&
types
[
0
]
)
// if the result of defaulting did not set a version or group, ensure that at least group is set
// if the result of defaulting did not set a version or group, ensure that at least group is set
// (copyKindDefaults will not assign Group if version is already set). This guarantees that the group
// (copyKindDefaults will not assign Group if version is already set). This guarantees that the group
// of into is set if there is no better information from the caller or object.
// of into is set if there is no better information from the caller or object.
if
len
(
actual
.
Version
)
==
0
&&
len
(
actual
.
Group
)
==
0
{
if
len
(
actual
.
Version
)
==
0
&&
len
(
actual
.
Group
)
==
0
{
actual
.
Group
=
type
d
.
Group
actual
.
Group
=
type
s
[
0
]
.
Group
}
}
}
}
}
}
...
@@ -277,7 +277,7 @@ func estimateUnknownSize(unk *runtime.Unknown, byteSize uint64) uint64 {
...
@@ -277,7 +277,7 @@ func estimateUnknownSize(unk *runtime.Unknown, byteSize uint64) uint64 {
// encoded object, and thus is not self describing (callers must know what type is being described in order to decode).
// encoded object, and thus is not self describing (callers must know what type is being described in order to decode).
//
//
// This encoding scheme is experimental, and is subject to change at any time.
// This encoding scheme is experimental, and is subject to change at any time.
func
NewRawSerializer
(
creater
runtime
.
ObjectCreater
,
typer
runtime
.
Typer
,
defaultContentType
string
)
*
RawSerializer
{
func
NewRawSerializer
(
creater
runtime
.
ObjectCreater
,
typer
runtime
.
Object
Typer
,
defaultContentType
string
)
*
RawSerializer
{
return
&
RawSerializer
{
return
&
RawSerializer
{
creater
:
creater
,
creater
:
creater
,
typer
:
typer
,
typer
:
typer
,
...
@@ -289,7 +289,7 @@ func NewRawSerializer(creater runtime.ObjectCreater, typer runtime.Typer, defaul
...
@@ -289,7 +289,7 @@ func NewRawSerializer(creater runtime.ObjectCreater, typer runtime.Typer, defaul
// type).
// type).
type
RawSerializer
struct
{
type
RawSerializer
struct
{
creater
runtime
.
ObjectCreater
creater
runtime
.
ObjectCreater
typer
runtime
.
Typer
typer
runtime
.
Object
Typer
contentType
string
contentType
string
}
}
...
@@ -337,7 +337,7 @@ func (s *RawSerializer) Decode(originalData []byte, gvk *unversioned.GroupVersio
...
@@ -337,7 +337,7 @@ func (s *RawSerializer) Decode(originalData []byte, gvk *unversioned.GroupVersio
return
intoUnknown
,
actual
,
nil
return
intoUnknown
,
actual
,
nil
}
}
type
d
,
_
,
err
:=
s
.
typer
.
ObjectKind
(
into
)
type
s
,
_
,
err
:=
s
.
typer
.
ObjectKinds
(
into
)
switch
{
switch
{
case
runtime
.
IsNotRegisteredError
(
err
)
:
case
runtime
.
IsNotRegisteredError
(
err
)
:
pb
,
ok
:=
into
.
(
proto
.
Message
)
pb
,
ok
:=
into
.
(
proto
.
Message
)
...
@@ -351,12 +351,12 @@ func (s *RawSerializer) Decode(originalData []byte, gvk *unversioned.GroupVersio
...
@@ -351,12 +351,12 @@ func (s *RawSerializer) Decode(originalData []byte, gvk *unversioned.GroupVersio
case
err
!=
nil
:
case
err
!=
nil
:
return
nil
,
actual
,
err
return
nil
,
actual
,
err
default
:
default
:
copyKindDefaults
(
actual
,
typed
)
copyKindDefaults
(
actual
,
&
types
[
0
]
)
// if the result of defaulting did not set a version or group, ensure that at least group is set
// if the result of defaulting did not set a version or group, ensure that at least group is set
// (copyKindDefaults will not assign Group if version is already set). This guarantees that the group
// (copyKindDefaults will not assign Group if version is already set). This guarantees that the group
// of into is set if there is no better information from the caller or object.
// of into is set if there is no better information from the caller or object.
if
len
(
actual
.
Version
)
==
0
&&
len
(
actual
.
Group
)
==
0
{
if
len
(
actual
.
Version
)
==
0
&&
len
(
actual
.
Group
)
==
0
{
actual
.
Group
=
type
d
.
Group
actual
.
Group
=
type
s
[
0
]
.
Group
}
}
}
}
...
@@ -371,7 +371,7 @@ func (s *RawSerializer) Decode(originalData []byte, gvk *unversioned.GroupVersio
...
@@ -371,7 +371,7 @@ func (s *RawSerializer) Decode(originalData []byte, gvk *unversioned.GroupVersio
}
}
// unmarshalToObject is the common code between decode in the raw and normal serializer.
// unmarshalToObject is the common code between decode in the raw and normal serializer.
func
unmarshalToObject
(
typer
runtime
.
Typer
,
creater
runtime
.
ObjectCreater
,
actual
*
unversioned
.
GroupVersionKind
,
into
runtime
.
Object
,
data
[]
byte
)
(
runtime
.
Object
,
*
unversioned
.
GroupVersionKind
,
error
)
{
func
unmarshalToObject
(
typer
runtime
.
Object
Typer
,
creater
runtime
.
ObjectCreater
,
actual
*
unversioned
.
GroupVersionKind
,
into
runtime
.
Object
,
data
[]
byte
)
(
runtime
.
Object
,
*
unversioned
.
GroupVersionKind
,
error
)
{
// use the target if necessary
// use the target if necessary
obj
,
err
:=
runtime
.
UseOrCreateObject
(
typer
,
creater
,
*
actual
,
into
)
obj
,
err
:=
runtime
.
UseOrCreateObject
(
typer
,
creater
,
*
actual
,
into
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/runtime/serializer/protobuf/protobuf_test.go
View file @
c6961d6f
...
@@ -323,7 +323,7 @@ func TestDecodeObjects(t *testing.T) {
...
@@ -323,7 +323,7 @@ func TestDecodeObjects(t *testing.T) {
}
}
for
i
,
test
:=
range
testCases
{
for
i
,
test
:=
range
testCases
{
s
:=
protobuf
.
NewSerializer
(
api
.
Scheme
,
runtime
.
ObjectTyperToTyper
(
api
.
Scheme
)
,
"application/protobuf"
)
s
:=
protobuf
.
NewSerializer
(
api
.
Scheme
,
api
.
Scheme
,
"application/protobuf"
)
obj
,
err
:=
runtime
.
Decode
(
s
,
test
.
data
)
obj
,
err
:=
runtime
.
Decode
(
s
,
test
.
data
)
switch
{
switch
{
...
...
pkg/runtime/serializer/protobuf_extension.go
View file @
c6961d6f
...
@@ -31,8 +31,8 @@ const (
...
@@ -31,8 +31,8 @@ const (
)
)
func
protobufSerializer
(
scheme
*
runtime
.
Scheme
)
(
serializerType
,
bool
)
{
func
protobufSerializer
(
scheme
*
runtime
.
Scheme
)
(
serializerType
,
bool
)
{
serializer
:=
protobuf
.
NewSerializer
(
scheme
,
runtime
.
ObjectTyperToTyper
(
scheme
)
,
contentTypeProtobuf
)
serializer
:=
protobuf
.
NewSerializer
(
scheme
,
scheme
,
contentTypeProtobuf
)
raw
:=
protobuf
.
NewRawSerializer
(
scheme
,
runtime
.
ObjectTyperToTyper
(
scheme
)
,
contentTypeProtobuf
)
raw
:=
protobuf
.
NewRawSerializer
(
scheme
,
scheme
,
contentTypeProtobuf
)
return
serializerType
{
return
serializerType
{
AcceptContentTypes
:
[]
string
{
contentTypeProtobuf
},
AcceptContentTypes
:
[]
string
{
contentTypeProtobuf
},
ContentType
:
contentTypeProtobuf
,
ContentType
:
contentTypeProtobuf
,
...
...
pkg/runtime/serializer/recognizer/recognizer_test.go
View file @
c6961d6f
...
@@ -32,8 +32,8 @@ func TestRecognizer(t *testing.T) {
...
@@ -32,8 +32,8 @@ func TestRecognizer(t *testing.T) {
s
:=
runtime
.
NewScheme
()
s
:=
runtime
.
NewScheme
()
s
.
AddKnownTypes
(
unversioned
.
GroupVersion
{
Version
:
"v1"
},
&
A
{})
s
.
AddKnownTypes
(
unversioned
.
GroupVersion
{
Version
:
"v1"
},
&
A
{})
d
:=
NewDecoder
(
d
:=
NewDecoder
(
json
.
NewSerializer
(
json
.
DefaultMetaFactory
,
s
,
runtime
.
ObjectTyperToTyper
(
s
)
,
false
),
json
.
NewSerializer
(
json
.
DefaultMetaFactory
,
s
,
s
,
false
),
json
.
NewYAMLSerializer
(
json
.
DefaultMetaFactory
,
s
,
runtime
.
ObjectTyperToTyper
(
s
)
),
json
.
NewYAMLSerializer
(
json
.
DefaultMetaFactory
,
s
,
s
),
)
)
out
,
_
,
err
:=
d
.
Decode
([]
byte
(
`
out
,
_
,
err
:=
d
.
Decode
([]
byte
(
`
kind: A
kind: A
...
...
pkg/runtime/serializer/versioning/versioning.go
View file @
c6961d6f
...
@@ -71,7 +71,7 @@ func NewCodecForScheme(
...
@@ -71,7 +71,7 @@ func NewCodecForScheme(
encodeVersion
[]
unversioned
.
GroupVersion
,
encodeVersion
[]
unversioned
.
GroupVersion
,
decodeVersion
[]
unversioned
.
GroupVersion
,
decodeVersion
[]
unversioned
.
GroupVersion
,
)
runtime
.
Codec
{
)
runtime
.
Codec
{
return
NewCodec
(
encoder
,
decoder
,
runtime
.
UnsafeObjectConvertor
(
scheme
),
scheme
,
scheme
,
runtime
.
ObjectTyperToTyper
(
scheme
)
,
encodeVersion
,
decodeVersion
)
return
NewCodec
(
encoder
,
decoder
,
runtime
.
UnsafeObjectConvertor
(
scheme
),
scheme
,
scheme
,
scheme
,
encodeVersion
,
decodeVersion
)
}
}
// NewCodec takes objects in their internal versions and converts them to external versions before
// NewCodec takes objects in their internal versions and converts them to external versions before
...
@@ -83,7 +83,7 @@ func NewCodec(
...
@@ -83,7 +83,7 @@ func NewCodec(
convertor
runtime
.
ObjectConvertor
,
convertor
runtime
.
ObjectConvertor
,
creater
runtime
.
ObjectCreater
,
creater
runtime
.
ObjectCreater
,
copier
runtime
.
ObjectCopier
,
copier
runtime
.
ObjectCopier
,
typer
runtime
.
Typer
,
typer
runtime
.
Object
Typer
,
encodeVersion
[]
unversioned
.
GroupVersion
,
encodeVersion
[]
unversioned
.
GroupVersion
,
decodeVersion
[]
unversioned
.
GroupVersion
,
decodeVersion
[]
unversioned
.
GroupVersion
,
)
runtime
.
Codec
{
)
runtime
.
Codec
{
...
@@ -130,7 +130,7 @@ type codec struct {
...
@@ -130,7 +130,7 @@ type codec struct {
convertor
runtime
.
ObjectConvertor
convertor
runtime
.
ObjectConvertor
creater
runtime
.
ObjectCreater
creater
runtime
.
ObjectCreater
copier
runtime
.
ObjectCopier
copier
runtime
.
ObjectCopier
typer
runtime
.
Typer
typer
runtime
.
Object
Typer
encodeVersion
map
[
string
]
unversioned
.
GroupVersion
encodeVersion
map
[
string
]
unversioned
.
GroupVersion
decodeVersion
map
[
string
]
unversioned
.
GroupVersion
decodeVersion
map
[
string
]
unversioned
.
GroupVersion
...
@@ -228,15 +228,16 @@ func (c *codec) EncodeToStream(obj runtime.Object, w io.Writer, overrides ...unv
...
@@ -228,15 +228,16 @@ func (c *codec) EncodeToStream(obj runtime.Object, w io.Writer, overrides ...unv
if
_
,
ok
:=
obj
.
(
*
runtime
.
Unknown
);
ok
{
if
_
,
ok
:=
obj
.
(
*
runtime
.
Unknown
);
ok
{
return
c
.
encoder
.
EncodeToStream
(
obj
,
w
,
overrides
...
)
return
c
.
encoder
.
EncodeToStream
(
obj
,
w
,
overrides
...
)
}
}
gvk
,
isUnversioned
,
err
:=
c
.
typer
.
ObjectKind
(
obj
)
gvk
s
,
isUnversioned
,
err
:=
c
.
typer
.
ObjectKinds
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
gvk
:=
gvks
[
0
]
if
(
c
.
encodeVersion
==
nil
&&
len
(
overrides
)
==
0
)
||
isUnversioned
{
if
(
c
.
encodeVersion
==
nil
&&
len
(
overrides
)
==
0
)
||
isUnversioned
{
objectKind
:=
obj
.
GetObjectKind
()
objectKind
:=
obj
.
GetObjectKind
()
old
:=
objectKind
.
GroupVersionKind
()
old
:=
objectKind
.
GroupVersionKind
()
objectKind
.
SetGroupVersionKind
(
*
gvk
)
objectKind
.
SetGroupVersionKind
(
gvk
)
err
=
c
.
encoder
.
EncodeToStream
(
obj
,
w
,
overrides
...
)
err
=
c
.
encoder
.
EncodeToStream
(
obj
,
w
,
overrides
...
)
objectKind
.
SetGroupVersionKind
(
old
)
objectKind
.
SetGroupVersionKind
(
old
)
return
err
return
err
...
...
pkg/runtime/serializer/versioning/versioning_test.go
View file @
c6961d6f
...
@@ -49,7 +49,7 @@ func TestDecode(t *testing.T) {
...
@@ -49,7 +49,7 @@ func TestDecode(t *testing.T) {
convertor
runtime
.
ObjectConvertor
convertor
runtime
.
ObjectConvertor
creater
runtime
.
ObjectCreater
creater
runtime
.
ObjectCreater
copier
runtime
.
ObjectCopier
copier
runtime
.
ObjectCopier
typer
runtime
.
Typer
typer
runtime
.
Object
Typer
yaml
bool
yaml
bool
pretty
bool
pretty
bool
...
...
plugin/pkg/scheduler/api/latest/latest.go
View file @
c6961d6f
...
@@ -42,7 +42,7 @@ var Versions = []string{"v1"}
...
@@ -42,7 +42,7 @@ var Versions = []string{"v1"}
var
Codec
runtime
.
Codec
var
Codec
runtime
.
Codec
func
init
()
{
func
init
()
{
jsonSerializer
:=
json
.
NewSerializer
(
json
.
DefaultMetaFactory
,
api
.
Scheme
,
runtime
.
ObjectTyperToTyper
(
api
.
Scheme
)
,
true
)
jsonSerializer
:=
json
.
NewSerializer
(
json
.
DefaultMetaFactory
,
api
.
Scheme
,
api
.
Scheme
,
true
)
Codec
=
versioning
.
NewCodecForScheme
(
Codec
=
versioning
.
NewCodecForScheme
(
api
.
Scheme
,
api
.
Scheme
,
jsonSerializer
,
jsonSerializer
,
...
...
test/integration/framework/serializer.go
View file @
c6961d6f
...
@@ -59,9 +59,9 @@ func (s *wrappedSerializer) UniversalDeserializer() runtime.Decoder {
...
@@ -59,9 +59,9 @@ func (s *wrappedSerializer) UniversalDeserializer() runtime.Decoder {
}
}
func
(
s
*
wrappedSerializer
)
EncoderForVersion
(
encoder
runtime
.
Encoder
,
gv
unversioned
.
GroupVersion
)
runtime
.
Encoder
{
func
(
s
*
wrappedSerializer
)
EncoderForVersion
(
encoder
runtime
.
Encoder
,
gv
unversioned
.
GroupVersion
)
runtime
.
Encoder
{
return
versioning
.
NewCodec
(
encoder
,
nil
,
s
.
scheme
,
s
.
scheme
,
s
.
scheme
,
runtime
.
ObjectTyperToTyper
(
s
.
scheme
)
,
[]
unversioned
.
GroupVersion
{
gv
},
nil
)
return
versioning
.
NewCodec
(
encoder
,
nil
,
s
.
scheme
,
s
.
scheme
,
s
.
scheme
,
s
.
scheme
,
[]
unversioned
.
GroupVersion
{
gv
},
nil
)
}
}
func
(
s
*
wrappedSerializer
)
DecoderToVersion
(
decoder
runtime
.
Decoder
,
gv
unversioned
.
GroupVersion
)
runtime
.
Decoder
{
func
(
s
*
wrappedSerializer
)
DecoderToVersion
(
decoder
runtime
.
Decoder
,
gv
unversioned
.
GroupVersion
)
runtime
.
Decoder
{
return
versioning
.
NewCodec
(
nil
,
decoder
,
s
.
scheme
,
s
.
scheme
,
s
.
scheme
,
runtime
.
ObjectTyperToTyper
(
s
.
scheme
)
,
nil
,
[]
unversioned
.
GroupVersion
{
gv
})
return
versioning
.
NewCodec
(
nil
,
decoder
,
s
.
scheme
,
s
.
scheme
,
s
.
scheme
,
s
.
scheme
,
nil
,
[]
unversioned
.
GroupVersion
{
gv
})
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment