Update ingress godeps
This commit is contained in:
parent
d43021b3f1
commit
28db8fb16d
1068 changed files with 461467 additions and 117300 deletions
86
vendor/k8s.io/kubernetes/pkg/runtime/serializer/codec_factory.go
generated
vendored
86
vendor/k8s.io/kubernetes/pkg/runtime/serializer/codec_factory.go
generated
vendored
|
|
@ -17,8 +17,6 @@ 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"
|
||||
|
|
@ -188,13 +186,17 @@ func (f CodecFactory) SupportedStreamingMediaTypes() []string {
|
|||
return f.streamingAccepts
|
||||
}
|
||||
|
||||
// LegacyCodec encodes output to a given API version, and decodes output into the internal form from
|
||||
// any recognized source. The returned codec will always encode output to JSON.
|
||||
// LegacyCodec encodes output to a given API versions, and decodes output into the internal form from
|
||||
// any recognized source. The returned codec will always encode output to JSON. If a type is not
|
||||
// found in the list of versions an error will be returned.
|
||||
//
|
||||
// This method is deprecated - clients and servers should negotiate a serializer by mime-type and
|
||||
// invoke CodecForVersions. Callers that need only to read data should use UniversalDecoder().
|
||||
//
|
||||
// TODO: make this call exist only in pkg/api, and initialize it with the set of default versions.
|
||||
// All other callers will be forced to request a Codec directly.
|
||||
func (f CodecFactory) LegacyCodec(version ...unversioned.GroupVersion) runtime.Codec {
|
||||
return versioning.NewCodecForScheme(f.scheme, f.legacySerializer, f.universal, version, nil)
|
||||
return versioning.NewCodecForScheme(f.scheme, f.legacySerializer, f.universal, unversioned.GroupVersions(version), runtime.InternalGroupVersioner)
|
||||
}
|
||||
|
||||
// UniversalDeserializer can convert any stored data recognized by this factory into a Go object that satisfies
|
||||
|
|
@ -211,25 +213,39 @@ func (f CodecFactory) UniversalDeserializer() runtime.Decoder {
|
|||
// defaulting.
|
||||
//
|
||||
// TODO: the decoder will eventually be removed in favor of dealing with objects in their versioned form
|
||||
// TODO: only accept a group versioner
|
||||
func (f CodecFactory) UniversalDecoder(versions ...unversioned.GroupVersion) runtime.Decoder {
|
||||
return f.CodecForVersions(nil, f.universal, nil, versions)
|
||||
var versioner runtime.GroupVersioner
|
||||
if len(versions) == 0 {
|
||||
versioner = runtime.InternalGroupVersioner
|
||||
} else {
|
||||
versioner = unversioned.GroupVersions(versions)
|
||||
}
|
||||
return f.CodecForVersions(nil, f.universal, nil, versioner)
|
||||
}
|
||||
|
||||
// CodecFor creates a codec with the provided serializer. If an object is decoded and its group is not in the list,
|
||||
// CodecForVersions creates a codec with the provided serializer. If an object is decoded and its group is not in the list,
|
||||
// it will default to runtime.APIVersionInternal. If encode is not specified for an object's group, the object is not
|
||||
// converted. If encode or decode are nil, no conversion is performed.
|
||||
func (f CodecFactory) CodecForVersions(encoder runtime.Encoder, decoder runtime.Decoder, encode []unversioned.GroupVersion, decode []unversioned.GroupVersion) runtime.Codec {
|
||||
func (f CodecFactory) CodecForVersions(encoder runtime.Encoder, decoder runtime.Decoder, encode runtime.GroupVersioner, decode runtime.GroupVersioner) runtime.Codec {
|
||||
// TODO: these are for backcompat, remove them in the future
|
||||
if encode == nil {
|
||||
encode = runtime.DisabledGroupVersioner
|
||||
}
|
||||
if decode == nil {
|
||||
decode = runtime.InternalGroupVersioner
|
||||
}
|
||||
return versioning.NewCodecForScheme(f.scheme, encoder, decoder, encode, decode)
|
||||
}
|
||||
|
||||
// DecoderToVersion returns a decoder that targets the provided group version.
|
||||
func (f CodecFactory) DecoderToVersion(decoder runtime.Decoder, gv unversioned.GroupVersion) runtime.Decoder {
|
||||
return f.CodecForVersions(nil, decoder, nil, []unversioned.GroupVersion{gv})
|
||||
func (f CodecFactory) DecoderToVersion(decoder runtime.Decoder, gv runtime.GroupVersioner) runtime.Decoder {
|
||||
return f.CodecForVersions(nil, decoder, nil, gv)
|
||||
}
|
||||
|
||||
// EncoderForVersion returns an encoder that targets the provided group version.
|
||||
func (f CodecFactory) EncoderForVersion(encoder runtime.Encoder, gv unversioned.GroupVersion) runtime.Encoder {
|
||||
return f.CodecForVersions(encoder, nil, []unversioned.GroupVersion{gv}, nil)
|
||||
func (f CodecFactory) EncoderForVersion(encoder runtime.Encoder, gv runtime.GroupVersioner) runtime.Encoder {
|
||||
return f.CodecForVersions(encoder, nil, gv, nil)
|
||||
}
|
||||
|
||||
// SerializerForMediaType returns a serializer that matches the provided RFC2046 mediaType, or false if no such
|
||||
|
|
@ -317,48 +333,16 @@ type DirectCodecFactory struct {
|
|||
}
|
||||
|
||||
// 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,
|
||||
func (f DirectCodecFactory) EncoderForVersion(serializer runtime.Encoder, _ runtime.GroupVersioner) runtime.Encoder {
|
||||
return versioning.DirectEncoder{
|
||||
Encoder: serializer,
|
||||
ObjectTyper: 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,
|
||||
func (f DirectCodecFactory) DecoderToVersion(serializer runtime.Decoder, _ runtime.GroupVersioner) runtime.Decoder {
|
||||
return versioning.DirectDecoder{
|
||||
Decoder: serializer,
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
|
|
|||
2
vendor/k8s.io/kubernetes/pkg/runtime/serializer/json/json.go
generated
vendored
2
vendor/k8s.io/kubernetes/pkg/runtime/serializer/json/json.go
generated
vendored
|
|
@ -25,6 +25,7 @@ import (
|
|||
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/runtime/serializer/recognizer"
|
||||
"k8s.io/kubernetes/pkg/util/framer"
|
||||
utilyaml "k8s.io/kubernetes/pkg/util/yaml"
|
||||
)
|
||||
|
|
@ -63,6 +64,7 @@ type Serializer struct {
|
|||
|
||||
// Serializer implements Serializer
|
||||
var _ runtime.Serializer = &Serializer{}
|
||||
var _ recognizer.RecognizingDecoder = &Serializer{}
|
||||
|
||||
// Decode attempts to convert the provided data into YAML or JSON, extract the stored schema kind, apply the provided default gvk, and then
|
||||
// load that data into an object matching the desired schema kind or the provided into. If into is *runtime.Unknown, the raw data will be
|
||||
|
|
|
|||
5
vendor/k8s.io/kubernetes/pkg/runtime/serializer/negotiated_codec.go
generated
vendored
5
vendor/k8s.io/kubernetes/pkg/runtime/serializer/negotiated_codec.go
generated
vendored
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||
package serializer
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
)
|
||||
|
||||
|
|
@ -48,10 +47,10 @@ func (n *negotiatedSerializerWrapper) StreamingSerializerForMediaType(mediaType
|
|||
return n.streamInfo, true
|
||||
}
|
||||
|
||||
func (n *negotiatedSerializerWrapper) EncoderForVersion(e runtime.Encoder, _ unversioned.GroupVersion) runtime.Encoder {
|
||||
func (n *negotiatedSerializerWrapper) EncoderForVersion(e runtime.Encoder, _ runtime.GroupVersioner) runtime.Encoder {
|
||||
return e
|
||||
}
|
||||
|
||||
func (n *negotiatedSerializerWrapper) DecoderToVersion(d runtime.Decoder, _gv unversioned.GroupVersion) runtime.Decoder {
|
||||
func (n *negotiatedSerializerWrapper) DecoderToVersion(d runtime.Decoder, _gv runtime.GroupVersioner) runtime.Decoder {
|
||||
return d
|
||||
}
|
||||
|
|
|
|||
45
vendor/k8s.io/kubernetes/pkg/runtime/serializer/protobuf/protobuf.go
generated
vendored
45
vendor/k8s.io/kubernetes/pkg/runtime/serializer/protobuf/protobuf.go
generated
vendored
|
|
@ -26,6 +26,7 @@ import (
|
|||
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/runtime/serializer/recognizer"
|
||||
"k8s.io/kubernetes/pkg/util/framer"
|
||||
)
|
||||
|
||||
|
|
@ -76,6 +77,7 @@ type Serializer struct {
|
|||
}
|
||||
|
||||
var _ runtime.Serializer = &Serializer{}
|
||||
var _ recognizer.RecognizingDecoder = &Serializer{}
|
||||
|
||||
// Decode attempts to convert the provided data into a protobuf message, extract the stored schema kind, apply the provided default
|
||||
// gvk, and then load that data into an object matching the desired schema kind or the provided into. If into is *runtime.Unknown,
|
||||
|
|
@ -124,7 +126,7 @@ func (s *Serializer) Decode(originalData []byte, gvk *unversioned.GroupVersionKi
|
|||
|
||||
if intoUnknown, ok := into.(*runtime.Unknown); ok && intoUnknown != nil {
|
||||
*intoUnknown = unk
|
||||
if len(intoUnknown.ContentType) == 0 {
|
||||
if ok, _, _ := s.RecognizesData(bytes.NewBuffer(unk.Raw)); ok {
|
||||
intoUnknown.ContentType = s.contentType
|
||||
}
|
||||
return intoUnknown, &actual, nil
|
||||
|
|
@ -167,17 +169,30 @@ func (s *Serializer) Decode(originalData []byte, gvk *unversioned.GroupVersionKi
|
|||
|
||||
// Encode serializes the provided object to the given writer.
|
||||
func (s *Serializer) Encode(obj runtime.Object, w io.Writer) error {
|
||||
var unk runtime.Unknown
|
||||
kind := obj.GetObjectKind().GroupVersionKind()
|
||||
unk = runtime.Unknown{
|
||||
TypeMeta: runtime.TypeMeta{
|
||||
Kind: kind.Kind,
|
||||
APIVersion: kind.GroupVersion().String(),
|
||||
},
|
||||
}
|
||||
|
||||
prefixSize := uint64(len(s.prefix))
|
||||
|
||||
var unk runtime.Unknown
|
||||
switch t := obj.(type) {
|
||||
case *runtime.Unknown:
|
||||
estimatedSize := prefixSize + uint64(t.Size())
|
||||
data := make([]byte, estimatedSize)
|
||||
i, err := t.MarshalTo(data[prefixSize:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
copy(data, s.prefix)
|
||||
_, err = w.Write(data[:prefixSize+uint64(i)])
|
||||
return err
|
||||
default:
|
||||
kind := obj.GetObjectKind().GroupVersionKind()
|
||||
unk = runtime.Unknown{
|
||||
TypeMeta: runtime.TypeMeta{
|
||||
Kind: kind.Kind,
|
||||
APIVersion: kind.GroupVersion().String(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
switch t := obj.(type) {
|
||||
case bufferedMarshaller:
|
||||
// this path performs a single allocation during write but requires the caller to implement
|
||||
|
|
@ -224,19 +239,19 @@ func (s *Serializer) Encode(obj runtime.Object, w io.Writer) error {
|
|||
}
|
||||
|
||||
// RecognizesData implements the RecognizingDecoder interface.
|
||||
func (s *Serializer) RecognizesData(peek io.Reader) (bool, error) {
|
||||
func (s *Serializer) RecognizesData(peek io.Reader) (bool, bool, error) {
|
||||
prefix := make([]byte, 4)
|
||||
n, err := peek.Read(prefix)
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
return false, nil
|
||||
return false, false, nil
|
||||
}
|
||||
return false, err
|
||||
return false, false, err
|
||||
}
|
||||
if n != 4 {
|
||||
return false, nil
|
||||
return false, false, nil
|
||||
}
|
||||
return bytes.Equal(s.prefix, prefix), nil
|
||||
return bytes.Equal(s.prefix, prefix), false, nil
|
||||
}
|
||||
|
||||
// copyKindDefaults defaults dst to the value in src if dst does not have a value set.
|
||||
|
|
|
|||
207
vendor/k8s.io/kubernetes/pkg/runtime/serializer/versioning/versioning.go
generated
vendored
207
vendor/k8s.io/kubernetes/pkg/runtime/serializer/versioning/versioning.go
generated
vendored
|
|
@ -17,59 +17,20 @@ limitations under the License.
|
|||
package versioning
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
)
|
||||
|
||||
// EnableCrossGroupDecoding modifies the given decoder in place, if it is a codec
|
||||
// from this package. It allows objects from one group to be auto-decoded into
|
||||
// another group. 'destGroup' must already exist in the codec.
|
||||
// TODO: this is an encapsulation violation and should be refactored
|
||||
func EnableCrossGroupDecoding(d runtime.Decoder, sourceGroup, destGroup string) error {
|
||||
internal, ok := d.(*codec)
|
||||
if !ok {
|
||||
return fmt.Errorf("unsupported decoder type")
|
||||
}
|
||||
|
||||
dest, ok := internal.decodeVersion[destGroup]
|
||||
if !ok {
|
||||
return fmt.Errorf("group %q is not a possible destination group in the given codec", destGroup)
|
||||
}
|
||||
internal.decodeVersion[sourceGroup] = dest
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// EnableCrossGroupEncoding modifies the given encoder in place, if it is a codec
|
||||
// from this package. It allows objects from one group to be auto-decoded into
|
||||
// another group. 'destGroup' must already exist in the codec.
|
||||
// TODO: this is an encapsulation violation and should be refactored
|
||||
func EnableCrossGroupEncoding(e runtime.Encoder, sourceGroup, destGroup string) error {
|
||||
internal, ok := e.(*codec)
|
||||
if !ok {
|
||||
return fmt.Errorf("unsupported encoder type")
|
||||
}
|
||||
|
||||
dest, ok := internal.encodeVersion[destGroup]
|
||||
if !ok {
|
||||
return fmt.Errorf("group %q is not a possible destination group in the given codec", destGroup)
|
||||
}
|
||||
internal.encodeVersion[sourceGroup] = dest
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewCodecForScheme is a convenience method for callers that are using a scheme.
|
||||
func NewCodecForScheme(
|
||||
// TODO: I should be a scheme interface?
|
||||
scheme *runtime.Scheme,
|
||||
encoder runtime.Encoder,
|
||||
decoder runtime.Decoder,
|
||||
encodeVersion []unversioned.GroupVersion,
|
||||
decodeVersion []unversioned.GroupVersion,
|
||||
encodeVersion runtime.GroupVersioner,
|
||||
decodeVersion runtime.GroupVersioner,
|
||||
) runtime.Codec {
|
||||
return NewCodec(encoder, decoder, runtime.UnsafeObjectConvertor(scheme), scheme, scheme, scheme, encodeVersion, decodeVersion)
|
||||
}
|
||||
|
|
@ -84,8 +45,8 @@ func NewCodec(
|
|||
creater runtime.ObjectCreater,
|
||||
copier runtime.ObjectCopier,
|
||||
typer runtime.ObjectTyper,
|
||||
encodeVersion []unversioned.GroupVersion,
|
||||
decodeVersion []unversioned.GroupVersion,
|
||||
encodeVersion runtime.GroupVersioner,
|
||||
decodeVersion runtime.GroupVersioner,
|
||||
) runtime.Codec {
|
||||
internal := &codec{
|
||||
encoder: encoder,
|
||||
|
|
@ -94,33 +55,10 @@ func NewCodec(
|
|||
creater: creater,
|
||||
copier: copier,
|
||||
typer: typer,
|
||||
}
|
||||
if encodeVersion != nil {
|
||||
internal.encodeVersion = make(map[string]unversioned.GroupVersion)
|
||||
for _, v := range encodeVersion {
|
||||
// first one for a group wins. This is consistent with best to worst order throughout the codebase
|
||||
if _, ok := internal.encodeVersion[v.Group]; ok {
|
||||
continue
|
||||
}
|
||||
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)
|
||||
for _, v := range decodeVersion {
|
||||
// first one for a group wins. This is consistent with best to worst order throughout the codebase
|
||||
if _, ok := internal.decodeVersion[v.Group]; ok {
|
||||
continue
|
||||
}
|
||||
internal.decodeVersion[v.Group] = v
|
||||
}
|
||||
}
|
||||
|
||||
encodeVersion: encodeVersion,
|
||||
decodeVersion: decodeVersion,
|
||||
}
|
||||
return internal
|
||||
}
|
||||
|
||||
|
|
@ -132,10 +70,8 @@ type codec struct {
|
|||
copier runtime.ObjectCopier
|
||||
typer runtime.ObjectTyper
|
||||
|
||||
encodeVersion map[string]unversioned.GroupVersion
|
||||
decodeVersion map[string]unversioned.GroupVersion
|
||||
|
||||
preferredEncodeVersion []unversioned.GroupVersion
|
||||
encodeVersion runtime.GroupVersioner
|
||||
decodeVersion runtime.GroupVersioner
|
||||
}
|
||||
|
||||
// Decode attempts a decode of the object, then tries to convert it to the internal version. If into is provided and the decoding is
|
||||
|
|
@ -152,6 +88,12 @@ func (c *codec) Decode(data []byte, defaultGVK *unversioned.GroupVersionKind, in
|
|||
return nil, gvk, err
|
||||
}
|
||||
|
||||
if d, ok := obj.(runtime.NestedObjectDecoder); ok {
|
||||
if err := d.DecodeNestedObjects(DirectDecoder{c.decoder}); err != nil {
|
||||
return nil, gvk, err
|
||||
}
|
||||
}
|
||||
|
||||
// if we specify a target, use generic conversion.
|
||||
if into != nil {
|
||||
if into == obj {
|
||||
|
|
@ -160,7 +102,7 @@ func (c *codec) Decode(data []byte, defaultGVK *unversioned.GroupVersionKind, in
|
|||
}
|
||||
return into, gvk, nil
|
||||
}
|
||||
if err := c.convertor.Convert(obj, into); err != nil {
|
||||
if err := c.convertor.Convert(obj, into, c.decodeVersion); err != nil {
|
||||
return nil, gvk, err
|
||||
}
|
||||
if isVersioned {
|
||||
|
|
@ -170,37 +112,7 @@ func (c *codec) Decode(data []byte, defaultGVK *unversioned.GroupVersionKind, in
|
|||
return into, gvk, nil
|
||||
}
|
||||
|
||||
// invoke a version conversion
|
||||
group := gvk.Group
|
||||
if defaultGVK != nil {
|
||||
group = defaultGVK.Group
|
||||
}
|
||||
var targetGV unversioned.GroupVersion
|
||||
if c.decodeVersion == nil {
|
||||
// convert to internal by default
|
||||
targetGV.Group = group
|
||||
targetGV.Version = runtime.APIVersionInternal
|
||||
} else {
|
||||
gv, ok := c.decodeVersion[group]
|
||||
if !ok {
|
||||
// unknown objects are left in their original version
|
||||
if isVersioned {
|
||||
versioned.Objects = []runtime.Object{obj}
|
||||
return versioned, gvk, nil
|
||||
}
|
||||
return obj, gvk, nil
|
||||
}
|
||||
targetGV = gv
|
||||
}
|
||||
|
||||
if gvk.GroupVersion() == targetGV {
|
||||
if isVersioned {
|
||||
versioned.Objects = []runtime.Object{obj}
|
||||
return versioned, gvk, nil
|
||||
}
|
||||
return obj, gvk, nil
|
||||
}
|
||||
|
||||
// Convert if needed.
|
||||
if isVersioned {
|
||||
// create a copy, because ConvertToVersion does not guarantee non-mutation of objects
|
||||
copied, err := c.copier.Copy(obj)
|
||||
|
|
@ -209,14 +121,14 @@ func (c *codec) Decode(data []byte, defaultGVK *unversioned.GroupVersionKind, in
|
|||
}
|
||||
versioned.Objects = []runtime.Object{copied}
|
||||
}
|
||||
|
||||
// Convert if needed.
|
||||
out, err := c.convertor.ConvertToVersion(obj, targetGV)
|
||||
out, err := c.convertor.ConvertToVersion(obj, c.decodeVersion)
|
||||
if err != nil {
|
||||
return nil, gvk, err
|
||||
}
|
||||
if isVersioned {
|
||||
versioned.Objects = append(versioned.Objects, out)
|
||||
if versioned.Last() != out {
|
||||
versioned.Objects = append(versioned.Objects, out)
|
||||
}
|
||||
return versioned, gvk, nil
|
||||
}
|
||||
return out, gvk, nil
|
||||
|
|
@ -225,51 +137,86 @@ func (c *codec) Decode(data []byte, defaultGVK *unversioned.GroupVersionKind, in
|
|||
// 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 {
|
||||
switch obj.(type) {
|
||||
case *runtime.Unknown, *runtime.Unstructured, *runtime.UnstructuredList:
|
||||
return c.encoder.Encode(obj, w)
|
||||
}
|
||||
|
||||
gvks, isUnversioned, err := c.typer.ObjectKinds(obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
gvk := gvks[0]
|
||||
|
||||
if c.encodeVersion == nil || isUnversioned {
|
||||
if e, ok := obj.(runtime.NestedObjectEncoder); ok {
|
||||
if err := e.EncodeNestedObjects(DirectEncoder{Encoder: c.encoder, ObjectTyper: c.typer}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
objectKind := obj.GetObjectKind()
|
||||
old := objectKind.GroupVersionKind()
|
||||
objectKind.SetGroupVersionKind(gvk)
|
||||
objectKind.SetGroupVersionKind(gvks[0])
|
||||
err = c.encoder.Encode(obj, w)
|
||||
objectKind.SetGroupVersionKind(old)
|
||||
return err
|
||||
}
|
||||
|
||||
targetGV, ok := c.encodeVersion[gvk.Group]
|
||||
|
||||
// attempt a conversion to the sole encode version
|
||||
if !ok && c.preferredEncodeVersion != nil {
|
||||
ok = true
|
||||
targetGV = c.preferredEncodeVersion[0]
|
||||
}
|
||||
|
||||
// if no fallback is available, error
|
||||
if !ok {
|
||||
return fmt.Errorf("the codec does not recognize group %q for kind %q and cannot encode it", gvk.Group, gvk.Kind)
|
||||
}
|
||||
|
||||
// Perform a conversion if necessary
|
||||
objectKind := obj.GetObjectKind()
|
||||
old := objectKind.GroupVersionKind()
|
||||
out, err := c.convertor.ConvertToVersion(obj, targetGV)
|
||||
out, err := c.convertor.ConvertToVersion(obj, c.encodeVersion)
|
||||
if err != nil {
|
||||
if ok {
|
||||
return err
|
||||
}
|
||||
|
||||
if e, ok := out.(runtime.NestedObjectEncoder); ok {
|
||||
if err := e.EncodeNestedObjects(DirectEncoder{Encoder: c.encoder, ObjectTyper: c.typer}); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
obj = out
|
||||
}
|
||||
|
||||
// Conversion is responsible for setting the proper group, version, and kind onto the outgoing object
|
||||
err = c.encoder.Encode(obj, w)
|
||||
err = c.encoder.Encode(out, w)
|
||||
// restore the old GVK, in case conversion returned the same object
|
||||
objectKind.SetGroupVersionKind(old)
|
||||
return err
|
||||
}
|
||||
|
||||
// DirectEncoder serializes an object and ensures the GVK is set.
|
||||
type DirectEncoder struct {
|
||||
runtime.Encoder
|
||||
runtime.ObjectTyper
|
||||
}
|
||||
|
||||
// Encode does not do conversion. It sets the gvk during serialization.
|
||||
func (e DirectEncoder) Encode(obj runtime.Object, stream io.Writer) error {
|
||||
gvks, _, err := e.ObjectTyper.ObjectKinds(obj)
|
||||
if err != nil {
|
||||
if runtime.IsNotRegisteredError(err) {
|
||||
return e.Encoder.Encode(obj, stream)
|
||||
}
|
||||
return err
|
||||
}
|
||||
kind := obj.GetObjectKind()
|
||||
oldGVK := kind.GroupVersionKind()
|
||||
kind.SetGroupVersionKind(gvks[0])
|
||||
err = e.Encoder.Encode(obj, stream)
|
||||
kind.SetGroupVersionKind(oldGVK)
|
||||
return err
|
||||
}
|
||||
|
||||
// DirectDecoder clears the group version kind of a deserialized object.
|
||||
type DirectDecoder struct {
|
||||
runtime.Decoder
|
||||
}
|
||||
|
||||
// Decode does not do conversion. It removes the gvk during deserialization.
|
||||
func (d DirectDecoder) Decode(data []byte, defaults *unversioned.GroupVersionKind, into runtime.Object) (runtime.Object, *unversioned.GroupVersionKind, error) {
|
||||
obj, gvk, err := d.Decoder.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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue