summaryrefslogtreecommitdiff
path: root/vendor/k8s.io/apimachinery/pkg/runtime/interfaces.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/k8s.io/apimachinery/pkg/runtime/interfaces.go')
-rw-r--r--vendor/k8s.io/apimachinery/pkg/runtime/interfaces.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/vendor/k8s.io/apimachinery/pkg/runtime/interfaces.go b/vendor/k8s.io/apimachinery/pkg/runtime/interfaces.go
index bded5bf15..f44693c0c 100644
--- a/vendor/k8s.io/apimachinery/pkg/runtime/interfaces.go
+++ b/vendor/k8s.io/apimachinery/pkg/runtime/interfaces.go
@@ -37,13 +37,36 @@ type GroupVersioner interface {
// Scheme.New(target) and then perform a conversion between the current Go type and the destination Go type.
// Sophisticated implementations may use additional information about the input kinds to pick a destination kind.
KindForGroupVersionKinds(kinds []schema.GroupVersionKind) (target schema.GroupVersionKind, ok bool)
+ // Identifier returns string representation of the object.
+ // Identifiers of two different encoders should be equal only if for every input
+ // kinds they return the same result.
+ Identifier() string
}
+// Identifier represents an identifier.
+// Identitier of two different objects should be equal if and only if for every
+// input the output they produce is exactly the same.
+type Identifier string
+
// Encoder writes objects to a serialized form
type Encoder interface {
// Encode writes an object to a stream. Implementations may return errors if the versions are
// incompatible, or if no conversion is defined.
Encode(obj Object, w io.Writer) error
+ // Identifier returns an identifier of the encoder.
+ // Identifiers of two different encoders should be equal if and only if for every input
+ // object it will be encoded to the same representation by both of them.
+ //
+ // Identifier is inteted for use with CacheableObject#CacheEncode method. In order to
+ // correctly handle CacheableObject, Encode() method should look similar to below, where
+ // doEncode() is the encoding logic of implemented encoder:
+ // func (e *MyEncoder) Encode(obj Object, w io.Writer) error {
+ // if co, ok := obj.(CacheableObject); ok {
+ // return co.CacheEncode(e.Identifier(), e.doEncode, w)
+ // }
+ // return e.doEncode(obj, w)
+ // }
+ Identifier() Identifier
}
// Decoder attempts to load an object from data.
@@ -132,6 +155,28 @@ type NegotiatedSerializer interface {
DecoderToVersion(serializer Decoder, gv GroupVersioner) Decoder
}
+// ClientNegotiator handles turning an HTTP content type into the appropriate encoder.
+// Use NewClientNegotiator or NewVersionedClientNegotiator to create this interface from
+// a NegotiatedSerializer.
+type ClientNegotiator interface {
+ // Encoder returns the appropriate encoder for the provided contentType (e.g. application/json)
+ // and any optional mediaType parameters (e.g. pretty=1), or an error. If no serializer is found
+ // a NegotiateError will be returned. The current client implementations consider params to be
+ // optional modifiers to the contentType and will ignore unrecognized parameters.
+ Encoder(contentType string, params map[string]string) (Encoder, error)
+ // Decoder returns the appropriate decoder for the provided contentType (e.g. application/json)
+ // and any optional mediaType parameters (e.g. pretty=1), or an error. If no serializer is found
+ // a NegotiateError will be returned. The current client implementations consider params to be
+ // optional modifiers to the contentType and will ignore unrecognized parameters.
+ Decoder(contentType string, params map[string]string) (Decoder, error)
+ // StreamDecoder returns the appropriate stream decoder for the provided contentType (e.g.
+ // application/json) and any optional mediaType parameters (e.g. pretty=1), or an error. If no
+ // serializer is found a NegotiateError will be returned. The Serializer and Framer will always
+ // be returned if a Decoder is returned. The current client implementations consider params to be
+ // optional modifiers to the contentType and will ignore unrecognized parameters.
+ StreamDecoder(contentType string, params map[string]string) (Decoder, Serializer, Framer, error)
+}
+
// StorageSerializer is an interface used for obtaining encoders, decoders, and serializers
// that can read and write data at rest. This would commonly be used by client tools that must
// read files, or server side storage interfaces that persist restful objects.
@@ -256,6 +301,27 @@ type Object interface {
DeepCopyObject() Object
}
+// CacheableObject allows an object to cache its different serializations
+// to avoid performing the same serialization multiple times.
+type CacheableObject interface {
+ // CacheEncode writes an object to a stream. The <encode> function will
+ // be used in case of cache miss. The <encode> function takes ownership
+ // of the object.
+ // If CacheableObject is a wrapper, then deep-copy of the wrapped object
+ // should be passed to <encode> function.
+ // CacheEncode assumes that for two different calls with the same <id>,
+ // <encode> function will also be the same.
+ CacheEncode(id Identifier, encode func(Object, io.Writer) error, w io.Writer) error
+ // GetObject returns a deep-copy of an object to be encoded - the caller of
+ // GetObject() is the owner of returned object. The reason for making a copy
+ // is to avoid bugs, where caller modifies the object and forgets to copy it,
+ // thus modifying the object for everyone.
+ // The object returned by GetObject should be the same as the one that is supposed
+ // to be passed to <encode> function in CacheEncode method.
+ // If CacheableObject is a wrapper, the copy of wrapped object should be returned.
+ GetObject() Object
+}
+
// Unstructured objects store values as map[string]interface{}, with only values that can be serialized
// to JSON allowed.
type Unstructured interface {