Update godeps
This commit is contained in:
parent
423433bc5f
commit
701c5a0e30
482 changed files with 86915 additions and 19741 deletions
60
vendor/k8s.io/kubernetes/pkg/runtime/serializer/codec_factory.go
generated
vendored
60
vendor/k8s.io/kubernetes/pkg/runtime/serializer/codec_factory.go
generated
vendored
|
|
@ -17,6 +17,8 @@ limitations under the License.
|
|||
package serializer
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/runtime/serializer/json"
|
||||
|
|
@ -58,9 +60,9 @@ type serializerType struct {
|
|||
}
|
||||
|
||||
func newSerializersForScheme(scheme *runtime.Scheme, mf json.MetaFactory) []serializerType {
|
||||
jsonSerializer := json.NewSerializer(mf, scheme, runtime.ObjectTyperToTyper(scheme), false)
|
||||
jsonPrettySerializer := json.NewSerializer(mf, scheme, runtime.ObjectTyperToTyper(scheme), true)
|
||||
yamlSerializer := json.NewYAMLSerializer(mf, scheme, runtime.ObjectTyperToTyper(scheme))
|
||||
jsonSerializer := json.NewSerializer(mf, scheme, scheme, false)
|
||||
jsonPrettySerializer := json.NewSerializer(mf, scheme, scheme, true)
|
||||
yamlSerializer := json.NewYAMLSerializer(mf, scheme, scheme)
|
||||
|
||||
serializers := []serializerType{
|
||||
{
|
||||
|
|
@ -308,3 +310,55 @@ func (f CodecFactory) SerializerForFileExtension(extension string) (runtime.Seri
|
|||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// DirectCodecFactory provides methods for retrieving "DirectCodec"s, which do not do conversion.
|
||||
type DirectCodecFactory struct {
|
||||
CodecFactory
|
||||
}
|
||||
|
||||
// EncoderForVersion returns an encoder that does not do conversion. gv is ignored.
|
||||
func (f DirectCodecFactory) EncoderForVersion(serializer runtime.Encoder, gv unversioned.GroupVersion) runtime.Encoder {
|
||||
return DirectCodec{
|
||||
runtime.NewCodec(serializer, nil),
|
||||
f.CodecFactory.scheme,
|
||||
}
|
||||
}
|
||||
|
||||
// DecoderToVersion returns an decoder that does not do conversion. gv is ignored.
|
||||
func (f DirectCodecFactory) DecoderToVersion(serializer runtime.Decoder, gv unversioned.GroupVersion) runtime.Decoder {
|
||||
return DirectCodec{
|
||||
runtime.NewCodec(nil, serializer),
|
||||
nil,
|
||||
}
|
||||
}
|
||||
|
||||
// DirectCodec is a codec that does not do conversion. It sets the gvk during serialization, and removes the gvk during deserialization.
|
||||
type DirectCodec struct {
|
||||
runtime.Serializer
|
||||
runtime.ObjectTyper
|
||||
}
|
||||
|
||||
// EncodeToStream does not do conversion. It sets the gvk during serialization. overrides are ignored.
|
||||
func (c DirectCodec) Encode(obj runtime.Object, stream io.Writer) error {
|
||||
gvks, _, err := c.ObjectTyper.ObjectKinds(obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
kind := obj.GetObjectKind()
|
||||
oldGVK := kind.GroupVersionKind()
|
||||
kind.SetGroupVersionKind(gvks[0])
|
||||
err = c.Serializer.Encode(obj, stream)
|
||||
kind.SetGroupVersionKind(oldGVK)
|
||||
return err
|
||||
}
|
||||
|
||||
// Decode does not do conversion. It removes the gvk during deserialization.
|
||||
func (c DirectCodec) Decode(data []byte, defaults *unversioned.GroupVersionKind, into runtime.Object) (runtime.Object, *unversioned.GroupVersionKind, error) {
|
||||
obj, gvk, err := c.Serializer.Decode(data, defaults, into)
|
||||
if obj != nil {
|
||||
kind := obj.GetObjectKind()
|
||||
// clearing the gvk is just a convention of a codec
|
||||
kind.SetGroupVersionKind(unversioned.GroupVersionKind{})
|
||||
}
|
||||
return obj, gvk, err
|
||||
}
|
||||
|
|
|
|||
80
vendor/k8s.io/kubernetes/pkg/runtime/serializer/deep_copy_generated.go
generated
vendored
80
vendor/k8s.io/kubernetes/pkg/runtime/serializer/deep_copy_generated.go
generated
vendored
|
|
@ -1,80 +0,0 @@
|
|||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// This file was autogenerated by deepcopy-gen. Do not edit it manually!
|
||||
|
||||
package serializer
|
||||
|
||||
import (
|
||||
conversion "k8s.io/kubernetes/pkg/conversion"
|
||||
runtime "k8s.io/kubernetes/pkg/runtime"
|
||||
)
|
||||
|
||||
func DeepCopy_serializer_CodecFactory(in CodecFactory, out *CodecFactory, c *conversion.Cloner) error {
|
||||
if in.scheme != nil {
|
||||
in, out := in.scheme, &out.scheme
|
||||
*out = new(runtime.Scheme)
|
||||
if err := runtime.DeepCopy_runtime_Scheme(*in, *out, c); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.scheme = nil
|
||||
}
|
||||
if in.serializers != nil {
|
||||
in, out := in.serializers, &out.serializers
|
||||
*out = make([]serializerType, len(in))
|
||||
for i := range in {
|
||||
if newVal, err := c.DeepCopy(in[i]); err != nil {
|
||||
return err
|
||||
} else {
|
||||
(*out)[i] = newVal.(serializerType)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
out.serializers = nil
|
||||
}
|
||||
if in.universal == nil {
|
||||
out.universal = nil
|
||||
} else if newVal, err := c.DeepCopy(in.universal); err != nil {
|
||||
return err
|
||||
} else {
|
||||
out.universal = newVal.(runtime.Decoder)
|
||||
}
|
||||
if in.accepts != nil {
|
||||
in, out := in.accepts, &out.accepts
|
||||
*out = make([]string, len(in))
|
||||
copy(*out, in)
|
||||
} else {
|
||||
out.accepts = nil
|
||||
}
|
||||
if in.streamingAccepts != nil {
|
||||
in, out := in.streamingAccepts, &out.streamingAccepts
|
||||
*out = make([]string, len(in))
|
||||
copy(*out, in)
|
||||
} else {
|
||||
out.streamingAccepts = nil
|
||||
}
|
||||
if in.legacySerializer == nil {
|
||||
out.legacySerializer = nil
|
||||
} else if newVal, err := c.DeepCopy(in.legacySerializer); err != nil {
|
||||
return err
|
||||
} else {
|
||||
out.legacySerializer = newVal.(runtime.Serializer)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
15
vendor/k8s.io/kubernetes/pkg/runtime/serializer/json/json.go
generated
vendored
15
vendor/k8s.io/kubernetes/pkg/runtime/serializer/json/json.go
generated
vendored
|
|
@ -31,7 +31,7 @@ import (
|
|||
|
||||
// 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.
|
||||
func NewSerializer(meta MetaFactory, creater runtime.ObjectCreater, typer runtime.Typer, pretty bool) *Serializer {
|
||||
func NewSerializer(meta MetaFactory, creater runtime.ObjectCreater, typer runtime.ObjectTyper, pretty bool) *Serializer {
|
||||
return &Serializer{
|
||||
meta: meta,
|
||||
creater: creater,
|
||||
|
|
@ -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
|
||||
// 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.
|
||||
func NewYAMLSerializer(meta MetaFactory, creater runtime.ObjectCreater, typer runtime.Typer) *Serializer {
|
||||
func NewYAMLSerializer(meta MetaFactory, creater runtime.ObjectCreater, typer runtime.ObjectTyper) *Serializer {
|
||||
return &Serializer{
|
||||
meta: meta,
|
||||
creater: creater,
|
||||
|
|
@ -56,7 +56,7 @@ func NewYAMLSerializer(meta MetaFactory, creater runtime.ObjectCreater, typer ru
|
|||
type Serializer struct {
|
||||
meta MetaFactory
|
||||
creater runtime.ObjectCreater
|
||||
typer runtime.Typer
|
||||
typer runtime.ObjectTyper
|
||||
yaml bool
|
||||
pretty bool
|
||||
}
|
||||
|
|
@ -111,12 +111,12 @@ func (s *Serializer) Decode(originalData []byte, gvk *unversioned.GroupVersionKi
|
|||
if unk, ok := into.(*runtime.Unknown); ok && unk != nil {
|
||||
unk.Raw = originalData
|
||||
unk.ContentType = runtime.ContentTypeJSON
|
||||
unk.GetObjectKind().SetGroupVersionKind(actual)
|
||||
unk.GetObjectKind().SetGroupVersionKind(*actual)
|
||||
return unk, actual, nil
|
||||
}
|
||||
|
||||
if into != nil {
|
||||
typed, _, err := s.typer.ObjectKind(into)
|
||||
types, _, err := s.typer.ObjectKinds(into)
|
||||
switch {
|
||||
case runtime.IsNotRegisteredError(err):
|
||||
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
|
|||
case err != nil:
|
||||
return nil, actual, err
|
||||
default:
|
||||
typed := types[0]
|
||||
if len(actual.Kind) == 0 {
|
||||
actual.Kind = typed.Kind
|
||||
}
|
||||
|
|
@ -158,8 +159,8 @@ func (s *Serializer) Decode(originalData []byte, gvk *unversioned.GroupVersionKi
|
|||
return obj, actual, nil
|
||||
}
|
||||
|
||||
// EncodeToStream serializes the provided object to the given writer. Overrides is ignored.
|
||||
func (s *Serializer) EncodeToStream(obj runtime.Object, w io.Writer, overrides ...unversioned.GroupVersion) error {
|
||||
// Encode serializes the provided object to the given writer.
|
||||
func (s *Serializer) Encode(obj runtime.Object, w io.Writer) error {
|
||||
if s.yaml {
|
||||
json, err := json.Marshal(obj)
|
||||
if err != nil {
|
||||
|
|
|
|||
65
vendor/k8s.io/kubernetes/pkg/runtime/serializer/protobuf/protobuf.go
generated
vendored
65
vendor/k8s.io/kubernetes/pkg/runtime/serializer/protobuf/protobuf.go
generated
vendored
|
|
@ -31,7 +31,7 @@ import (
|
|||
|
||||
var (
|
||||
// protoEncodingPrefix serves as a magic number for an encoded protobuf message on this serializer. All
|
||||
// proto messages serialized by this schema will be precedeed by the bytes 0x6b 0x38 0x73, with the fourth
|
||||
// proto messages serialized by this schema will be preceded by the bytes 0x6b 0x38 0x73, with the fourth
|
||||
// byte being reserved for the encoding style. The only encoding style defined is 0x00, which means that
|
||||
// the rest of the byte stream is a message of type k8s.io.kubernetes.pkg.runtime.Unknown (proto2).
|
||||
//
|
||||
|
|
@ -59,7 +59,7 @@ 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.Typer, defaultContentType string) *Serializer {
|
||||
func NewSerializer(creater runtime.ObjectCreater, typer runtime.ObjectTyper, defaultContentType string) *Serializer {
|
||||
return &Serializer{
|
||||
prefix: protoEncodingPrefix,
|
||||
creater: creater,
|
||||
|
|
@ -71,7 +71,7 @@ func NewSerializer(creater runtime.ObjectCreater, typer runtime.Typer, defaultCo
|
|||
type Serializer struct {
|
||||
prefix []byte
|
||||
creater runtime.ObjectCreater
|
||||
typer runtime.Typer
|
||||
typer runtime.ObjectTyper
|
||||
contentType string
|
||||
}
|
||||
|
||||
|
|
@ -120,61 +120,60 @@ func (s *Serializer) Decode(originalData []byte, gvk *unversioned.GroupVersionKi
|
|||
}
|
||||
|
||||
actual := unk.GroupVersionKind()
|
||||
copyKindDefaults(actual, gvk)
|
||||
copyKindDefaults(&actual, gvk)
|
||||
|
||||
if intoUnknown, ok := into.(*runtime.Unknown); ok && intoUnknown != nil {
|
||||
*intoUnknown = unk
|
||||
if len(intoUnknown.ContentType) == 0 {
|
||||
intoUnknown.ContentType = s.contentType
|
||||
}
|
||||
return intoUnknown, actual, nil
|
||||
return intoUnknown, &actual, nil
|
||||
}
|
||||
|
||||
if into != nil {
|
||||
typed, _, err := s.typer.ObjectKind(into)
|
||||
types, _, err := s.typer.ObjectKinds(into)
|
||||
switch {
|
||||
case runtime.IsNotRegisteredError(err):
|
||||
pb, ok := into.(proto.Message)
|
||||
if !ok {
|
||||
return nil, actual, errNotMarshalable{reflect.TypeOf(into)}
|
||||
return nil, &actual, errNotMarshalable{reflect.TypeOf(into)}
|
||||
}
|
||||
if err := proto.Unmarshal(unk.Raw, pb); err != nil {
|
||||
return nil, actual, err
|
||||
return nil, &actual, err
|
||||
}
|
||||
return into, actual, nil
|
||||
return into, &actual, nil
|
||||
case err != nil:
|
||||
return nil, actual, err
|
||||
return nil, &actual, err
|
||||
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
|
||||
// (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.
|
||||
if len(actual.Version) == 0 && len(actual.Group) == 0 {
|
||||
actual.Group = typed.Group
|
||||
actual.Group = types[0].Group
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(actual.Kind) == 0 {
|
||||
return nil, actual, runtime.NewMissingKindErr(fmt.Sprintf("%#v", unk.TypeMeta))
|
||||
return nil, &actual, runtime.NewMissingKindErr(fmt.Sprintf("%#v", unk.TypeMeta))
|
||||
}
|
||||
if len(actual.Version) == 0 {
|
||||
return nil, actual, runtime.NewMissingVersionErr(fmt.Sprintf("%#v", unk.TypeMeta))
|
||||
return nil, &actual, runtime.NewMissingVersionErr(fmt.Sprintf("%#v", unk.TypeMeta))
|
||||
}
|
||||
|
||||
return unmarshalToObject(s.typer, s.creater, actual, into, unk.Raw)
|
||||
return unmarshalToObject(s.typer, s.creater, &actual, into, unk.Raw)
|
||||
}
|
||||
|
||||
// EncodeToStream serializes the provided object to the given writer. Overrides is ignored.
|
||||
func (s *Serializer) EncodeToStream(obj runtime.Object, w io.Writer, overrides ...unversioned.GroupVersion) error {
|
||||
// Encode serializes the provided object to the given writer.
|
||||
func (s *Serializer) Encode(obj runtime.Object, w io.Writer) error {
|
||||
var unk runtime.Unknown
|
||||
if kind := obj.GetObjectKind().GroupVersionKind(); kind != nil {
|
||||
unk = runtime.Unknown{
|
||||
TypeMeta: runtime.TypeMeta{
|
||||
Kind: kind.Kind,
|
||||
APIVersion: kind.GroupVersion().String(),
|
||||
},
|
||||
}
|
||||
kind := obj.GetObjectKind().GroupVersionKind()
|
||||
unk = runtime.Unknown{
|
||||
TypeMeta: runtime.TypeMeta{
|
||||
Kind: kind.Kind,
|
||||
APIVersion: kind.GroupVersion().String(),
|
||||
},
|
||||
}
|
||||
|
||||
prefixSize := uint64(len(s.prefix))
|
||||
|
|
@ -278,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).
|
||||
//
|
||||
// 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.ObjectTyper, defaultContentType string) *RawSerializer {
|
||||
return &RawSerializer{
|
||||
creater: creater,
|
||||
typer: typer,
|
||||
|
|
@ -290,7 +289,7 @@ func NewRawSerializer(creater runtime.ObjectCreater, typer runtime.Typer, defaul
|
|||
// type).
|
||||
type RawSerializer struct {
|
||||
creater runtime.ObjectCreater
|
||||
typer runtime.Typer
|
||||
typer runtime.ObjectTyper
|
||||
contentType string
|
||||
}
|
||||
|
||||
|
|
@ -334,11 +333,11 @@ func (s *RawSerializer) Decode(originalData []byte, gvk *unversioned.GroupVersio
|
|||
intoUnknown.Raw = data
|
||||
intoUnknown.ContentEncoding = ""
|
||||
intoUnknown.ContentType = s.contentType
|
||||
intoUnknown.SetGroupVersionKind(actual)
|
||||
intoUnknown.SetGroupVersionKind(*actual)
|
||||
return intoUnknown, actual, nil
|
||||
}
|
||||
|
||||
typed, _, err := s.typer.ObjectKind(into)
|
||||
types, _, err := s.typer.ObjectKinds(into)
|
||||
switch {
|
||||
case runtime.IsNotRegisteredError(err):
|
||||
pb, ok := into.(proto.Message)
|
||||
|
|
@ -352,12 +351,12 @@ func (s *RawSerializer) Decode(originalData []byte, gvk *unversioned.GroupVersio
|
|||
case err != nil:
|
||||
return nil, actual, err
|
||||
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
|
||||
// (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.
|
||||
if len(actual.Version) == 0 && len(actual.Group) == 0 {
|
||||
actual.Group = typed.Group
|
||||
actual.Group = types[0].Group
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -372,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.
|
||||
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.ObjectTyper, creater runtime.ObjectCreater, actual *unversioned.GroupVersionKind, into runtime.Object, data []byte) (runtime.Object, *unversioned.GroupVersionKind, error) {
|
||||
// use the target if necessary
|
||||
obj, err := runtime.UseOrCreateObject(typer, creater, *actual, into)
|
||||
if err != nil {
|
||||
|
|
@ -389,8 +388,8 @@ func unmarshalToObject(typer runtime.Typer, creater runtime.ObjectCreater, actua
|
|||
return obj, actual, nil
|
||||
}
|
||||
|
||||
// EncodeToStream serializes the provided object to the given writer. Overrides is ignored.
|
||||
func (s *RawSerializer) EncodeToStream(obj runtime.Object, w io.Writer, overrides ...unversioned.GroupVersion) error {
|
||||
// Encode serializes the provided object to the given writer. Overrides is ignored.
|
||||
func (s *RawSerializer) Encode(obj runtime.Object, w io.Writer) error {
|
||||
switch t := obj.(type) {
|
||||
case bufferedMarshaller:
|
||||
// this path performs a single allocation during write but requires the caller to implement
|
||||
|
|
|
|||
4
vendor/k8s.io/kubernetes/pkg/runtime/serializer/protobuf_extension.go
generated
vendored
4
vendor/k8s.io/kubernetes/pkg/runtime/serializer/protobuf_extension.go
generated
vendored
|
|
@ -31,8 +31,8 @@ const (
|
|||
)
|
||||
|
||||
func protobufSerializer(scheme *runtime.Scheme) (serializerType, bool) {
|
||||
serializer := protobuf.NewSerializer(scheme, runtime.ObjectTyperToTyper(scheme), contentTypeProtobuf)
|
||||
raw := protobuf.NewRawSerializer(scheme, runtime.ObjectTyperToTyper(scheme), contentTypeProtobuf)
|
||||
serializer := protobuf.NewSerializer(scheme, scheme, contentTypeProtobuf)
|
||||
raw := protobuf.NewRawSerializer(scheme, scheme, contentTypeProtobuf)
|
||||
return serializerType{
|
||||
AcceptContentTypes: []string{contentTypeProtobuf},
|
||||
ContentType: contentTypeProtobuf,
|
||||
|
|
|
|||
8
vendor/k8s.io/kubernetes/pkg/runtime/serializer/streaming/streaming.go
generated
vendored
8
vendor/k8s.io/kubernetes/pkg/runtime/serializer/streaming/streaming.go
generated
vendored
|
|
@ -30,8 +30,8 @@ import (
|
|||
// Encoder is a runtime.Encoder on a stream.
|
||||
type Encoder interface {
|
||||
// Encode will write the provided object to the stream or return an error. It obeys the same
|
||||
// contract as runtime.Encoder.
|
||||
Encode(obj runtime.Object, overrides ...unversioned.GroupVersion) error
|
||||
// contract as runtime.VersionedEncoder.
|
||||
Encode(obj runtime.Object) error
|
||||
}
|
||||
|
||||
// Decoder is a runtime.Decoder from a stream.
|
||||
|
|
@ -127,8 +127,8 @@ func NewEncoder(w io.Writer, e runtime.Encoder) Encoder {
|
|||
}
|
||||
|
||||
// Encode writes the provided object to the nested writer.
|
||||
func (e *encoder) Encode(obj runtime.Object, overrides ...unversioned.GroupVersion) error {
|
||||
if err := e.encoder.EncodeToStream(obj, e.buf, overrides...); err != nil {
|
||||
func (e *encoder) Encode(obj runtime.Object) error {
|
||||
if err := e.encoder.Encode(obj, e.buf); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := e.writer.Write(e.buf.Bytes())
|
||||
|
|
|
|||
94
vendor/k8s.io/kubernetes/pkg/runtime/serializer/versioning/versioning.go
generated
vendored
94
vendor/k8s.io/kubernetes/pkg/runtime/serializer/versioning/versioning.go
generated
vendored
|
|
@ -71,7 +71,7 @@ func NewCodecForScheme(
|
|||
encodeVersion []unversioned.GroupVersion,
|
||||
decodeVersion []unversioned.GroupVersion,
|
||||
) runtime.Codec {
|
||||
return NewCodec(encoder, decoder, 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
|
||||
|
|
@ -83,7 +83,7 @@ func NewCodec(
|
|||
convertor runtime.ObjectConvertor,
|
||||
creater runtime.ObjectCreater,
|
||||
copier runtime.ObjectCopier,
|
||||
typer runtime.Typer,
|
||||
typer runtime.ObjectTyper,
|
||||
encodeVersion []unversioned.GroupVersion,
|
||||
decodeVersion []unversioned.GroupVersion,
|
||||
) runtime.Codec {
|
||||
|
|
@ -104,6 +104,11 @@ func NewCodec(
|
|||
}
|
||||
internal.encodeVersion[v.Group] = v
|
||||
}
|
||||
if len(internal.encodeVersion) == 1 {
|
||||
for _, v := range internal.encodeVersion {
|
||||
internal.preferredEncodeVersion = []unversioned.GroupVersion{v}
|
||||
}
|
||||
}
|
||||
}
|
||||
if decodeVersion != nil {
|
||||
internal.decodeVersion = make(map[string]unversioned.GroupVersion)
|
||||
|
|
@ -125,10 +130,12 @@ type codec struct {
|
|||
convertor runtime.ObjectConvertor
|
||||
creater runtime.ObjectCreater
|
||||
copier runtime.ObjectCopier
|
||||
typer runtime.Typer
|
||||
typer runtime.ObjectTyper
|
||||
|
||||
encodeVersion map[string]unversioned.GroupVersion
|
||||
decodeVersion map[string]unversioned.GroupVersion
|
||||
|
||||
preferredEncodeVersion []unversioned.GroupVersion
|
||||
}
|
||||
|
||||
// Decode attempts a decode of the object, then tries to convert it to the internal version. If into is provided and the decoding is
|
||||
|
|
@ -204,7 +211,7 @@ func (c *codec) Decode(data []byte, defaultGVK *unversioned.GroupVersionKind, in
|
|||
}
|
||||
|
||||
// Convert if needed.
|
||||
out, err := c.convertor.ConvertToVersion(obj, targetGV.String())
|
||||
out, err := c.convertor.ConvertToVersion(obj, targetGV)
|
||||
if err != nil {
|
||||
return nil, gvk, err
|
||||
}
|
||||
|
|
@ -215,44 +222,33 @@ func (c *codec) Decode(data []byte, defaultGVK *unversioned.GroupVersionKind, in
|
|||
return out, gvk, nil
|
||||
}
|
||||
|
||||
// EncodeToStream ensures the provided object is output in the right scheme. If overrides are specified, when
|
||||
// encoding the object the first override that matches the object's group is used. Other overrides are ignored.
|
||||
func (c *codec) EncodeToStream(obj runtime.Object, w io.Writer, overrides ...unversioned.GroupVersion) error {
|
||||
// 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.
|
||||
func (c *codec) Encode(obj runtime.Object, w io.Writer) error {
|
||||
if _, ok := obj.(*runtime.Unknown); ok {
|
||||
return c.encoder.EncodeToStream(obj, w, overrides...)
|
||||
return c.encoder.Encode(obj, w)
|
||||
}
|
||||
gvk, isUnversioned, err := c.typer.ObjectKind(obj)
|
||||
gvks, isUnversioned, err := c.typer.ObjectKinds(obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
gvk := gvks[0]
|
||||
|
||||
if (c.encodeVersion == nil && len(overrides) == 0) || isUnversioned {
|
||||
old := obj.GetObjectKind().GroupVersionKind()
|
||||
obj.GetObjectKind().SetGroupVersionKind(gvk)
|
||||
defer obj.GetObjectKind().SetGroupVersionKind(old)
|
||||
return c.encoder.EncodeToStream(obj, w, overrides...)
|
||||
if c.encodeVersion == nil || isUnversioned {
|
||||
objectKind := obj.GetObjectKind()
|
||||
old := objectKind.GroupVersionKind()
|
||||
objectKind.SetGroupVersionKind(gvk)
|
||||
err = c.encoder.Encode(obj, w)
|
||||
objectKind.SetGroupVersionKind(old)
|
||||
return err
|
||||
}
|
||||
|
||||
targetGV, ok := c.encodeVersion[gvk.Group]
|
||||
// use override if provided
|
||||
for i, override := range overrides {
|
||||
if override.Group == gvk.Group {
|
||||
ok = true
|
||||
targetGV = override
|
||||
// swap the position of the override
|
||||
overrides[0], overrides[i] = targetGV, overrides[0]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// attempt a conversion to the sole encode version
|
||||
if !ok && len(c.encodeVersion) == 1 {
|
||||
if !ok && c.preferredEncodeVersion != nil {
|
||||
ok = true
|
||||
for _, v := range c.encodeVersion {
|
||||
targetGV = v
|
||||
}
|
||||
// ensure the target override is first
|
||||
overrides = promoteOrPrependGroupVersion(targetGV, overrides)
|
||||
targetGV = c.preferredEncodeVersion[0]
|
||||
}
|
||||
|
||||
// if no fallback is available, error
|
||||
|
|
@ -261,33 +257,19 @@ func (c *codec) EncodeToStream(obj runtime.Object, w io.Writer, overrides ...unv
|
|||
}
|
||||
|
||||
// Perform a conversion if necessary
|
||||
if gvk.GroupVersion() != targetGV {
|
||||
out, err := c.convertor.ConvertToVersion(obj, targetGV.String())
|
||||
if err != nil {
|
||||
if ok {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
obj = out
|
||||
objectKind := obj.GetObjectKind()
|
||||
old := objectKind.GroupVersionKind()
|
||||
out, err := c.convertor.ConvertToVersion(obj, targetGV)
|
||||
if err != nil {
|
||||
if ok {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
old := obj.GetObjectKind().GroupVersionKind()
|
||||
defer obj.GetObjectKind().SetGroupVersionKind(old)
|
||||
obj.GetObjectKind().SetGroupVersionKind(&unversioned.GroupVersionKind{Group: targetGV.Group, Version: targetGV.Version, Kind: gvk.Kind})
|
||||
obj = out
|
||||
}
|
||||
|
||||
return c.encoder.EncodeToStream(obj, w, overrides...)
|
||||
}
|
||||
|
||||
// promoteOrPrependGroupVersion finds the group version in the provided group versions that has the same group as target.
|
||||
// If the group is found the returned array will have that group version in the first position - if the group is not found
|
||||
// the returned array will have target in the first position.
|
||||
func promoteOrPrependGroupVersion(target unversioned.GroupVersion, gvs []unversioned.GroupVersion) []unversioned.GroupVersion {
|
||||
for i, gv := range gvs {
|
||||
if gv.Group == target.Group {
|
||||
gvs[0], gvs[i] = gvs[i], gvs[0]
|
||||
return gvs
|
||||
}
|
||||
}
|
||||
return append([]unversioned.GroupVersion{target}, gvs...)
|
||||
// Conversion is responsible for setting the proper group, version, and kind onto the outgoing object
|
||||
err = c.encoder.Encode(obj, w)
|
||||
// restore the old GVK, in case conversion returned the same object
|
||||
objectKind.SetGroupVersionKind(old)
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue