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
db515f47
Commit
db515f47
authored
May 11, 2016
by
Kris
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Provide a dumb ObjectConverter for Unstructured
parent
6cd2fa6b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
0 deletions
+38
-0
unstructured.go
pkg/runtime/unstructured.go
+38
-0
No files found.
pkg/runtime/unstructured.go
View file @
db515f47
...
@@ -18,6 +18,8 @@ package runtime
...
@@ -18,6 +18,8 @@ package runtime
import
(
import
(
gojson
"encoding/json"
gojson
"encoding/json"
"errors"
"fmt"
"io"
"io"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
...
@@ -146,3 +148,39 @@ func (s unstructuredJSONScheme) decodeToList(data []byte, list *UnstructuredList
...
@@ -146,3 +148,39 @@ func (s unstructuredJSONScheme) decodeToList(data []byte, list *UnstructuredList
}
}
return
nil
return
nil
}
}
// UnstructuredObjectConverter is an ObjectConverter for use with
// Unstructured objects. Since it has no schema or type information,
// it will only succeed for no-op conversions. This is provided as a
// sane implementation for APIs that require an object converter.
type
UnstructuredObjectConverter
struct
{}
func
(
UnstructuredObjectConverter
)
Convert
(
in
,
out
interface
{})
error
{
unstructIn
,
ok
:=
in
.
(
*
Unstructured
)
if
!
ok
{
return
fmt
.
Errorf
(
"input type %T in not valid for unstructured conversion"
,
in
)
}
unstructOut
,
ok
:=
out
.
(
*
Unstructured
)
if
!
ok
{
return
fmt
.
Errorf
(
"output type %T in not valid for unstructured conversion"
,
out
)
}
// maybe deep copy the map? It is documented in the
// ObjectConverter interface that this function is not
// guaranteeed to not mutate the input. Or maybe set the input
// object to nil.
unstructOut
.
Object
=
unstructIn
.
Object
return
nil
}
func
(
UnstructuredObjectConverter
)
ConvertToVersion
(
in
Object
,
outVersion
unversioned
.
GroupVersion
)
(
Object
,
error
)
{
if
gvk
:=
in
.
GetObjectKind
()
.
GroupVersionKind
();
gvk
.
GroupVersion
()
!=
outVersion
{
return
nil
,
errors
.
New
(
"unstructured converter cannot convert versions"
)
}
return
in
,
nil
}
func
(
UnstructuredObjectConverter
)
ConvertFieldLabel
(
version
,
kind
,
label
,
value
string
)
(
string
,
string
,
error
)
{
return
""
,
""
,
errors
.
New
(
"unstructured cannot convert field labels"
)
}
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