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
556f8ccb
Commit
556f8ccb
authored
Feb 22, 2018
by
Dr. Stefan Schimanski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apimachinery duct tape: in versioning codec avoid conversion roundtrip for same GVK
parent
91662210
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
5 deletions
+12
-5
versioning.go
...machinery/pkg/runtime/serializer/versioning/versioning.go
+12
-5
No files found.
staging/src/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go
View file @
556f8ccb
...
@@ -18,6 +18,7 @@ package versioning
...
@@ -18,6 +18,7 @@ package versioning
import
(
import
(
"io"
"io"
"reflect"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/schema"
...
@@ -166,15 +167,21 @@ func (c *codec) Decode(data []byte, defaultGVK *schema.GroupVersionKind, into ru
...
@@ -166,15 +167,21 @@ func (c *codec) Decode(data []byte, defaultGVK *schema.GroupVersionKind, into ru
// Encode ensures the provided object is output in the appropriate group and version, invoking
// Encode ensures the provided object is output in the appropriate group and version, invoking
// conversion if necessary. Unversioned objects (according to the ObjectTyper) are output as is.
// conversion if necessary. Unversioned objects (according to the ObjectTyper) are output as is.
func
(
c
*
codec
)
Encode
(
obj
runtime
.
Object
,
w
io
.
Writer
)
error
{
func
(
c
*
codec
)
Encode
(
obj
runtime
.
Object
,
w
io
.
Writer
)
error
{
switch
obj
.
(
type
)
{
switch
obj
:=
obj
.
(
type
)
{
case
*
runtime
.
Unknown
:
case
*
runtime
.
Unknown
:
return
c
.
encoder
.
Encode
(
obj
,
w
)
return
c
.
encoder
.
Encode
(
obj
,
w
)
case
runtime
.
Unstructured
:
// avoid conversion roundtrip if GVK is the right one already
objGVK
:=
obj
.
GetObjectKind
()
.
GroupVersionKind
()
targetGVK
,
ok
:=
c
.
encodeVersion
.
KindForGroupVersionKinds
([]
schema
.
GroupVersionKind
{
objGVK
})
if
!
ok
{
return
runtime
.
NewNotRegisteredErrForTarget
(
reflect
.
TypeOf
(
obj
)
.
Elem
(),
c
.
encodeVersion
)
}
if
targetGVK
==
objGVK
{
return
c
.
encoder
.
Encode
(
obj
,
w
)
}
}
}
// Note: for runtime.Unstructured, the typer will return the GVK in the object and we will do conversion as normal below.
// For the normal runtime.Scheme converter the conversion will be a no-op for Unstructured. For CustomResources
// the conversion will actually do something.
gvks
,
isUnversioned
,
err
:=
c
.
typer
.
ObjectKinds
(
obj
)
gvks
,
isUnversioned
,
err
:=
c
.
typer
.
ObjectKinds
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
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