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
89585237
Commit
89585237
authored
Mar 17, 2016
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename RawJSON to Raw in runtime.RawExtension and add ContentType & ContentEncoding.
parent
6bd5ecc1
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
65 additions
and
52 deletions
+65
-52
help.go
pkg/api/meta/help.go
+3
-3
help_test.go
pkg/api/meta/help_test.go
+2
-2
rest.go
pkg/api/rest/rest.go
+1
-1
visitor.go
pkg/kubectl/resource/visitor.go
+5
-4
resource_printer_test.go
pkg/kubectl/resource_printer_test.go
+2
-2
sorting_printer_test.go
pkg/kubectl/sorting_printer_test.go
+12
-12
deep_copy_generated.go
pkg/runtime/deep_copy_generated.go
+3
-3
embedded.go
pkg/runtime/embedded.go
+4
-4
embedded_test.go
pkg/runtime/embedded_test.go
+2
-2
extension.go
pkg/runtime/extension.go
+4
-3
extension_test.go
pkg/runtime/extension_test.go
+1
-1
protobuf.go
pkg/runtime/protobuf/protobuf.go
+11
-4
types.go
pkg/runtime/types.go
+12
-8
decoder.go
pkg/watch/json/decoder.go
+1
-1
decoder_test.go
pkg/watch/json/decoder_test.go
+1
-1
types.go
pkg/watch/json/types.go
+1
-1
No files found.
pkg/api/meta/help.go
View file @
89585237
...
...
@@ -76,9 +76,9 @@ func ExtractList(obj runtime.Object) ([]runtime.Object, error) {
switch
{
case
item
.
Object
!=
nil
:
list
[
i
]
=
item
.
Object
case
item
.
Raw
JSON
!=
nil
:
// TODO: Set ContentEncoding and ContentType.
list
[
i
]
=
&
runtime
.
Unknown
{
Raw
:
item
.
Raw
JSON
}
case
item
.
Raw
!=
nil
:
// TODO: Set ContentEncoding and ContentType
correctly
.
list
[
i
]
=
&
runtime
.
Unknown
{
Raw
:
item
.
Raw
}
default
:
list
[
i
]
=
nil
}
...
...
pkg/api/meta/help_test.go
View file @
89585237
...
...
@@ -114,8 +114,8 @@ func TestExtractListGeneric(t *testing.T) {
func
TestExtractListGenericV1
(
t
*
testing
.
T
)
{
pl
:=
&
v1
.
List
{
Items
:
[]
runtime
.
RawExtension
{
{
Raw
JSON
:
[]
byte
(
"foo"
)},
{
Raw
JSON
:
[]
byte
(
"bar"
)},
{
Raw
:
[]
byte
(
"foo"
)},
{
Raw
:
[]
byte
(
"bar"
)},
{
Object
:
&
v1
.
Pod
{
ObjectMeta
:
v1
.
ObjectMeta
{
Name
:
"other"
}}},
},
}
...
...
pkg/api/rest/rest.go
View file @
89585237
...
...
@@ -57,7 +57,7 @@ type Storage interface {
// KindProvider specifies a different kind for its API than for its internal storage. This is necessary for external
// objects that are not compiled into the api server. For such objects, there is no in-memory representation for
// the object, so they must be represented as generic objects (e.g.
RawJSON
), but when we present the object as part of
// the object, so they must be represented as generic objects (e.g.
runtime.Unknown
), but when we present the object as part of
// API discovery we want to present the specific kind, not the generic internal representation.
type
KindProvider
interface
{
Kind
()
string
...
...
pkg/kubectl/resource/visitor.go
View file @
89585237
...
...
@@ -474,14 +474,15 @@ func (v *StreamVisitor) Visit(fn VisitorFunc) error {
}
return
err
}
ext
.
RawJSON
=
bytes
.
TrimSpace
(
ext
.
RawJSON
)
if
len
(
ext
.
RawJSON
)
==
0
||
bytes
.
Equal
(
ext
.
RawJSON
,
[]
byte
(
"null"
))
{
// TODO: This needs to be able to handle object in other encodings and schemas.
ext
.
Raw
=
bytes
.
TrimSpace
(
ext
.
Raw
)
if
len
(
ext
.
Raw
)
==
0
||
bytes
.
Equal
(
ext
.
Raw
,
[]
byte
(
"null"
))
{
continue
}
if
err
:=
ValidateSchema
(
ext
.
Raw
JSON
,
v
.
Schema
);
err
!=
nil
{
if
err
:=
ValidateSchema
(
ext
.
Raw
,
v
.
Schema
);
err
!=
nil
{
return
fmt
.
Errorf
(
"error validating %q: %v"
,
v
.
Source
,
err
)
}
info
,
err
:=
v
.
InfoForData
(
ext
.
Raw
JSON
,
v
.
Source
)
info
,
err
:=
v
.
InfoForData
(
ext
.
Raw
,
v
.
Source
)
if
err
!=
nil
{
if
fnErr
:=
fn
(
info
,
err
);
fnErr
!=
nil
{
return
fnErr
...
...
pkg/kubectl/resource_printer_test.go
View file @
89585237
...
...
@@ -299,10 +299,10 @@ func TestNamePrinter(t *testing.T) {
},
Items
:
[]
runtime
.
RawExtension
{
{
Raw
JSON
:
[]
byte
(
`{"kind": "Pod", "apiVersion": "v1", "metadata": { "name": "foo"}}`
),
Raw
:
[]
byte
(
`{"kind": "Pod", "apiVersion": "v1", "metadata": { "name": "foo"}}`
),
},
{
Raw
JSON
:
[]
byte
(
`{"kind": "Pod", "apiVersion": "v1", "metadata": { "name": "bar"}}`
),
Raw
:
[]
byte
(
`{"kind": "Pod", "apiVersion": "v1", "metadata": { "name": "bar"}}`
),
},
},
},
...
...
pkg/kubectl/sorting_printer_test.go
View file @
89585237
...
...
@@ -190,16 +190,16 @@ func TestSortingPrinter(t *testing.T) {
name
:
"v1.List in order"
,
obj
:
&
api
.
List
{
Items
:
[]
runtime
.
RawExtension
{
{
Raw
JSON
:
encodeOrDie
(
a
)},
{
Raw
JSON
:
encodeOrDie
(
b
)},
{
Raw
JSON
:
encodeOrDie
(
c
)},
{
Raw
:
encodeOrDie
(
a
)},
{
Raw
:
encodeOrDie
(
b
)},
{
Raw
:
encodeOrDie
(
c
)},
},
},
sort
:
&
api
.
List
{
Items
:
[]
runtime
.
RawExtension
{
{
Raw
JSON
:
encodeOrDie
(
a
)},
{
Raw
JSON
:
encodeOrDie
(
b
)},
{
Raw
JSON
:
encodeOrDie
(
c
)},
{
Raw
:
encodeOrDie
(
a
)},
{
Raw
:
encodeOrDie
(
b
)},
{
Raw
:
encodeOrDie
(
c
)},
},
},
field
:
"{.metadata.name}"
,
...
...
@@ -208,16 +208,16 @@ func TestSortingPrinter(t *testing.T) {
name
:
"v1.List in reverse"
,
obj
:
&
api
.
List
{
Items
:
[]
runtime
.
RawExtension
{
{
Raw
JSON
:
encodeOrDie
(
c
)},
{
Raw
JSON
:
encodeOrDie
(
b
)},
{
Raw
JSON
:
encodeOrDie
(
a
)},
{
Raw
:
encodeOrDie
(
c
)},
{
Raw
:
encodeOrDie
(
b
)},
{
Raw
:
encodeOrDie
(
a
)},
},
},
sort
:
&
api
.
List
{
Items
:
[]
runtime
.
RawExtension
{
{
Raw
JSON
:
encodeOrDie
(
a
)},
{
Raw
JSON
:
encodeOrDie
(
b
)},
{
Raw
JSON
:
encodeOrDie
(
c
)},
{
Raw
:
encodeOrDie
(
a
)},
{
Raw
:
encodeOrDie
(
b
)},
{
Raw
:
encodeOrDie
(
c
)},
},
},
field
:
"{.metadata.name}"
,
...
...
pkg/runtime/deep_copy_generated.go
View file @
89585237
...
...
@@ -27,12 +27,12 @@ import (
)
func
DeepCopy_runtime_RawExtension
(
in
RawExtension
,
out
*
RawExtension
,
c
*
conversion
.
Cloner
)
error
{
if
in
.
Raw
JSON
!=
nil
{
in
,
out
:=
in
.
Raw
JSON
,
&
out
.
RawJSON
if
in
.
Raw
!=
nil
{
in
,
out
:=
in
.
Raw
,
&
out
.
Raw
*
out
=
make
([]
byte
,
len
(
in
))
copy
(
*
out
,
in
)
}
else
{
out
.
Raw
JSON
=
nil
out
.
Raw
=
nil
}
if
in
.
Object
==
nil
{
out
.
Object
=
nil
...
...
pkg/runtime/embedded.go
View file @
89585237
...
...
@@ -92,19 +92,19 @@ func DefaultEmbeddedConversions() []interface{} {
return
[]
interface
{}{
func
(
in
*
Object
,
out
*
RawExtension
,
s
conversion
.
Scope
)
error
{
if
in
==
nil
{
out
.
Raw
JSON
=
[]
byte
(
"null"
)
out
.
Raw
=
[]
byte
(
"null"
)
return
nil
}
obj
:=
*
in
if
unk
,
ok
:=
obj
.
(
*
Unknown
);
ok
{
if
unk
.
Raw
!=
nil
{
out
.
Raw
JSON
=
unk
.
Raw
out
.
Raw
=
unk
.
Raw
return
nil
}
obj
=
out
.
Object
}
if
obj
==
nil
{
out
.
Raw
JSON
=
nil
out
.
Raw
=
nil
return
nil
}
out
.
Object
=
obj
...
...
@@ -116,7 +116,7 @@ func DefaultEmbeddedConversions() []interface{} {
*
out
=
in
.
Object
return
nil
}
data
:=
in
.
Raw
JSON
data
:=
in
.
Raw
if
len
(
data
)
==
0
||
(
len
(
data
)
==
4
&&
string
(
data
)
==
"null"
)
{
*
out
=
nil
return
nil
...
...
pkg/runtime/embedded_test.go
View file @
89585237
...
...
@@ -138,7 +138,7 @@ func TestArrayOfRuntimeObject(t *testing.T) {
if
err
:=
json
.
Unmarshal
(
wire
,
obj
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
t
.
Logf
(
"exact wire is: %s"
,
string
(
obj
.
Items
[
0
]
.
Raw
JSON
))
t
.
Logf
(
"exact wire is: %s"
,
string
(
obj
.
Items
[
0
]
.
Raw
))
items
[
3
]
=
&
ObjectTest
{
Items
:
innerItems
}
internal
.
Items
=
items
...
...
@@ -230,7 +230,7 @@ func TestNestedObject(t *testing.T) {
if
externalViaJSON
.
Kind
==
""
||
externalViaJSON
.
APIVersion
==
""
||
externalViaJSON
.
ID
!=
"outer"
{
t
.
Errorf
(
"Expected objects to have type info set, got %#v"
,
externalViaJSON
)
}
if
!
reflect
.
DeepEqual
(
externalViaJSON
.
EmptyObject
.
Raw
JSON
,
[]
byte
(
"null"
))
||
len
(
externalViaJSON
.
Object
.
RawJSON
)
==
0
{
if
!
reflect
.
DeepEqual
(
externalViaJSON
.
EmptyObject
.
Raw
,
[]
byte
(
"null"
))
||
len
(
externalViaJSON
.
Object
.
Raw
)
==
0
{
t
.
Errorf
(
"Expected deserialization of nested objects into bytes, got %#v"
,
externalViaJSON
)
}
...
...
pkg/runtime/extension.go
View file @
89585237
...
...
@@ -25,14 +25,14 @@ func (re *RawExtension) UnmarshalJSON(in []byte) error {
if
re
==
nil
{
return
errors
.
New
(
"runtime.RawExtension: UnmarshalJSON on nil pointer"
)
}
re
.
Raw
JSON
=
append
(
re
.
RawJSON
[
0
:
0
],
in
...
)
re
.
Raw
=
append
(
re
.
Raw
[
0
:
0
],
in
...
)
return
nil
}
// Marshal may get called on pointers or values, so implement MarshalJSON on value.
// http://stackoverflow.com/questions/21390979/custom-marshaljson-never-gets-called-in-go
func
(
re
RawExtension
)
MarshalJSON
()
([]
byte
,
error
)
{
if
re
.
Raw
JSON
==
nil
{
if
re
.
Raw
==
nil
{
// TODO: this is to support legacy behavior of JSONPrinter and YAMLPrinter, which
// expect to call json.Marshal on arbitrary versioned objects (even those not in
// the scheme). pkg/kubectl/resource#AsVersionedObjects and its interaction with
...
...
@@ -43,5 +43,6 @@ func (re RawExtension) MarshalJSON() ([]byte, error) {
}
return
[]
byte
(
"null"
),
nil
}
return
re
.
RawJSON
,
nil
// TODO: Check whether ContentType is actually JSON before returning it.
return
re
.
Raw
,
nil
}
pkg/runtime/extension_test.go
View file @
89585237
...
...
@@ -28,7 +28,7 @@ func TestEmbeddedRawExtensionMarshal(t *testing.T) {
Ext
runtime
.
RawExtension
}
extension
:=
test
{
Ext
:
runtime
.
RawExtension
{
Raw
JSON
:
[]
byte
(
`{"foo":"bar"}`
)}}
extension
:=
test
{
Ext
:
runtime
.
RawExtension
{
Raw
:
[]
byte
(
`{"foo":"bar"}`
)}}
data
,
err
:=
json
.
Marshal
(
extension
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
...
...
pkg/runtime/protobuf/protobuf.go
View file @
89585237
...
...
@@ -64,7 +64,10 @@ func (c codec) Decode(data []byte) (runtime.Object, error) {
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"runtime object is not a proto.Message: %v"
,
reflect
.
TypeOf
(
obj
))
}
if
err
:=
proto
.
Unmarshal
(
unknown
.
RawJSON
,
pobj
);
err
!=
nil
{
if
unknown
.
ContentType
!=
runtime
.
ContentTypeProtobuf
{
return
nil
,
fmt
.
Errorf
(
"unmarshal non-protobuf object with protobuf decoder"
)
}
if
err
:=
proto
.
Unmarshal
(
unknown
.
Raw
,
pobj
);
err
!=
nil
{
return
nil
,
err
}
if
unknown
.
APIVersion
!=
c
.
outputVersion
{
...
...
@@ -90,13 +93,16 @@ func (c codec) DecodeInto(data []byte, obj runtime.Object) error {
if
err
:=
proto
.
Unmarshal
(
data
,
unknown
);
err
!=
nil
{
return
err
}
if
unknown
.
ContentType
!=
runtime
.
ContentTypeProtobuf
{
return
nil
,
fmt
.
Errorf
(
"unmarshal non-protobuf object with protobuf decoder"
)
}
if
unknown
.
APIVersion
==
version
&&
unknown
.
Kind
==
kind
{
pobj
,
ok
:=
obj
.
(
proto
.
Message
)
if
!
ok
{
return
fmt
.
Errorf
(
"runtime object is not a proto.Message: %v"
,
reflect
.
TypeOf
(
obj
))
}
return
proto
.
Unmarshal
(
unknown
.
Raw
JSON
,
pobj
)
return
proto
.
Unmarshal
(
unknown
.
Raw
,
pobj
)
}
versioned
,
err
:=
c
.
creater
.
New
(
unknown
.
APIVersion
,
unknown
.
Kind
)
...
...
@@ -109,7 +115,7 @@ func (c codec) DecodeInto(data []byte, obj runtime.Object) error {
return
fmt
.
Errorf
(
"runtime object is not a proto.Message: %v"
,
reflect
.
TypeOf
(
obj
))
}
if
err
:=
proto
.
Unmarshal
(
unknown
.
Raw
JSON
,
pobj
);
err
!=
nil
{
if
err
:=
proto
.
Unmarshal
(
unknown
.
Raw
,
pobj
);
err
!=
nil
{
return
err
}
return
c
.
convertor
.
Convert
(
versioned
,
obj
)
...
...
@@ -149,7 +155,8 @@ func (c codec) Encode(obj runtime.Object) (data []byte, err error) {
Kind
:
kind
,
APIVersion
:
version
,
},
RawJSON
:
b
,
Raw
:
b
,
ContentType
:
runtime
.
ContentTypeProtobuf
,
})
.
Marshal
()
}
...
...
pkg/runtime/types.go
View file @
89585237
...
...
@@ -36,6 +36,12 @@ type TypeMeta struct {
Kind
string
`json:"kind,omitempty" yaml:"kind,omitempty"`
}
const
(
ContentTypeJSON
string
=
"application/json"
// TODO: Fix the value.
ContentTypeProtobuf
string
=
"application/protobuf"
)
// RawExtension is used to hold extensions in external versions.
//
// To use this, make a field which has RawExtension as its type in your external, versioned
...
...
@@ -80,17 +86,15 @@ type TypeMeta struct {
//
// +protobuf=true
type
RawExtension
struct
{
// RawJSON is the underlying serialization of this object.
RawJSON
[]
byte
// Raw is the underlying serialization of this object.
//
// TODO: Determine how to detect ContentType and ContentEncoding of 'Raw' data.
Raw
[]
byte
// Object can hold a representation of this extension - useful for working with versioned
// structs.
Object
Object
`json:"-"`
}
// TODO; Where should it be?
// TODO; What value it should have?
const
ContentTypeJSON
string
=
"application/json"
// Unknown allows api objects with unknown types to be passed-through. This can be used
// to deal with the API objects from a plug-in. Unknown objects still have functioning
// TypeMeta features-- kind, version, etc.
...
...
@@ -105,10 +109,10 @@ type Unknown struct {
// except for passing it through the system.
Raw
[]
byte
// ContentEncoding is encoding used to encode 'Raw' data.
// Unspecified mean no encoding.
// Unspecified mean
s
no encoding.
ContentEncoding
string
// ContentType is serialization method used to serialize 'Raw'.
//
TODO: Define what unspecified means
.
//
Unspecified means ContentTypeJSON
.
ContentType
string
}
...
...
pkg/watch/json/decoder.go
View file @
89585237
...
...
@@ -56,7 +56,7 @@ func (d *Decoder) Decode() (watch.EventType, runtime.Object, error) {
return
""
,
nil
,
fmt
.
Errorf
(
"got invalid watch event type: %v"
,
got
.
Type
)
}
obj
,
err
:=
runtime
.
Decode
(
d
.
codec
,
got
.
Object
.
Raw
JSON
)
obj
,
err
:=
runtime
.
Decode
(
d
.
codec
,
got
.
Object
.
Raw
)
if
err
!=
nil
{
return
""
,
nil
,
fmt
.
Errorf
(
"unable to decode watch event: %v"
,
err
)
}
...
...
pkg/watch/json/decoder_test.go
View file @
89585237
...
...
@@ -43,7 +43,7 @@ func TestDecoder(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error %v"
,
err
)
}
if
err
:=
encoder
.
Encode
(
&
WatchEvent
{
eventType
,
runtime
.
RawExtension
{
Raw
JSON
:
json
.
RawMessage
(
data
)}});
err
!=
nil
{
if
err
:=
encoder
.
Encode
(
&
WatchEvent
{
eventType
,
runtime
.
RawExtension
{
Raw
:
json
.
RawMessage
(
data
)}});
err
!=
nil
{
t
.
Errorf
(
"Unexpected error %v"
,
err
)
}
in
.
Close
()
...
...
pkg/watch/json/types.go
View file @
89585237
...
...
@@ -49,5 +49,5 @@ func Object(encoder runtime.Encoder, event *watch.Event) (interface{}, error) {
if
err
!=
nil
{
return
nil
,
err
}
return
&
WatchEvent
{
event
.
Type
,
runtime
.
RawExtension
{
Raw
JSON
:
json
.
RawMessage
(
data
)}},
nil
return
&
WatchEvent
{
event
.
Type
,
runtime
.
RawExtension
{
Raw
:
json
.
RawMessage
(
data
)}},
nil
}
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