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
b48cc43e
Commit
b48cc43e
authored
Apr 19, 2019
by
wojtekt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup content-type protobuf constants
parent
c1d27351
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
27 additions
and
31 deletions
+27
-31
serialization_proto_test.go
pkg/api/testing/serialization_proto_test.go
+3
-3
roundtrip.go
...io/apimachinery/pkg/api/apitesting/roundtrip/roundtrip.go
+2
-2
codec_factory.go
...s.io/apimachinery/pkg/runtime/serializer/codec_factory.go
+2
-2
protobuf.go
.../apimachinery/pkg/runtime/serializer/protobuf/protobuf.go
+14
-18
runtime_serializer_protobuf_protobuf_test.go
...ery/pkg/test/runtime_serializer_protobuf_protobuf_test.go
+5
-5
apiserver_test.go
test/integration/apiserver/apiserver_test.go
+1
-1
No files found.
pkg/api/testing/serialization_proto_test.go
View file @
b48cc43e
...
...
@@ -121,7 +121,7 @@ func TestProtobufRoundTrip(t *testing.T) {
func
BenchmarkEncodeCodecProtobuf
(
b
*
testing
.
B
)
{
items
:=
benchmarkItems
(
b
)
width
:=
len
(
items
)
s
:=
protobuf
.
NewSerializer
(
nil
,
nil
,
"application/arbitrary.content.type"
)
s
:=
protobuf
.
NewSerializer
(
nil
,
nil
)
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
if
_
,
err
:=
runtime
.
Encode
(
s
,
&
items
[
i
%
width
]);
err
!=
nil
{
...
...
@@ -142,7 +142,7 @@ func BenchmarkEncodeCodecFromInternalProtobuf(b *testing.B) {
b
.
Fatal
(
err
)
}
}
s
:=
protobuf
.
NewSerializer
(
nil
,
nil
,
"application/arbitrary.content.type"
)
s
:=
protobuf
.
NewSerializer
(
nil
,
nil
)
codec
:=
legacyscheme
.
Codecs
.
EncoderForVersion
(
s
,
v1
.
SchemeGroupVersion
)
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
...
...
@@ -170,7 +170,7 @@ func BenchmarkEncodeProtobufGeneratedMarshal(b *testing.B) {
func
BenchmarkDecodeCodecToInternalProtobuf
(
b
*
testing
.
B
)
{
items
:=
benchmarkItems
(
b
)
width
:=
len
(
items
)
s
:=
protobuf
.
NewSerializer
(
legacyscheme
.
Scheme
,
legacyscheme
.
Scheme
,
"application/arbitrary.content.type"
)
s
:=
protobuf
.
NewSerializer
(
legacyscheme
.
Scheme
,
legacyscheme
.
Scheme
)
encoder
:=
legacyscheme
.
Codecs
.
EncoderForVersion
(
s
,
v1
.
SchemeGroupVersion
)
var
encoded
[][]
byte
for
i
:=
range
items
{
...
...
staging/src/k8s.io/apimachinery/pkg/api/apitesting/roundtrip/roundtrip.go
View file @
b48cc43e
...
...
@@ -231,7 +231,7 @@ func roundTripToAllExternalVersions(t *testing.T, scheme *runtime.Scheme, codecF
// TODO remove this hack after we're past the intermediate steps
if
!
skipProtobuf
&&
externalGVK
.
Group
!=
"kubeadm.k8s.io"
{
s
:=
protobuf
.
NewSerializer
(
scheme
,
scheme
,
"application/arbitrary.content.type"
)
s
:=
protobuf
.
NewSerializer
(
scheme
,
scheme
)
protobufCodec
:=
codecFactory
.
CodecForVersions
(
s
,
s
,
externalGVK
.
GroupVersion
(),
nil
)
roundTrip
(
t
,
scheme
,
protobufCodec
,
object
)
}
...
...
@@ -260,7 +260,7 @@ func roundTripOfExternalType(t *testing.T, scheme *runtime.Scheme, codecFactory
// TODO remove this hack after we're past the intermediate steps
if
!
skipProtobuf
{
roundTrip
(
t
,
scheme
,
protobuf
.
NewSerializer
(
scheme
,
scheme
,
"application/protobuf"
),
object
)
roundTrip
(
t
,
scheme
,
protobuf
.
NewSerializer
(
scheme
,
scheme
),
object
)
}
}
...
...
staging/src/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go
View file @
b48cc43e
...
...
@@ -52,8 +52,8 @@ func newSerializersForScheme(scheme *runtime.Scheme, mf json.MetaFactory) []seri
jsonSerializer
:=
json
.
NewSerializer
(
mf
,
scheme
,
scheme
,
false
)
jsonPrettySerializer
:=
json
.
NewSerializer
(
mf
,
scheme
,
scheme
,
true
)
yamlSerializer
:=
json
.
NewYAMLSerializer
(
mf
,
scheme
,
scheme
)
serializer
:=
protobuf
.
NewSerializer
(
scheme
,
scheme
,
runtime
.
ContentTypeProtobuf
)
raw
:=
protobuf
.
NewRawSerializer
(
scheme
,
scheme
,
runtime
.
ContentTypeProtobuf
)
serializer
:=
protobuf
.
NewSerializer
(
scheme
,
scheme
)
raw
:=
protobuf
.
NewRawSerializer
(
scheme
,
scheme
)
serializers
:=
[]
serializerType
{
{
...
...
staging/src/k8s.io/apimachinery/pkg/runtime/serializer/protobuf/protobuf.go
View file @
b48cc43e
...
...
@@ -71,20 +71,18 @@ func IsNotMarshalable(err error) bool {
// 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.
func
NewSerializer
(
creater
runtime
.
ObjectCreater
,
typer
runtime
.
ObjectTyper
,
defaultContentType
string
)
*
Serializer
{
func
NewSerializer
(
creater
runtime
.
ObjectCreater
,
typer
runtime
.
ObjectTyper
)
*
Serializer
{
return
&
Serializer
{
prefix
:
protoEncodingPrefix
,
creater
:
creater
,
typer
:
typer
,
contentType
:
defaultContentType
,
prefix
:
protoEncodingPrefix
,
creater
:
creater
,
typer
:
typer
,
}
}
type
Serializer
struct
{
prefix
[]
byte
creater
runtime
.
ObjectCreater
typer
runtime
.
ObjectTyper
contentType
string
prefix
[]
byte
creater
runtime
.
ObjectCreater
typer
runtime
.
ObjectTyper
}
var
_
runtime
.
Serializer
=
&
Serializer
{}
...
...
@@ -138,7 +136,7 @@ func (s *Serializer) Decode(originalData []byte, gvk *schema.GroupVersionKind, i
if
intoUnknown
,
ok
:=
into
.
(
*
runtime
.
Unknown
);
ok
&&
intoUnknown
!=
nil
{
*
intoUnknown
=
unk
if
ok
,
_
,
_
:=
s
.
RecognizesData
(
bytes
.
NewBuffer
(
unk
.
Raw
));
ok
{
intoUnknown
.
ContentType
=
s
.
contentType
intoUnknown
.
ContentType
=
runtime
.
ContentTypeProtobuf
}
return
intoUnknown
,
&
actual
,
nil
}
...
...
@@ -303,20 +301,18 @@ 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).
//
// This encoding scheme is experimental, and is subject to change at any time.
func
NewRawSerializer
(
creater
runtime
.
ObjectCreater
,
typer
runtime
.
ObjectTyper
,
defaultContentType
string
)
*
RawSerializer
{
func
NewRawSerializer
(
creater
runtime
.
ObjectCreater
,
typer
runtime
.
ObjectTyper
)
*
RawSerializer
{
return
&
RawSerializer
{
creater
:
creater
,
typer
:
typer
,
contentType
:
defaultContentType
,
creater
:
creater
,
typer
:
typer
,
}
}
// RawSerializer encodes and decodes objects without adding a runtime.Unknown wrapper (objects are encoded without identifying
// type).
type
RawSerializer
struct
{
creater
runtime
.
ObjectCreater
typer
runtime
.
ObjectTyper
contentType
string
creater
runtime
.
ObjectCreater
typer
runtime
.
ObjectTyper
}
var
_
runtime
.
Serializer
=
&
RawSerializer
{}
...
...
@@ -358,7 +354,7 @@ func (s *RawSerializer) Decode(originalData []byte, gvk *schema.GroupVersionKind
if
intoUnknown
,
ok
:=
into
.
(
*
runtime
.
Unknown
);
ok
&&
intoUnknown
!=
nil
{
intoUnknown
.
Raw
=
data
intoUnknown
.
ContentEncoding
=
""
intoUnknown
.
ContentType
=
s
.
contentType
intoUnknown
.
ContentType
=
runtime
.
ContentTypeProtobuf
intoUnknown
.
SetGroupVersionKind
(
*
actual
)
return
intoUnknown
,
actual
,
nil
}
...
...
staging/src/k8s.io/apimachinery/pkg/test/runtime_serializer_protobuf_protobuf_test.go
View file @
b48cc43e
...
...
@@ -84,7 +84,7 @@ func (d *testBufferedMarshalable) DeepCopyObject() runtime.Object {
}
func
TestRecognize
(
t
*
testing
.
T
)
{
s
:=
protobuf
.
NewSerializer
(
nil
,
nil
,
"application/protobuf"
)
s
:=
protobuf
.
NewSerializer
(
nil
,
nil
)
ignores
:=
[][]
byte
{
nil
,
{},
...
...
@@ -172,7 +172,7 @@ func TestEncode(t *testing.T) {
}
for
i
,
test
:=
range
testCases
{
s
:=
protobuf
.
NewSerializer
(
nil
,
nil
,
"application/protobuf"
)
s
:=
protobuf
.
NewSerializer
(
nil
,
nil
)
data
,
err
:=
runtime
.
Encode
(
s
,
test
.
obj
)
switch
{
...
...
@@ -251,7 +251,7 @@ func TestProtobufDecode(t *testing.T) {
Kind
:
"test"
,
},
// content type is set because the prefix matches the content
ContentType
:
"application/protobuf"
,
ContentType
:
runtime
.
ContentTypeProtobuf
,
Raw
:
[]
byte
{
0x6b
,
0x38
,
0x73
,
0x00
,
0x01
,
0x02
,
0x03
},
},
data
:
wire2
,
...
...
@@ -259,7 +259,7 @@ func TestProtobufDecode(t *testing.T) {
}
for
i
,
test
:=
range
testCases
{
s
:=
protobuf
.
NewSerializer
(
nil
,
nil
,
"application/protobuf"
)
s
:=
protobuf
.
NewSerializer
(
nil
,
nil
)
unk
:=
&
runtime
.
Unknown
{}
err
:=
runtime
.
DecodeInto
(
s
,
test
.
data
,
unk
)
...
...
@@ -334,7 +334,7 @@ func TestDecodeObjects(t *testing.T) {
for
i
,
test
:=
range
testCases
{
scheme
.
AddKnownTypes
(
schema
.
GroupVersion
{
Version
:
"v1"
},
&
v1
.
Carp
{})
require
.
NoError
(
t
,
v1
.
AddToScheme
(
scheme
))
s
:=
protobuf
.
NewSerializer
(
scheme
,
scheme
,
"application/protobuf"
)
s
:=
protobuf
.
NewSerializer
(
scheme
,
scheme
)
obj
,
err
:=
runtime
.
Decode
(
s
,
test
.
data
)
switch
{
...
...
test/integration/apiserver/apiserver_test.go
View file @
b48cc43e
...
...
@@ -971,7 +971,7 @@ func expectPartialObjectMetaEvents(t *testing.T, d *json.Decoder, values ...stri
func
expectPartialObjectMetaEventsProtobuf
(
t
*
testing
.
T
,
r
io
.
Reader
,
values
...
string
)
{
scheme
:=
runtime
.
NewScheme
()
metav1
.
AddToGroupVersion
(
scheme
,
schema
.
GroupVersion
{
Version
:
"v1"
})
rs
:=
protobuf
.
NewRawSerializer
(
scheme
,
scheme
,
"application/vnd.kubernetes.protobuf"
)
rs
:=
protobuf
.
NewRawSerializer
(
scheme
,
scheme
)
d
:=
streaming
.
NewDecoder
(
protobuf
.
LengthDelimitedFramer
.
NewFrameReader
(
ioutil
.
NopCloser
(
r
)),
rs
,
...
...
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