summaryrefslogtreecommitdiff
path: root/vendor/k8s.io/apimachinery/pkg/runtime/serializer
diff options
context:
space:
mode:
authorTomSweeneyRedHat <tsweeney@redhat.com>2020-01-14 14:46:46 -0500
committerTomSweeneyRedHat <tsweeney@redhat.com>2020-01-14 14:46:46 -0500
commitf5bda9994d5e6cb1ee42ade5e7786059feedf633 (patch)
tree4473a0c3b4615ee58165f06ccf57a1bfe4298fe9 /vendor/k8s.io/apimachinery/pkg/runtime/serializer
parent564bd693cae4e8a870be7a7860ef673e793f6358 (diff)
downloadpodman-f5bda9994d5e6cb1ee42ade5e7786059feedf633.tar.gz
podman-f5bda9994d5e6cb1ee42ade5e7786059feedf633.tar.bz2
podman-f5bda9994d5e6cb1ee42ade5e7786059feedf633.zip
Bump to Buildah v1.13.1
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
Diffstat (limited to 'vendor/k8s.io/apimachinery/pkg/runtime/serializer')
-rw-r--r--vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go4
-rw-r--r--vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go48
-rw-r--r--vendor/k8s.io/apimachinery/pkg/runtime/serializer/protobuf/protobuf.go59
-rw-r--r--vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go82
4 files changed, 112 insertions, 81 deletions
diff --git a/vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go b/vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go
index d1d407397..f21b0ef19 100644
--- a/vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go
+++ b/vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go
@@ -322,7 +322,3 @@ func (f WithoutConversionCodecFactory) DecoderToVersion(serializer runtime.Decod
Decoder: serializer,
}
}
-
-// DirectCodecFactory was renamed to WithoutConversionCodecFactory in 1.15.
-// TODO: remove in 1.16.
-type DirectCodecFactory = WithoutConversionCodecFactory
diff --git a/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go b/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go
index 69ada8ecf..9d17f09e5 100644
--- a/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go
+++ b/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go
@@ -31,6 +31,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/serializer/recognizer"
"k8s.io/apimachinery/pkg/util/framer"
utilyaml "k8s.io/apimachinery/pkg/util/yaml"
+ "k8s.io/klog"
)
// NewSerializer creates a JSON serializer that handles encoding versioned objects into the proper JSON form. If typer
@@ -53,13 +54,28 @@ func NewYAMLSerializer(meta MetaFactory, creater runtime.ObjectCreater, typer ru
// and are immutable.
func NewSerializerWithOptions(meta MetaFactory, creater runtime.ObjectCreater, typer runtime.ObjectTyper, options SerializerOptions) *Serializer {
return &Serializer{
- meta: meta,
- creater: creater,
- typer: typer,
- options: options,
+ meta: meta,
+ creater: creater,
+ typer: typer,
+ options: options,
+ identifier: identifier(options),
}
}
+// identifier computes Identifier of Encoder based on the given options.
+func identifier(options SerializerOptions) runtime.Identifier {
+ result := map[string]string{
+ "name": "json",
+ "yaml": strconv.FormatBool(options.Yaml),
+ "pretty": strconv.FormatBool(options.Pretty),
+ }
+ identifier, err := json.Marshal(result)
+ if err != nil {
+ klog.Fatalf("Failed marshaling identifier for json Serializer: %v", err)
+ }
+ return runtime.Identifier(identifier)
+}
+
// SerializerOptions holds the options which are used to configure a JSON/YAML serializer.
// example:
// (1) To configure a JSON serializer, set `Yaml` to `false`.
@@ -85,6 +101,8 @@ type Serializer struct {
options SerializerOptions
creater runtime.ObjectCreater
typer runtime.ObjectTyper
+
+ identifier runtime.Identifier
}
// Serializer implements Serializer
@@ -188,16 +206,6 @@ func gvkWithDefaults(actual, defaultGVK schema.GroupVersionKind) schema.GroupVer
// On success or most errors, the method will return the calculated schema kind.
// The gvk calculate priority will be originalData > default gvk > into
func (s *Serializer) Decode(originalData []byte, gvk *schema.GroupVersionKind, into runtime.Object) (runtime.Object, *schema.GroupVersionKind, error) {
- if versioned, ok := into.(*runtime.VersionedObjects); ok {
- into = versioned.Last()
- obj, actual, err := s.Decode(originalData, gvk, into)
- if err != nil {
- return nil, actual, err
- }
- versioned.Objects = []runtime.Object{obj}
- return versioned, actual, nil
- }
-
data := originalData
if s.options.Yaml {
altered, err := yaml.YAMLToJSON(data)
@@ -286,6 +294,13 @@ func (s *Serializer) Decode(originalData []byte, gvk *schema.GroupVersionKind, i
// Encode serializes the provided object to the given writer.
func (s *Serializer) Encode(obj runtime.Object, w io.Writer) error {
+ if co, ok := obj.(runtime.CacheableObject); ok {
+ return co.CacheEncode(s.Identifier(), s.doEncode, w)
+ }
+ return s.doEncode(obj, w)
+}
+
+func (s *Serializer) doEncode(obj runtime.Object, w io.Writer) error {
if s.options.Yaml {
json, err := caseSensitiveJsonIterator.Marshal(obj)
if err != nil {
@@ -311,6 +326,11 @@ func (s *Serializer) Encode(obj runtime.Object, w io.Writer) error {
return encoder.Encode(obj)
}
+// Identifier implements runtime.Encoder interface.
+func (s *Serializer) Identifier() runtime.Identifier {
+ return s.identifier
+}
+
// RecognizesData implements the RecognizingDecoder interface.
func (s *Serializer) RecognizesData(peek io.Reader) (ok, unknown bool, err error) {
if s.options.Yaml {
diff --git a/vendor/k8s.io/apimachinery/pkg/runtime/serializer/protobuf/protobuf.go b/vendor/k8s.io/apimachinery/pkg/runtime/serializer/protobuf/protobuf.go
index 0f33e1d82..f606b7d72 100644
--- a/vendor/k8s.io/apimachinery/pkg/runtime/serializer/protobuf/protobuf.go
+++ b/vendor/k8s.io/apimachinery/pkg/runtime/serializer/protobuf/protobuf.go
@@ -86,6 +86,8 @@ type Serializer struct {
var _ runtime.Serializer = &Serializer{}
var _ recognizer.RecognizingDecoder = &Serializer{}
+const serializerIdentifier runtime.Identifier = "protobuf"
+
// 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,
// the raw data will be extracted and no decoding will be performed. If into is not registered with the typer, then the object will
@@ -93,23 +95,6 @@ var _ recognizer.RecognizingDecoder = &Serializer{}
// not fully qualified with kind/version/group, the type of the into will be used to alter the returned gvk. On success or most
// errors, the method will return the calculated schema kind.
func (s *Serializer) Decode(originalData []byte, gvk *schema.GroupVersionKind, into runtime.Object) (runtime.Object, *schema.GroupVersionKind, error) {
- if versioned, ok := into.(*runtime.VersionedObjects); ok {
- into = versioned.Last()
- obj, actual, err := s.Decode(originalData, gvk, into)
- if err != nil {
- return nil, actual, err
- }
- // the last item in versioned becomes into, so if versioned was not originally empty we reset the object
- // array so the first position is the decoded object and the second position is the outermost object.
- // if there were no objects in the versioned list passed to us, only add ourselves.
- if into != nil && into != obj {
- versioned.Objects = []runtime.Object{obj, into}
- } else {
- versioned.Objects = []runtime.Object{obj}
- }
- return versioned, actual, err
- }
-
prefixLen := len(s.prefix)
switch {
case len(originalData) == 0:
@@ -176,6 +161,13 @@ func (s *Serializer) Decode(originalData []byte, gvk *schema.GroupVersionKind, i
// Encode serializes the provided object to the given writer.
func (s *Serializer) Encode(obj runtime.Object, w io.Writer) error {
+ if co, ok := obj.(runtime.CacheableObject); ok {
+ return co.CacheEncode(s.Identifier(), s.doEncode, w)
+ }
+ return s.doEncode(obj, w)
+}
+
+func (s *Serializer) doEncode(obj runtime.Object, w io.Writer) error {
prefixSize := uint64(len(s.prefix))
var unk runtime.Unknown
@@ -245,6 +237,11 @@ func (s *Serializer) Encode(obj runtime.Object, w io.Writer) error {
}
}
+// Identifier implements runtime.Encoder interface.
+func (s *Serializer) Identifier() runtime.Identifier {
+ return serializerIdentifier
+}
+
// RecognizesData implements the RecognizingDecoder interface.
func (s *Serializer) RecognizesData(peek io.Reader) (bool, bool, error) {
prefix := make([]byte, 4)
@@ -321,6 +318,8 @@ type RawSerializer struct {
var _ runtime.Serializer = &RawSerializer{}
+const rawSerializerIdentifier runtime.Identifier = "raw-protobuf"
+
// 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,
// the raw data will be extracted and no decoding will be performed. If into is not registered with the typer, then the object will
@@ -332,20 +331,6 @@ func (s *RawSerializer) Decode(originalData []byte, gvk *schema.GroupVersionKind
return nil, nil, fmt.Errorf("this serializer requires an object to decode into: %#v", s)
}
- if versioned, ok := into.(*runtime.VersionedObjects); ok {
- into = versioned.Last()
- obj, actual, err := s.Decode(originalData, gvk, into)
- if err != nil {
- return nil, actual, err
- }
- if into != nil && into != obj {
- versioned.Objects = []runtime.Object{obj, into}
- } else {
- versioned.Objects = []runtime.Object{obj}
- }
- return versioned, actual, err
- }
-
if len(originalData) == 0 {
// TODO: treat like decoding {} from JSON with defaulting
return nil, nil, fmt.Errorf("empty data")
@@ -419,6 +404,13 @@ func unmarshalToObject(typer runtime.ObjectTyper, creater runtime.ObjectCreater,
// Encode serializes the provided object to the given writer. Overrides is ignored.
func (s *RawSerializer) Encode(obj runtime.Object, w io.Writer) error {
+ if co, ok := obj.(runtime.CacheableObject); ok {
+ return co.CacheEncode(s.Identifier(), s.doEncode, w)
+ }
+ return s.doEncode(obj, w)
+}
+
+func (s *RawSerializer) doEncode(obj runtime.Object, w io.Writer) error {
switch t := obj.(type) {
case bufferedReverseMarshaller:
// this path performs a single allocation during write but requires the caller to implement
@@ -460,6 +452,11 @@ func (s *RawSerializer) Encode(obj runtime.Object, w io.Writer) error {
}
}
+// Identifier implements runtime.Encoder interface.
+func (s *RawSerializer) Identifier() runtime.Identifier {
+ return rawSerializerIdentifier
+}
+
var LengthDelimitedFramer = lengthDelimitedFramer{}
type lengthDelimitedFramer struct{}
diff --git a/vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go b/vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go
index ee5cb86f7..ced184c91 100644
--- a/vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go
+++ b/vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go
@@ -17,12 +17,15 @@ limitations under the License.
package versioning
import (
+ "encoding/json"
"io"
"reflect"
+ "sync"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
+ "k8s.io/klog"
)
// NewDefaultingCodecForScheme is a convenience method for callers that are using a scheme.
@@ -62,6 +65,8 @@ func NewCodec(
encodeVersion: encodeVersion,
decodeVersion: decodeVersion,
+ identifier: identifier(encodeVersion, encoder),
+
originalSchemeName: originalSchemeName,
}
return internal
@@ -78,19 +83,47 @@ type codec struct {
encodeVersion runtime.GroupVersioner
decodeVersion runtime.GroupVersioner
+ identifier runtime.Identifier
+
// originalSchemeName is optional, but when filled in it holds the name of the scheme from which this codec originates
originalSchemeName string
}
+var identifiersMap sync.Map
+
+type codecIdentifier struct {
+ EncodeGV string `json:"encodeGV,omitempty"`
+ Encoder string `json:"encoder,omitempty"`
+ Name string `json:"name,omitempty"`
+}
+
+// identifier computes Identifier of Encoder based on codec parameters.
+func identifier(encodeGV runtime.GroupVersioner, encoder runtime.Encoder) runtime.Identifier {
+ result := codecIdentifier{
+ Name: "versioning",
+ }
+
+ if encodeGV != nil {
+ result.EncodeGV = encodeGV.Identifier()
+ }
+ if encoder != nil {
+ result.Encoder = string(encoder.Identifier())
+ }
+ if id, ok := identifiersMap.Load(result); ok {
+ return id.(runtime.Identifier)
+ }
+ identifier, err := json.Marshal(result)
+ if err != nil {
+ klog.Fatalf("Failed marshaling identifier for codec: %v", err)
+ }
+ identifiersMap.Store(result, runtime.Identifier(identifier))
+ return runtime.Identifier(identifier)
+}
+
// Decode attempts a decode of the object, then tries to convert it to the internal version. If into is provided and the decoding is
// successful, the returned runtime.Object will be the value passed as into. Note that this may bypass conversion if you pass an
// into that matches the serialized version.
func (c *codec) Decode(data []byte, defaultGVK *schema.GroupVersionKind, into runtime.Object) (runtime.Object, *schema.GroupVersionKind, error) {
- versioned, isVersioned := into.(*runtime.VersionedObjects)
- if isVersioned {
- into = versioned.Last()
- }
-
// If the into object is unstructured and expresses an opinion about its group/version,
// create a new instance of the type so we always exercise the conversion path (skips short-circuiting on `into == obj`)
decodeInto := into
@@ -115,22 +148,11 @@ func (c *codec) Decode(data []byte, defaultGVK *schema.GroupVersionKind, into ru
if into != nil {
// perform defaulting if requested
if c.defaulter != nil {
- // create a copy to ensure defaulting is not applied to the original versioned objects
- if isVersioned {
- versioned.Objects = []runtime.Object{obj.DeepCopyObject()}
- }
c.defaulter.Default(obj)
- } else {
- if isVersioned {
- versioned.Objects = []runtime.Object{obj}
- }
}
// Short-circuit conversion if the into object is same object
if into == obj {
- if isVersioned {
- return versioned, gvk, nil
- }
return into, gvk, nil
}
@@ -138,19 +160,9 @@ func (c *codec) Decode(data []byte, defaultGVK *schema.GroupVersionKind, into ru
return nil, gvk, err
}
- if isVersioned {
- versioned.Objects = append(versioned.Objects, into)
- return versioned, gvk, nil
- }
return into, gvk, nil
}
- // Convert if needed.
- if isVersioned {
- // create a copy, because ConvertToVersion does not guarantee non-mutation of objects
- versioned.Objects = []runtime.Object{obj.DeepCopyObject()}
- }
-
// perform defaulting if requested
if c.defaulter != nil {
c.defaulter.Default(obj)
@@ -160,18 +172,19 @@ func (c *codec) Decode(data []byte, defaultGVK *schema.GroupVersionKind, into ru
if err != nil {
return nil, gvk, err
}
- if isVersioned {
- if versioned.Last() != out {
- versioned.Objects = append(versioned.Objects, out)
- }
- return versioned, gvk, nil
- }
return out, gvk, nil
}
// 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 co, ok := obj.(runtime.CacheableObject); ok {
+ return co.CacheEncode(c.Identifier(), c.doEncode, w)
+ }
+ return c.doEncode(obj, w)
+}
+
+func (c *codec) doEncode(obj runtime.Object, w io.Writer) error {
switch obj := obj.(type) {
case *runtime.Unknown:
return c.encoder.Encode(obj, w)
@@ -230,3 +243,8 @@ func (c *codec) Encode(obj runtime.Object, w io.Writer) error {
// Conversion is responsible for setting the proper group, version, and kind onto the outgoing object
return c.encoder.Encode(out, w)
}
+
+// Identifier implements runtime.Encoder interface.
+func (c *codec) Identifier() runtime.Identifier {
+ return c.identifier
+}