Documentation ¶
Overview ¶
Package runtime defines conversions between generic types and structs to map query strings to struct objects.
Package runtime includes helper functions for working with API objects that follow the kubernetes API object conventions, which are:
0. Your API objects have a common metadata struct member, TypeMeta.
1. Your code refers to an internal set of API objects.
2. In a separate package, you have an external set of API objects.
3. The external set is considered to be versioned, and no breaking changes are ever made to it (fields may be added but not changed or removed).
4. As your api evolves, you'll make an additional versioned package with every major change.
5. Versioned packages have conversion functions which convert to and from the internal version.
6. You'll continue to support older versions according to your deprecation policy, and you can easily provide a program/library to update old versions into new versions because of 5.
7. All of your serializations and deserializations are handled in a centralized place.
Package runtime provides a conversion helper to make 5 easy, and the Encode/Decode/DecodeInto trio to accomplish 7. You can also register additional "codecs" which use a version of your choice. It's recommended that you register your types with runtime in your package's init function.
As a bonus, a few common types useful from all api objects and versions are provided in types.go.
Index ¶
- Constants
- Variables
- func AsStrictDecodingError(err error) (*strictDecodingError, bool)
- func CheckCodec(c Codec, internalType Object, externalTypes ...schema.GroupVersionKind) error
- func Convert_Slice_string_To_Pointer_bool(in *[]string, out **bool, s conversion.Scope) error
- func Convert_Slice_string_To_Pointer_int64(in *[]string, out **int64, s conversion.Scope) error
- func Convert_Slice_string_To_bool(in *[]string, out *bool, s conversion.Scope) error
- func Convert_Slice_string_To_int(in *[]string, out *int, s conversion.Scope) error
- func Convert_Slice_string_To_int64(in *[]string, out *int64, s conversion.Scope) error
- func Convert_Slice_string_To_string(in *[]string, out *string, s conversion.Scope) error
- func Convert_runtime_Object_To_runtime_RawExtension(in *Object, out *RawExtension, s conversion.Scope) error
- func Convert_runtime_RawExtension_To_runtime_Object(in *RawExtension, out *Object, s conversion.Scope) error
- func Convert_string_To_Pointer_int64(in *string, out **int64, s conversion.Scope) error
- func Convert_string_To_int64(in *string, out *int64, s conversion.Scope) error
- func DecodeInto(d Decoder, data []byte, into Object) error
- func DecodeList(objects []Object, decoders ...Decoder) []error
- func DeepCopyJSON(x map[string]interface{}) map[string]interface{}
- func DeepCopyJSONValue(x interface{}) interface{}
- func DefaultMetaV1FieldSelectorConversion(label, value string) (string, string, error)
- func Encode(e Encoder, obj Object) ([]byte, error)
- func EncodeList(e Encoder, objects []Object) error
- func EncodeOrDie(e Encoder, obj Object) string
- func Field(v reflect.Value, fieldName string, dest interface{}) error
- func FieldPtr(v reflect.Value, fieldName string, dest interface{}) error
- func IsMissingKind(err error) bool
- func IsMissingVersion(err error) bool
- func IsNotRegisteredError(err error) bool
- func IsStrictDecodingError(err error) bool
- func JSONKeyMapper(key string, sourceTag, destTag reflect.StructTag) (string, string)
- func NewMissingKindErr(data string) error
- func NewMissingVersionErr(data string) error
- func NewNotRegisteredErrForKind(schemeName string, gvk schema.GroupVersionKind) error
- func NewNotRegisteredErrForTarget(schemeName string, t reflect.Type, target GroupVersioner) error
- func NewNotRegisteredErrForType(schemeName string, t reflect.Type) error
- func NewNotRegisteredGVKErrForTarget(schemeName string, gvk schema.GroupVersionKind, target GroupVersioner) error
- func NewStrictDecodingError(errors []error) error
- func NewTestUnstructuredConverterWithValidation(comparison conversion.Equalities) *unstructuredConverter
- func RegisterEmbeddedConversions(s *Scheme) error
- func RegisterStringConversions(s *Scheme) error
- func SetField(src interface{}, v reflect.Value, fieldName string) error
- func SetZeroValue(objPtr Object) error
- func VerifySwaggerDocsExist(kubeTypes []KubeTypes, w io.Writer) (int, error)
- func WriteSwaggerDocFunc(kubeTypes []KubeTypes, w io.Writer) error
- type Allocator
- type CacheableObject
- type ClientNegotiator
- type Codec
- type Decoder
- type Encoder
- type EncoderWithAllocator
- type EquivalentResourceMapper
- type EquivalentResourceRegistry
- type FieldLabelConversionFunc
- type Framer
- type GroupVersioner
- type Identifier
- type KubeTypes
- type MemoryAllocator
- type MultiObjectTyper
- type Namer
- type NegotiateError
- type NegotiatedSerializer
- type NestedObjectDecoder
- type NestedObjectEncoder
- type NondeterministicEncoder
- type NoopDecoder
- type NoopEncoder
- type Object
- func Decode(d Decoder, data []byte) (Object, error)
- func NewEncodable(e Encoder, obj Object, versions ...schema.GroupVersion) Object
- func NewEncodableList(e Encoder, objects []Object, versions ...schema.GroupVersion) []Object
- func UseOrCreateObject(t ObjectTyper, c ObjectCreater, gvk schema.GroupVersionKind, obj Object) (Object, error)
- type ObjectConvertor
- type ObjectCreater
- type ObjectDefaulter
- type ObjectTyper
- type ObjectVersioner
- type Pair
- type ParameterCodec
- type ProtobufMarshaller
- type ProtobufReverseMarshaller
- type RawExtension
- func (in *RawExtension) DeepCopy() *RawExtension
- func (in *RawExtension) DeepCopyInto(out *RawExtension)
- func (*RawExtension) Descriptor() ([]byte, []int)
- func (m *RawExtension) Marshal() (dAtA []byte, err error)
- func (re RawExtension) MarshalCBOR() ([]byte, error)
- func (re RawExtension) MarshalJSON() ([]byte, error)
- func (m *RawExtension) MarshalTo(dAtA []byte) (int, error)
- func (m *RawExtension) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*RawExtension) ProtoMessage()
- func (m *RawExtension) Reset()
- func (m *RawExtension) Size() (n int)
- func (this *RawExtension) String() string
- func (m *RawExtension) Unmarshal(dAtA []byte) error
- func (re *RawExtension) UnmarshalCBOR(in []byte) error
- func (re *RawExtension) UnmarshalJSON(in []byte) error
- func (m *RawExtension) XXX_DiscardUnknown()
- func (m *RawExtension) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *RawExtension) XXX_Merge(src proto.Message)
- func (m *RawExtension) XXX_Size() int
- func (m *RawExtension) XXX_Unmarshal(b []byte) error
- type ResourceVersioner
- type Scheme
- func (s *Scheme) AddConversionFunc(a, b interface{}, fn conversion.ConversionFunc) error
- func (s *Scheme) AddFieldLabelConversionFunc(gvk schema.GroupVersionKind, conversionFunc FieldLabelConversionFunc) error
- func (s *Scheme) AddGeneratedConversionFunc(a, b interface{}, fn conversion.ConversionFunc) error
- func (s *Scheme) AddIgnoredConversionType(from, to interface{}) error
- func (s *Scheme) AddKnownTypeWithName(gvk schema.GroupVersionKind, obj Object)
- func (s *Scheme) AddKnownTypes(gv schema.GroupVersion, types ...Object)
- func (s *Scheme) AddTypeDefaultingFunc(srcType Object, fn func(interface{}))
- func (s *Scheme) AddUnversionedTypes(version schema.GroupVersion, types ...Object)
- func (s *Scheme) AllKnownTypes() map[schema.GroupVersionKind]reflect.Type
- func (s *Scheme) Convert(in, out interface{}, context interface{}) error
- func (s *Scheme) ConvertFieldLabel(gvk schema.GroupVersionKind, label, value string) (string, string, error)
- func (s *Scheme) ConvertToVersion(in Object, target GroupVersioner) (Object, error)
- func (s *Scheme) Converter() *conversion.Converter
- func (s *Scheme) Default(src Object)
- func (s *Scheme) IsGroupRegistered(group string) bool
- func (s *Scheme) IsUnversioned(obj Object) (bool, bool)
- func (s *Scheme) IsVersionRegistered(version schema.GroupVersion) bool
- func (s *Scheme) KnownTypes(gv schema.GroupVersion) map[string]reflect.Type
- func (s *Scheme) Name() string
- func (s *Scheme) New(kind schema.GroupVersionKind) (Object, error)
- func (s *Scheme) ObjectKinds(obj Object) ([]schema.GroupVersionKind, bool, error)
- func (s *Scheme) PreferredVersionAllGroups() []schema.GroupVersion
- func (s *Scheme) PrioritizedVersionsAllGroups() []schema.GroupVersion
- func (s *Scheme) PrioritizedVersionsForGroup(group string) []schema.GroupVersion
- func (s *Scheme) Recognizes(gvk schema.GroupVersionKind) bool
- func (s *Scheme) SetVersionPriority(versions ...schema.GroupVersion) error
- func (s *Scheme) UnsafeConvertToVersion(in Object, target GroupVersioner) (Object, error)
- func (s *Scheme) VersionsForGroupKind(gk schema.GroupKind) []schema.GroupVersion
- type SchemeBuilder
- type Serializer
- type SerializerInfo
- type SimpleAllocator
- type Splice
- type StorageSerializer
- type StreamSerializerInfo
- type TypeMeta
- func (*TypeMeta) Descriptor() ([]byte, []int)
- func (obj *TypeMeta) GetObjectKind() schema.ObjectKind
- func (obj *TypeMeta) GroupVersionKind() schema.GroupVersionKind
- func (m *TypeMeta) Marshal() (dAtA []byte, err error)
- func (m *TypeMeta) MarshalTo(dAtA []byte) (int, error)
- func (m *TypeMeta) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*TypeMeta) ProtoMessage()
- func (m *TypeMeta) Reset()
- func (obj *TypeMeta) SetGroupVersionKind(gvk schema.GroupVersionKind)
- func (m *TypeMeta) Size() (n int)
- func (this *TypeMeta) String() string
- func (m *TypeMeta) Unmarshal(dAtA []byte) error
- func (m *TypeMeta) XXX_DiscardUnknown()
- func (m *TypeMeta) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *TypeMeta) XXX_Merge(src proto.Message)
- func (m *TypeMeta) XXX_Size() int
- func (m *TypeMeta) XXX_Unmarshal(b []byte) error
- type Unknown
- func (in *Unknown) DeepCopy() *Unknown
- func (in *Unknown) DeepCopyInto(out *Unknown)
- func (in *Unknown) DeepCopyObject() Object
- func (*Unknown) Descriptor() ([]byte, []int)
- func (m *Unknown) Marshal() (dAtA []byte, err error)
- func (e Unknown) MarshalJSON() ([]byte, error)
- func (m *Unknown) MarshalTo(dAtA []byte) (int, error)
- func (m *Unknown) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (m *Unknown) NestedMarshalTo(data []byte, b ProtobufMarshaller, size uint64) (int, error)
- func (*Unknown) ProtoMessage()
- func (m *Unknown) Reset()
- func (m *Unknown) Size() (n int)
- func (this *Unknown) String() string
- func (m *Unknown) Unmarshal(dAtA []byte) error
- func (e *Unknown) UnmarshalJSON(in []byte) error
- func (m *Unknown) XXX_DiscardUnknown()
- func (m *Unknown) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Unknown) XXX_Merge(src proto.Message)
- func (m *Unknown) XXX_Size() int
- func (m *Unknown) XXX_Unmarshal(b []byte) error
- type Unstructured
- type UnstructuredConverter
- type WithVersionEncoder
- type WithoutVersionDecoder
Constants ¶
const ( ContentTypeJSON string = "application/json" ContentTypeYAML string = "application/yaml" ContentTypeProtobuf string = "application/vnd.kubernetes.protobuf" ContentTypeCBOR string = "application/cbor" // RFC 8949 ContentTypeCBORSequence string = "application/cbor-seq" // RFC 8742 )
const ( // APIVersionInternal may be used if you are registering a type that should not // be considered stable or serialized - it is a convention only and has no // special behavior in this package. APIVersionInternal = "__internal" )
Variables ¶
var ( ErrInvalidLengthGenerated = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowGenerated = fmt.Errorf("proto: integer overflow") ErrUnexpectedEndOfGroupGenerated = fmt.Errorf("proto: unexpected end of group") )
var AllocatorPool = sync.Pool{ New: func() interface{} { return &Allocator{} }, }
AllocatorPool simply stores Allocator objects to avoid additional memory allocations by caching created but unused items for later reuse, relieving pressure on the garbage collector.
Usage:
memoryAllocator := runtime.AllocatorPool.Get().(*runtime.Allocator) defer runtime.AllocatorPool.Put(memoryAllocator)
A note for future:
consider introducing multiple pools for storing buffers of different sizes perhaps this could allow us to be more efficient.
var DefaultFramer = defaultFramer{}
DefaultFramer is valid for any stream that can read objects serially without any separation in the stream.
var ( // DefaultUnstructuredConverter performs unstructured to Go typed object conversions. DefaultUnstructuredConverter = &unstructuredConverter{ mismatchDetection: parseBool(os.Getenv("KUBE_PATCH_CONVERSION_DETECTOR")), comparison: conversion.EqualitiesOrDie( func(a, b time.Time) bool { return a.UTC() == b.UTC() }, ), } )
Functions ¶
func AsStrictDecodingError ¶ added in v0.23.0
AsStrictDecodingError returns a strict decoding error containing all the strictness violations.
func CheckCodec ¶
func CheckCodec(c Codec, internalType Object, externalTypes ...schema.GroupVersionKind) error
CheckCodec makes sure that the codec can encode objects like internalType, decode all of the external types listed, and also decode them into the given object. (Will modify internalObject.) (Assumes JSON serialization.) TODO: verify that the correct external version is chosen on encode...
func Convert_Slice_string_To_Pointer_bool ¶ added in v0.17.0
func Convert_Slice_string_To_Pointer_bool(in *[]string, out **bool, s conversion.Scope) error
Convert_Slice_string_To_bool will convert a string parameter to boolean. Only the absence of a value (i.e. zero-length slice), a value of "false", or a value of "0" resolve to false. Any other value (including empty string) resolves to true.
func Convert_Slice_string_To_Pointer_int64 ¶ added in v0.17.0
func Convert_Slice_string_To_Pointer_int64(in *[]string, out **int64, s conversion.Scope) error
func Convert_Slice_string_To_bool ¶
func Convert_Slice_string_To_bool(in *[]string, out *bool, s conversion.Scope) error
Convert_Slice_string_To_bool will convert a string parameter to boolean. Only the absence of a value (i.e. zero-length slice), a value of "false", or a value of "0" resolve to false. Any other value (including empty string) resolves to true.
func Convert_Slice_string_To_int ¶
func Convert_Slice_string_To_int(in *[]string, out *int, s conversion.Scope) error
func Convert_Slice_string_To_int64 ¶
func Convert_Slice_string_To_int64(in *[]string, out *int64, s conversion.Scope) error
func Convert_Slice_string_To_string ¶
func Convert_Slice_string_To_string(in *[]string, out *string, s conversion.Scope) error
func Convert_runtime_Object_To_runtime_RawExtension ¶
func Convert_runtime_Object_To_runtime_RawExtension(in *Object, out *RawExtension, s conversion.Scope) error
func Convert_runtime_RawExtension_To_runtime_Object ¶
func Convert_runtime_RawExtension_To_runtime_Object(in *RawExtension, out *Object, s conversion.Scope) error
func Convert_string_To_Pointer_int64 ¶ added in v0.17.0
func Convert_string_To_Pointer_int64(in *string, out **int64, s conversion.Scope) error
func Convert_string_To_int64 ¶ added in v0.17.0
func Convert_string_To_int64(in *string, out *int64, s conversion.Scope) error
func DecodeInto ¶
DecodeInto performs a Decode into the provided object.
func DecodeList ¶
DecodeList alters the list in place, attempting to decode any objects found in the list that have the Unknown type. Any errors that occur are returned after the entire list is processed. Decoders are tried in order.
func DeepCopyJSON ¶
DeepCopyJSON deep copies the passed value, assuming it is a valid JSON representation i.e. only contains types produced by json.Unmarshal() and also int64. bool, int64, float64, string, []interface{}, map[string]interface{}, json.Number and nil
func DeepCopyJSONValue ¶
func DeepCopyJSONValue(x interface{}) interface{}
DeepCopyJSONValue deep copies the passed value, assuming it is a valid JSON representation i.e. only contains types produced by json.Unmarshal() and also int64. bool, int64, float64, string, []interface{}, map[string]interface{}, json.Number and nil
func DefaultMetaV1FieldSelectorConversion ¶
DefaultMetaV1FieldSelectorConversion auto-accepts metav1 values for name and namespace. A cluster scoped resource specifying namespace empty works fine and specifying a particular namespace will return no results, as expected.
func EncodeList ¶
EncodeList ensures that each object in an array is converted to a Unknown{} in serialized form. TODO: accept a content type.
func EncodeOrDie ¶
EncodeOrDie is a version of Encode which will panic instead of returning an error. For tests.
func Field ¶
Field puts the value of fieldName, which must be a member of v, into dest, which must be a variable to which this field's value can be assigned.
func FieldPtr ¶
FieldPtr puts the address of fieldName, which must be a member of v, into dest, which must be an address of a variable to which this field's address can be assigned.
func IsMissingKind ¶
IsMissingKind returns true if the error indicates that the provided object is missing a 'Kind' field.
func IsMissingVersion ¶
IsMissingVersion returns true if the error indicates that the provided object is missing a 'Version' field.
func IsNotRegisteredError ¶
IsNotRegisteredError returns true if the error indicates the provided object or input data is not registered.
func IsStrictDecodingError ¶
IsStrictDecodingError returns true if the error indicates that the provided object strictness violations.
func JSONKeyMapper ¶
JSONKeyMapper uses the struct tags on a conversion to determine the key value for the other side. Use when mapping from a map[string]* to a struct or vice versa.
func NewMissingKindErr ¶
func NewMissingVersionErr ¶
func NewNotRegisteredErrForKind ¶
func NewNotRegisteredErrForKind(schemeName string, gvk schema.GroupVersionKind) error
func NewNotRegisteredErrForTarget ¶
func NewNotRegisteredErrForTarget(schemeName string, t reflect.Type, target GroupVersioner) error
func NewNotRegisteredGVKErrForTarget ¶
func NewNotRegisteredGVKErrForTarget(schemeName string, gvk schema.GroupVersionKind, target GroupVersioner) error
func NewStrictDecodingError ¶
NewStrictDecodingError creates a new strictDecodingError object.
func NewTestUnstructuredConverterWithValidation ¶ added in v0.23.0
func NewTestUnstructuredConverterWithValidation(comparison conversion.Equalities) *unstructuredConverter
NewTestUnstrucutredConverterWithValidation allows for access to FromUnstructuredWithValidation from within tests.
func RegisterEmbeddedConversions ¶ added in v0.18.0
func RegisterStringConversions ¶ added in v0.18.0
func SetField ¶
SetField puts the value of src, into fieldName, which must be a member of v. The value of src must be assignable to the field.
func SetZeroValue ¶
SetZeroValue would set the object of objPtr to zero value of its type.
func VerifySwaggerDocsExist ¶
VerifySwaggerDocsExist writes in a io.Writer a list of structs and fields that are missing of documentation.
Types ¶
type Allocator ¶ added in v0.24.0
type Allocator struct {
// contains filtered or unexported fields
}
Allocator knows how to allocate memory It exists to make the cost of object serialization cheaper. In some cases, it allows for allocating memory only once and then reusing it. This approach puts less load on GC and leads to less fragmented memory in general.
func (*Allocator) Allocate ¶ added in v0.24.0
Allocate reserves memory for n bytes only if the underlying array doesn't have enough capacity otherwise it returns previously allocated block of memory.
Note that the returned array is not zeroed, it is the caller's responsibility to clean the memory if needed.
type CacheableObject ¶ added in v0.17.0
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 }
CacheableObject allows an object to cache its different serializations to avoid performing the same serialization multiple times.
type ClientNegotiator ¶ added in v0.17.0
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) }
ClientNegotiator handles turning an HTTP content type into the appropriate encoder. Use NewClientNegotiator or NewVersionedClientNegotiator to create this interface from a NegotiatedSerializer.
func NewClientNegotiator ¶ added in v0.17.0
func NewClientNegotiator(serializer NegotiatedSerializer, gv schema.GroupVersion) ClientNegotiator
NewClientNegotiator will attempt to retrieve the appropriate encoder, decoder, or stream decoder for a given content type. Does not perform any conversion, but will encode the object to the desired group, version, and kind. Use when creating a client.
type Codec ¶
type Codec Serializer
Codec is a Serializer that deals with the details of versioning objects. It offers the same interface as Serializer, so this is a marker to consumers that care about the version of the objects they receive.
type Decoder ¶
type Decoder interface { // Decode attempts to deserialize the provided data using either the innate typing of the scheme or the // default kind, group, and version provided. It returns a decoded object as well as the kind, group, and // version from the serialized data, or an error. If into is non-nil, it will be used as the target type // and implementations may choose to use it rather than reallocating an object. However, the object is not // guaranteed to be populated. The returned object is not guaranteed to match into. If defaults are // provided, they are applied to the data by default. If no defaults or partial defaults are provided, the // type of the into may be used to guide conversion decisions. Decode(data []byte, defaults *schema.GroupVersionKind, into Object) (Object, *schema.GroupVersionKind, error) }
Decoder attempts to load an object from data.
type Encoder ¶
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 intended 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 }
Encoder writes objects to a serialized form
func NewEncoderWithAllocator ¶ added in v0.29.0
func NewEncoderWithAllocator(e EncoderWithAllocator, a MemoryAllocator) Encoder
NewEncoderWithAllocator returns a new encoder
func UseNondeterministicEncoding ¶ added in v0.32.0
UseNondeterministicEncoding returns an Encoder that encodes objects using the provided Encoder's EncodeNondeterministic method if it implements NondeterministicEncoder, otherwise it returns the provided Encoder as-is.
type EncoderWithAllocator ¶ added in v0.24.0
type EncoderWithAllocator interface { Encoder // EncodeWithAllocator writes an object to a stream as Encode does. // In addition, it allows for providing a memory allocator for efficient memory usage during object serialization EncodeWithAllocator(obj Object, w io.Writer, memAlloc MemoryAllocator) error }
EncoderWithAllocator serializes objects in a way that allows callers to manage any additional memory allocations.
type EquivalentResourceMapper ¶
type EquivalentResourceMapper interface { // EquivalentResourcesFor returns a list of resources that address the same underlying data as resource. // If subresource is specified, only equivalent resources which also have the same subresource are included. // The specified resource can be included in the returned list. EquivalentResourcesFor(resource schema.GroupVersionResource, subresource string) []schema.GroupVersionResource // KindFor returns the kind expected by the specified resource[/subresource]. // A zero value is returned if the kind is unknown. KindFor(resource schema.GroupVersionResource, subresource string) schema.GroupVersionKind }
EquivalentResourceMapper provides information about resources that address the same underlying data as a specified resource
type EquivalentResourceRegistry ¶
type EquivalentResourceRegistry interface { EquivalentResourceMapper // RegisterKindFor registers the existence of the specified resource[/subresource] along with its expected kind. RegisterKindFor(resource schema.GroupVersionResource, subresource string, kind schema.GroupVersionKind) }
EquivalentResourceRegistry provides an EquivalentResourceMapper interface, and allows registering known resource[/subresource] -> kind
func NewEquivalentResourceRegistry ¶
func NewEquivalentResourceRegistry() EquivalentResourceRegistry
NewEquivalentResourceRegistry creates a resource registry that considers all versions of a GroupResource to be equivalent.
func NewEquivalentResourceRegistryWithIdentity ¶
func NewEquivalentResourceRegistryWithIdentity(keyFunc func(schema.GroupResource) string) EquivalentResourceRegistry
NewEquivalentResourceRegistryWithIdentity creates a resource mapper with a custom identity function. If "" is returned by the function, GroupResource#String is used as the identity. GroupResources with the same identity string are considered equivalent.
type FieldLabelConversionFunc ¶
type FieldLabelConversionFunc func(label, value string) (internalLabel, internalValue string, err error)
FieldLabelConversionFunc converts a field selector to internal representation.
type Framer ¶
type Framer interface { NewFrameReader(r io.ReadCloser) io.ReadCloser NewFrameWriter(w io.Writer) io.Writer }
Framer is a factory for creating readers and writers that obey a particular framing pattern.
type GroupVersioner ¶
type GroupVersioner interface { // KindForGroupVersionKinds returns a desired target group version kind for the given input, or returns ok false if no // target is known. In general, if the return target is not in the input list, the caller is expected to invoke // 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 }
GroupVersioner refines a set of possible conversion targets into a single option.
var ( // InternalGroupVersioner will always prefer the internal version for a given group version kind. InternalGroupVersioner GroupVersioner = internalGroupVersioner{} // DisabledGroupVersioner will reject all kinds passed to it. DisabledGroupVersioner GroupVersioner = disabledGroupVersioner{} )
func NewCoercingMultiGroupVersioner ¶
func NewCoercingMultiGroupVersioner(gv schema.GroupVersion, groupKinds ...schema.GroupKind) GroupVersioner
NewCoercingMultiGroupVersioner returns the provided group version for any incoming kind. Incoming kinds that match the provided groupKinds are preferred. Kind may be empty in the provided group kind, in which case any kind will match. Examples:
gv=mygroup/__internal, groupKinds=mygroup/Foo, anothergroup/Bar KindForGroupVersionKinds(yetanother/v1/Baz, anothergroup/v1/Bar) -> mygroup/__internal/Bar (matched preferred group/kind) gv=mygroup/__internal, groupKinds=mygroup, anothergroup KindForGroupVersionKinds(yetanother/v1/Baz, anothergroup/v1/Bar) -> mygroup/__internal/Bar (matched preferred group) gv=mygroup/__internal, groupKinds=mygroup, anothergroup KindForGroupVersionKinds(yetanother/v1/Baz, yetanother/v1/Bar) -> mygroup/__internal/Baz (no preferred group/kind match, uses first kind in list)
func NewMultiGroupVersioner ¶
func NewMultiGroupVersioner(gv schema.GroupVersion, groupKinds ...schema.GroupKind) GroupVersioner
NewMultiGroupVersioner returns the provided group version for any kind that matches one of the provided group kinds. Kind may be empty in the provided group kind, in which case any kind will match.
type Identifier ¶ added in v0.17.0
type 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 KubeTypes ¶
type KubeTypes []Pair
KubeTypes is an array to represent all available types in a parsed file. [0] is for the type itself
func ParseDocumentationFrom ¶
ParseDocumentationFrom gets all types' documentation and returns them as an array. Each type is again represented as an array (we have to use arrays as we need to be sure for the order of the fields). This function returns fields and struct definitions that have no documentation as {name, ""}.
type MemoryAllocator ¶ added in v0.24.0
type MemoryAllocator interface { // Allocate reserves memory for n bytes. // Note that implementations of this method are not required to zero the returned array. // It is the caller's responsibility to clean the memory if needed. Allocate(n uint64) []byte }
MemoryAllocator is responsible for allocating memory. By encapsulating memory allocation into its own interface, we can reuse the memory across many operations in places we know it can significantly improve the performance.
type MultiObjectTyper ¶
type MultiObjectTyper []ObjectTyper
MultiObjectTyper returns the types of objects across multiple schemes in order.
func (MultiObjectTyper) ObjectKinds ¶
func (m MultiObjectTyper) ObjectKinds(obj Object) (gvks []schema.GroupVersionKind, unversionedType bool, err error)
func (MultiObjectTyper) Recognizes ¶
func (m MultiObjectTyper) Recognizes(gvk schema.GroupVersionKind) bool
type Namer ¶ added in v0.24.0
type Namer interface { // Name returns the name of a given object. Name(obj Object) (string, error) // Namespace returns the name of a given object. Namespace(obj Object) (string, error) }
Namer provides methods for retrieving name and namespace of an API object.
type NegotiateError ¶ added in v0.17.0
NegotiateError is returned when a ClientNegotiator is unable to locate a serializer for the requested operation.
func (NegotiateError) Error ¶ added in v0.17.0
func (e NegotiateError) Error() string
type NegotiatedSerializer ¶
type NegotiatedSerializer interface { // SupportedMediaTypes is the media types supported for reading and writing single objects. SupportedMediaTypes() []SerializerInfo // EncoderForVersion returns an encoder that ensures objects being written to the provided // serializer are in the provided group version. EncoderForVersion(serializer Encoder, gv GroupVersioner) Encoder // DecoderToVersion returns a decoder that ensures objects being read by the provided // serializer are in the provided group version by default. DecoderToVersion(serializer Decoder, gv GroupVersioner) Decoder }
NegotiatedSerializer is an interface used for obtaining encoders, decoders, and serializers for multiple supported media types. This would commonly be accepted by a server component that performs HTTP content negotiation to accept multiple formats.
func NewSimpleNegotiatedSerializer ¶ added in v0.17.0
func NewSimpleNegotiatedSerializer(info SerializerInfo) NegotiatedSerializer
type NestedObjectDecoder ¶
NestedObjectDecoder is an optional interface that objects may implement to be given an opportunity to decode any nested Objects / RawExtensions during serialization. It is possible for DecodeNestedObjects to return a non-nil error but for the decoding to have succeeded in the case of strict decoding errors (e.g. unknown/duplicate fields). As such it is important for callers of DecodeNestedObjects to check to confirm whether an error is a runtime.StrictDecodingError before short circuiting. Similarly, implementations of DecodeNestedObjects should ensure that a runtime.StrictDecodingError is only returned when the rest of decoding has succeeded.
type NestedObjectEncoder ¶
NestedObjectEncoder is an optional interface that objects may implement to be given an opportunity to encode any nested Objects / RawExtensions during serialization.
type NondeterministicEncoder ¶ added in v0.32.0
type NondeterministicEncoder interface { Encoder // EncodeNondeterministic writes an object to the stream. Unlike the Encode method of // Encoder, EncodeNondeterministic does not guarantee that any two invocations will write // the same sequence of bytes to the io.Writer. Any differences will not be significant to a // generic decoder. For example, map entries and struct fields might be encoded in any // order. EncodeNondeterministic(Object, io.Writer) error }
NondeterministicEncoder is implemented by Encoders that can serialize objects more efficiently in cases where the output does not need to be deterministic.
type NoopDecoder ¶
type NoopDecoder struct {
Encoder
}
NoopDecoder converts an Encoder to a Serializer or Codec for code that expects them but only uses encoding.
func (NoopDecoder) Decode ¶
func (n NoopDecoder) Decode(data []byte, gvk *schema.GroupVersionKind, into Object) (Object, *schema.GroupVersionKind, error)
type NoopEncoder ¶
type NoopEncoder struct {
Decoder
}
NoopEncoder converts an Decoder to a Serializer or Codec for code that expects them but only uses decoding.
func (NoopEncoder) Identifier ¶ added in v0.17.0
func (n NoopEncoder) Identifier() Identifier
Identifier implements runtime.Encoder interface.
type Object ¶
type Object interface { GetObjectKind() schema.ObjectKind DeepCopyObject() Object }
Object interface must be supported by all API types registered with Scheme. Since objects in a scheme are expected to be serialized to the wire, the interface an Object must provide to the Scheme allows serializers to set the kind, version, and group the object is represented as. An Object may choose to return a no-op ObjectKindAccessor in cases where it is not expected to be serialized.
func NewEncodable ¶
func NewEncodable(e Encoder, obj Object, versions ...schema.GroupVersion) Object
NewEncodable creates an object that will be encoded with the provided codec on demand. Provided as a convenience for test cases dealing with internal objects.
func NewEncodableList ¶
func NewEncodableList(e Encoder, objects []Object, versions ...schema.GroupVersion) []Object
NewEncodableList creates an object that will be encoded with the provided codec on demand. Provided as a convenience for test cases dealing with internal objects.
func UseOrCreateObject ¶
func UseOrCreateObject(t ObjectTyper, c ObjectCreater, gvk schema.GroupVersionKind, obj Object) (Object, error)
UseOrCreateObject returns obj if the canonical ObjectKind returned by the provided typer matches gvk, or invokes the ObjectCreator to instantiate a new gvk. Returns an error if the typer cannot find the object.
type ObjectConvertor ¶
type ObjectConvertor interface { // Convert attempts to convert one object into another, or returns an error. This // method does not mutate the in object, but the in and out object might share data structures, // i.e. the out object cannot be mutated without mutating the in object as well. // The context argument will be passed to all nested conversions. Convert(in, out, context interface{}) error // ConvertToVersion takes the provided object and converts it the provided version. This // method does not mutate the in object, but the in and out object might share data structures, // i.e. the out object cannot be mutated without mutating the in object as well. // This method is similar to Convert() but handles specific details of choosing the correct // output version. ConvertToVersion(in Object, gv GroupVersioner) (out Object, err error) ConvertFieldLabel(gvk schema.GroupVersionKind, label, value string) (string, string, error) }
ObjectConvertor converts an object to a different version.
func UnsafeObjectConvertor ¶
func UnsafeObjectConvertor(scheme *Scheme) ObjectConvertor
UnsafeObjectConvertor performs object conversion without copying the object structure, for use when the converted object will not be reused or mutated. Primarily for use within versioned codecs, which use the external object for serialization but do not return it.
type ObjectCreater ¶
type ObjectCreater interface {
New(kind schema.GroupVersionKind) (out Object, err error)
}
ObjectCreater contains methods for instantiating an object by kind and version.
type ObjectDefaulter ¶
type ObjectDefaulter interface { // Default takes an object (must be a pointer) and applies any default values. // Defaulters may not error. Default(in Object) }
type ObjectTyper ¶
type ObjectTyper interface { // ObjectKinds returns the all possible group,version,kind of the provided object, true if // the object is unversioned, or an error if the object is not recognized // (IsNotRegisteredError will return true). ObjectKinds(Object) ([]schema.GroupVersionKind, bool, error) // Recognizes returns true if the scheme is able to handle the provided version and kind, // or more precisely that the provided version is a possible conversion or decoding // target. Recognizes(gvk schema.GroupVersionKind) bool }
ObjectTyper contains methods for extracting the APIVersion and Kind of objects.
type ObjectVersioner ¶
type ObjectVersioner interface {
ConvertToVersion(in Object, gv GroupVersioner) (out Object, err error)
}
type Pair ¶
type Pair struct {
Name, Doc string
}
Pair of strings. We keed the name of fields and the doc
type ParameterCodec ¶
type ParameterCodec interface { // DecodeParameters takes the given url.Values in the specified group version and decodes them // into the provided object, or returns an error. DecodeParameters(parameters url.Values, from schema.GroupVersion, into Object) error // EncodeParameters encodes the provided object as query parameters or returns an error. EncodeParameters(obj Object, to schema.GroupVersion) (url.Values, error) }
ParameterCodec defines methods for serializing and deserializing API objects to url.Values and performing any necessary conversion. Unlike the normal Codec, query parameters are not self describing and the desired version must be specified.
func NewParameterCodec ¶
func NewParameterCodec(scheme *Scheme) ParameterCodec
NewParameterCodec creates a ParameterCodec capable of transforming url values into versioned objects and back.
type ProtobufMarshaller ¶
type ProtobufReverseMarshaller ¶ added in v0.16.4
type RawExtension ¶
type RawExtension struct { // Raw is the underlying serialization of this object. // // TODO: Determine how to detect ContentType and ContentEncoding of 'Raw' data. Raw []byte `json:"-" protobuf:"bytes,1,opt,name=raw"` // Object can hold a representation of this extension - useful for working with versioned // structs. Object Object `json:"-"` }
RawExtension is used to hold extensions in external versions.
To use this, make a field which has RawExtension as its type in your external, versioned struct, and Object in your internal struct. You also need to register your various plugin types.
// Internal package:
type MyAPIObject struct { runtime.TypeMeta `json:",inline"` MyPlugin runtime.Object `json:"myPlugin"` } type PluginA struct { AOption string `json:"aOption"` }
// External package:
type MyAPIObject struct { runtime.TypeMeta `json:",inline"` MyPlugin runtime.RawExtension `json:"myPlugin"` } type PluginA struct { AOption string `json:"aOption"` }
// On the wire, the JSON will look something like this:
{ "kind":"MyAPIObject", "apiVersion":"v1", "myPlugin": { "kind":"PluginA", "aOption":"foo", }, }
So what happens? Decode first uses json or yaml to unmarshal the serialized data into your external MyAPIObject. That causes the raw JSON to be stored, but not unpacked. The next step is to copy (using pkg/conversion) into the internal struct. The runtime package's DefaultScheme has conversion functions installed which will unpack the JSON stored in RawExtension, turning it into the correct object type, and storing it in the Object. (TODO: In the case where the object is of an unknown type, a runtime.Unknown object will be created and stored.)
+k8s:deepcopy-gen=true +protobuf=true +k8s:openapi-gen=true
func (*RawExtension) DeepCopy ¶
func (in *RawExtension) DeepCopy() *RawExtension
DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RawExtension.
func (*RawExtension) DeepCopyInto ¶
func (in *RawExtension) DeepCopyInto(out *RawExtension)
DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (*RawExtension) Descriptor ¶
func (*RawExtension) Descriptor() ([]byte, []int)
func (*RawExtension) Marshal ¶
func (m *RawExtension) Marshal() (dAtA []byte, err error)
func (RawExtension) MarshalCBOR ¶ added in v0.31.0
func (re RawExtension) MarshalCBOR() ([]byte, error)
func (RawExtension) MarshalJSON ¶
func (re RawExtension) MarshalJSON() ([]byte, error)
MarshalJSON may get called on pointers or values, so implement MarshalJSON on value. http://stackoverflow.com/questions/21390979/custom-marshaljson-never-gets-called-in-go
func (*RawExtension) MarshalToSizedBuffer ¶ added in v0.16.4
func (m *RawExtension) MarshalToSizedBuffer(dAtA []byte) (int, error)
func (*RawExtension) ProtoMessage ¶
func (*RawExtension) ProtoMessage()
func (*RawExtension) Reset ¶
func (m *RawExtension) Reset()
func (*RawExtension) Size ¶
func (m *RawExtension) Size() (n int)
func (*RawExtension) String ¶
func (this *RawExtension) String() string
func (*RawExtension) Unmarshal ¶
func (m *RawExtension) Unmarshal(dAtA []byte) error
func (*RawExtension) UnmarshalCBOR ¶ added in v0.31.0
func (re *RawExtension) UnmarshalCBOR(in []byte) error
func (*RawExtension) UnmarshalJSON ¶
func (re *RawExtension) UnmarshalJSON(in []byte) error
func (*RawExtension) XXX_DiscardUnknown ¶ added in v0.16.4
func (m *RawExtension) XXX_DiscardUnknown()
func (*RawExtension) XXX_Marshal ¶ added in v0.16.4
func (m *RawExtension) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*RawExtension) XXX_Merge ¶ added in v0.16.4
func (m *RawExtension) XXX_Merge(src proto.Message)
func (*RawExtension) XXX_Size ¶ added in v0.16.4
func (m *RawExtension) XXX_Size() int
func (*RawExtension) XXX_Unmarshal ¶ added in v0.16.4
func (m *RawExtension) XXX_Unmarshal(b []byte) error
type ResourceVersioner ¶
type ResourceVersioner interface { SetResourceVersion(obj Object, version string) error ResourceVersion(obj Object) (string, error) }
ResourceVersioner provides methods for setting and retrieving the resource version from an API object.
type Scheme ¶
type Scheme struct {
// contains filtered or unexported fields
}
Scheme defines methods for serializing and deserializing API objects, a type registry for converting group, version, and kind information to and from Go schemas, and mappings between Go schemas of different versions. A scheme is the foundation for a versioned API and versioned configuration over time.
In a Scheme, a Type is a particular Go struct, a Version is a point-in-time identifier for a particular representation of that Type (typically backwards compatible), a Kind is the unique name for that Type within the Version, and a Group identifies a set of Versions, Kinds, and Types that evolve over time. An Unversioned Type is one that is not yet formally bound to a type and is promised to be backwards compatible (effectively a "v1" of a Type that does not expect to break in the future).
Schemes are not expected to change at runtime and are only threadsafe after registration is complete.
func NewScheme ¶
func NewScheme() *Scheme
NewScheme creates a new Scheme. This scheme is pluggable by default.
func (*Scheme) AddConversionFunc ¶
func (s *Scheme) AddConversionFunc(a, b interface{}, fn conversion.ConversionFunc) error
AddConversionFunc registers a function that converts between a and b by passing objects of those types to the provided function. The function *must* accept objects of a and b - this machinery will not enforce any other guarantee.
func (*Scheme) AddFieldLabelConversionFunc ¶
func (s *Scheme) AddFieldLabelConversionFunc(gvk schema.GroupVersionKind, conversionFunc FieldLabelConversionFunc) error
AddFieldLabelConversionFunc adds a conversion function to convert field selectors of the given kind from the given version to internal version representation.
func (*Scheme) AddGeneratedConversionFunc ¶
func (s *Scheme) AddGeneratedConversionFunc(a, b interface{}, fn conversion.ConversionFunc) error
AddGeneratedConversionFunc registers a function that converts between a and b by passing objects of those types to the provided function. The function *must* accept objects of a and b - this machinery will not enforce any other guarantee.
func (*Scheme) AddIgnoredConversionType ¶
AddIgnoredConversionType identifies a pair of types that should be skipped by conversion (because the data inside them is explicitly dropped during conversion).
func (*Scheme) AddKnownTypeWithName ¶
func (s *Scheme) AddKnownTypeWithName(gvk schema.GroupVersionKind, obj Object)
AddKnownTypeWithName is like AddKnownTypes, but it lets you specify what this type should be encoded as. Useful for testing when you don't want to make multiple packages to define your structs. Version may not be empty - use the APIVersionInternal constant if you have a type that does not have a formal version.
func (*Scheme) AddKnownTypes ¶
func (s *Scheme) AddKnownTypes(gv schema.GroupVersion, types ...Object)
AddKnownTypes registers all types passed in 'types' as being members of version 'version'. All objects passed to types should be pointers to structs. The name that go reports for the struct becomes the "kind" field when encoding. Version may not be empty - use the APIVersionInternal constant if you have a type that does not have a formal version.
func (*Scheme) AddTypeDefaultingFunc ¶
AddTypeDefaultingFunc registers a function that is passed a pointer to an object and can default fields on the object. These functions will be invoked when Default() is called. The function will never be called unless the defaulted object matches srcType. If this function is invoked twice with the same srcType, the fn passed to the later call will be used instead.
func (*Scheme) AddUnversionedTypes ¶
func (s *Scheme) AddUnversionedTypes(version schema.GroupVersion, types ...Object)
AddUnversionedTypes registers the provided types as "unversioned", which means that they follow special rules. Whenever an object of this type is serialized, it is serialized with the provided group version and is not converted. Thus unversioned objects are expected to remain backwards compatible forever, as if they were in an API group and version that would never be updated.
TODO: there is discussion about removing unversioned and replacing it with objects that are manifest into every version with particular schemas. Resolve this method at that point.
func (*Scheme) AllKnownTypes ¶
func (s *Scheme) AllKnownTypes() map[schema.GroupVersionKind]reflect.Type
AllKnownTypes returns the all known types.
func (*Scheme) Convert ¶
Convert will attempt to convert in into out. Both must be pointers. For easy testing of conversion functions. Returns an error if the conversion isn't possible. You can call this with types that haven't been registered (for example, a to test conversion of types that are nested within registered types). The context interface is passed to the convertor. Convert also supports Unstructured types and will convert them intelligently.
func (*Scheme) ConvertFieldLabel ¶
func (s *Scheme) ConvertFieldLabel(gvk schema.GroupVersionKind, label, value string) (string, string, error)
ConvertFieldLabel alters the given field label and value for an kind field selector from versioned representation to an unversioned one or returns an error.
func (*Scheme) ConvertToVersion ¶
func (s *Scheme) ConvertToVersion(in Object, target GroupVersioner) (Object, error)
ConvertToVersion attempts to convert an input object to its matching Kind in another version within this scheme. Will return an error if the provided version does not contain the inKind (or a mapping by name defined with AddKnownTypeWithName). Will also return an error if the conversion does not result in a valid Object being returned. Passes target down to the conversion methods as the Context on the scope.
func (*Scheme) Converter ¶
func (s *Scheme) Converter() *conversion.Converter
Converter allows access to the converter for the scheme
func (*Scheme) IsGroupRegistered ¶
IsGroupRegistered returns true if types for the group have been registered with the scheme
func (*Scheme) IsVersionRegistered ¶
func (s *Scheme) IsVersionRegistered(version schema.GroupVersion) bool
IsVersionRegistered returns true if types for the version have been registered with the scheme
func (*Scheme) KnownTypes ¶
KnownTypes returns the types known for the given version.
func (*Scheme) New ¶
func (s *Scheme) New(kind schema.GroupVersionKind) (Object, error)
New returns a new API object of the given version and name, or an error if it hasn't been registered. The version and kind fields must be specified.
func (*Scheme) ObjectKinds ¶
ObjectKinds returns all possible group,version,kind of the go object, true if the object is considered unversioned, or an error if it's not a pointer or is unregistered.
func (*Scheme) PreferredVersionAllGroups ¶
func (s *Scheme) PreferredVersionAllGroups() []schema.GroupVersion
PreferredVersionAllGroups returns the most preferred version for every group. group ordering is random.
func (*Scheme) PrioritizedVersionsAllGroups ¶
func (s *Scheme) PrioritizedVersionsAllGroups() []schema.GroupVersion
PrioritizedVersionsAllGroups returns all known versions in their priority order. Groups are random, but versions for a single group are prioritized
func (*Scheme) PrioritizedVersionsForGroup ¶
func (s *Scheme) PrioritizedVersionsForGroup(group string) []schema.GroupVersion
PrioritizedVersionsForGroup returns versions for a single group in priority order
func (*Scheme) Recognizes ¶
func (s *Scheme) Recognizes(gvk schema.GroupVersionKind) bool
Recognizes returns true if the scheme is able to handle the provided group,version,kind of an object.
func (*Scheme) SetVersionPriority ¶
func (s *Scheme) SetVersionPriority(versions ...schema.GroupVersion) error
SetVersionPriority allows specifying a precise order of priority. All specified versions must be in the same group, and the specified order overwrites any previously specified order for this group
func (*Scheme) UnsafeConvertToVersion ¶
func (s *Scheme) UnsafeConvertToVersion(in Object, target GroupVersioner) (Object, error)
UnsafeConvertToVersion will convert in to the provided target if such a conversion is possible, but does not guarantee the output object does not share fields with the input object. It attempts to be as efficient as possible when doing conversion.
func (*Scheme) VersionsForGroupKind ¶ added in v0.21.0
func (s *Scheme) VersionsForGroupKind(gk schema.GroupKind) []schema.GroupVersion
VersionsForGroupKind returns the versions that a particular GroupKind can be converted to within the given group. A GroupKind might be converted to a different group. That information is available in EquivalentResourceMapper.
type SchemeBuilder ¶
SchemeBuilder collects functions that add things to a scheme. It's to allow code to compile without explicitly referencing generated types. You should declare one in each package that will have generated deep copy or conversion functions.
func NewSchemeBuilder ¶
func NewSchemeBuilder(funcs ...func(*Scheme) error) SchemeBuilder
NewSchemeBuilder calls Register for you.
func (*SchemeBuilder) AddToScheme ¶
func (sb *SchemeBuilder) AddToScheme(s *Scheme) error
AddToScheme applies all the stored functions to the scheme. A non-nil error indicates that one function failed and the attempt was abandoned.
func (*SchemeBuilder) Register ¶
func (sb *SchemeBuilder) Register(funcs ...func(*Scheme) error)
Register adds a scheme setup function to the list.
type Serializer ¶
Serializer is the core interface for transforming objects into a serialized format and back. Implementations may choose to perform conversion of the object, but no assumptions should be made.
func NewBase64Serializer ¶
func NewBase64Serializer(e Encoder, d Decoder) Serializer
type SerializerInfo ¶
type SerializerInfo struct { // MediaType is the value that represents this serializer over the wire. MediaType string // MediaTypeType is the first part of the MediaType ("application" in "application/json"). MediaTypeType string // MediaTypeSubType is the second part of the MediaType ("json" in "application/json"). MediaTypeSubType string // EncodesAsText indicates this serializer can be encoded to UTF-8 safely. EncodesAsText bool // Serializer is the individual object serializer for this media type. Serializer Serializer // PrettySerializer, if set, can serialize this object in a form biased towards // readability. PrettySerializer Serializer // StrictSerializer, if set, deserializes this object strictly, // erring on unknown fields. StrictSerializer Serializer // StreamSerializer, if set, describes the streaming serialization format // for this media type. StreamSerializer *StreamSerializerInfo }
SerializerInfo contains information about a specific serialization format
func SerializerInfoForMediaType ¶
func SerializerInfoForMediaType(types []SerializerInfo, mediaType string) (SerializerInfo, bool)
SerializerInfoForMediaType returns the first info in types that has a matching media type (which cannot include media-type parameters), or the first info with an empty media type, or false if no type matches.
type SimpleAllocator ¶ added in v0.24.0
type SimpleAllocator struct{}
SimpleAllocator a wrapper around make([]byte) conforms to the MemoryAllocator interface
func (*SimpleAllocator) Allocate ¶ added in v0.24.0
func (sa *SimpleAllocator) Allocate(n uint64) []byte
type Splice ¶ added in v0.28.0
Splice is the interface that wraps the Splice method.
Splice moves data from given slice without copying the underlying data for efficiency purpose. Therefore, the caller should make sure the underlying data is not changed later.
func NewSpliceBuffer ¶ added in v0.28.0
func NewSpliceBuffer() Splice
type StorageSerializer ¶
type StorageSerializer interface { // SupportedMediaTypes are the media types supported for reading and writing objects. SupportedMediaTypes() []SerializerInfo // UniversalDeserializer returns a Serializer that can read objects in multiple supported formats // by introspecting the data at rest. UniversalDeserializer() Decoder // EncoderForVersion returns an encoder that ensures objects being written to the provided // serializer are in the provided group version. EncoderForVersion(serializer Encoder, gv GroupVersioner) Encoder // DecoderForVersion returns a decoder that ensures objects being read by the provided // serializer are in the provided group version by default. DecoderToVersion(serializer Decoder, gv GroupVersioner) Decoder }
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.
type StreamSerializerInfo ¶
type StreamSerializerInfo struct { // EncodesAsText indicates this serializer can be encoded to UTF-8 safely. EncodesAsText bool // Serializer is the top level object serializer for this type when streaming Serializer // Framer is the factory for retrieving streams that separate objects on the wire Framer }
StreamSerializerInfo contains information about a specific stream serialization format
type TypeMeta ¶
type TypeMeta struct { // +optional APIVersion string `json:"apiVersion,omitempty" yaml:"apiVersion,omitempty" protobuf:"bytes,1,opt,name=apiVersion"` // +optional Kind string `json:"kind,omitempty" yaml:"kind,omitempty" protobuf:"bytes,2,opt,name=kind"` }
TypeMeta is shared by all top level objects. The proper way to use it is to inline it in your type, like this:
type MyAwesomeAPIObject struct { runtime.TypeMeta `json:",inline"` ... // other fields }
func (obj *MyAwesomeAPIObject) SetGroupVersionKind(gvk *metav1.GroupVersionKind) { metav1.UpdateTypeMeta(obj,gvk) }; GroupVersionKind() *GroupVersionKind
TypeMeta is provided here for convenience. You may use it directly from this package or define your own with the same fields.
+k8s:deepcopy-gen=false +protobuf=true +k8s:openapi-gen=true
func (*TypeMeta) Descriptor ¶
func (*TypeMeta) GetObjectKind ¶
func (obj *TypeMeta) GetObjectKind() schema.ObjectKind
func (*TypeMeta) GroupVersionKind ¶
func (obj *TypeMeta) GroupVersionKind() schema.GroupVersionKind
GroupVersionKind satisfies the ObjectKind interface for all objects that embed TypeMeta
func (*TypeMeta) MarshalToSizedBuffer ¶ added in v0.16.4
func (*TypeMeta) ProtoMessage ¶
func (*TypeMeta) ProtoMessage()
func (*TypeMeta) SetGroupVersionKind ¶
func (obj *TypeMeta) SetGroupVersionKind(gvk schema.GroupVersionKind)
SetGroupVersionKind satisfies the ObjectKind interface for all objects that embed TypeMeta
func (*TypeMeta) XXX_DiscardUnknown ¶ added in v0.16.4
func (m *TypeMeta) XXX_DiscardUnknown()
func (*TypeMeta) XXX_Marshal ¶ added in v0.16.4
func (*TypeMeta) XXX_Unmarshal ¶ added in v0.16.4
type Unknown ¶
type Unknown struct { TypeMeta `json:",inline" protobuf:"bytes,1,opt,name=typeMeta"` // Raw will hold the complete serialized object which couldn't be matched // with a registered type. Most likely, nothing should be done with this // except for passing it through the system. Raw []byte `json:"-" protobuf:"bytes,2,opt,name=raw"` // ContentEncoding is encoding used to encode 'Raw' data. // Unspecified means no encoding. ContentEncoding string `protobuf:"bytes,3,opt,name=contentEncoding"` // ContentType is serialization method used to serialize 'Raw'. // Unspecified means ContentTypeJSON. ContentType string `protobuf:"bytes,4,opt,name=contentType"` }
Unknown allows api objects with unknown types to be passed-through. This can be used to deal with the API objects from a plug-in. Unknown objects still have functioning TypeMeta features-- kind, version, etc. TODO: Make this object have easy access to field based accessors and settors for metadata and field mutatation.
+k8s:deepcopy-gen=true +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +protobuf=true +k8s:openapi-gen=true
func (*Unknown) DeepCopy ¶
DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Unknown.
func (*Unknown) DeepCopyInto ¶
DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (*Unknown) DeepCopyObject ¶
DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new Object.
func (*Unknown) Descriptor ¶
func (Unknown) MarshalJSON ¶
Marshal may get called on pointers or values, so implement MarshalJSON on value. http://stackoverflow.com/questions/21390979/custom-marshaljson-never-gets-called-in-go
func (*Unknown) MarshalToSizedBuffer ¶ added in v0.16.4
func (*Unknown) NestedMarshalTo ¶
NestedMarshalTo allows a caller to avoid extra allocations during serialization of an Unknown that will contain an object that implements ProtobufMarshaller or ProtobufReverseMarshaller.
func (*Unknown) ProtoMessage ¶
func (*Unknown) ProtoMessage()
func (*Unknown) UnmarshalJSON ¶
func (*Unknown) XXX_DiscardUnknown ¶ added in v0.16.4
func (m *Unknown) XXX_DiscardUnknown()
func (*Unknown) XXX_Marshal ¶ added in v0.16.4
func (*Unknown) XXX_Unmarshal ¶ added in v0.16.4
type Unstructured ¶
type Unstructured interface { Object // NewEmptyInstance returns a new instance of the concrete type containing only kind/apiVersion and no other data. // This should be called instead of reflect.New() for unstructured types because the go type alone does not preserve kind/apiVersion info. NewEmptyInstance() Unstructured // UnstructuredContent returns a non-nil map with this object's contents. Values may be // []interface{}, map[string]interface{}, or any primitive type. Contents are typically serialized to // and from JSON. SetUnstructuredContent should be used to mutate the contents. UnstructuredContent() map[string]interface{} // SetUnstructuredContent updates the object content to match the provided map. SetUnstructuredContent(map[string]interface{}) // IsList returns true if this type is a list or matches the list convention - has an array called "items". IsList() bool // EachListItem should pass a single item out of the list as an Object to the provided function. Any // error should terminate the iteration. If IsList() returns false, this method should return an error // instead of calling the provided function. EachListItem(func(Object) error) error // EachListItemWithAlloc works like EachListItem, but avoids retaining references to a slice of items. // It does this by making a shallow copy of non-pointer items before passing them to fn. // // If the items passed to fn are not retained, or are retained for the same duration, use EachListItem instead for memory efficiency. EachListItemWithAlloc(func(Object) error) error }
Unstructured objects store values as map[string]interface{}, with only values that can be serialized to JSON allowed.
type UnstructuredConverter ¶
type UnstructuredConverter interface { ToUnstructured(obj interface{}) (map[string]interface{}, error) FromUnstructured(u map[string]interface{}, obj interface{}) error }
UnstructuredConverter is an interface for converting between interface{} and map[string]interface representation.
func NewTestUnstructuredConverter ¶
func NewTestUnstructuredConverter(comparison conversion.Equalities) UnstructuredConverter
NewTestUnstructuredConverter creates an UnstructuredConverter that accepts JSON typed maps and translates them to Go types via reflection. It performs mismatch detection automatically and is intended for use by external test tools. Use DefaultUnstructuredConverter if you do not explicitly need mismatch detection.
type WithVersionEncoder ¶
type WithVersionEncoder struct { Version GroupVersioner Encoder ObjectTyper }
WithVersionEncoder serializes an object and ensures the GVK is set.
type WithoutVersionDecoder ¶
type WithoutVersionDecoder struct {
Decoder
}
WithoutVersionDecoder clears the group version kind of a deserialized object.
func (WithoutVersionDecoder) Decode ¶
func (d WithoutVersionDecoder) Decode(data []byte, defaults *schema.GroupVersionKind, into Object) (Object, *schema.GroupVersionKind, error)
Decode does not do conversion. It removes the gvk during deserialization.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cbor/direct
Package direct provides functions for marshaling and unmarshaling between arbitrary Go values and CBOR data, with behavior that is compatible with that of the CBOR serializer.
|
Package direct provides functions for marshaling and unmarshaling between arbitrary Go values and CBOR data, with behavior that is compatible with that of the CBOR serializer. |
protobuf
Package protobuf provides a Kubernetes serializer for the protobuf format.
|
Package protobuf provides a Kubernetes serializer for the protobuf format. |
streaming
Package streaming implements encoder and decoder for streams of runtime.Objects over io.Writer/Readers.
|
Package streaming implements encoder and decoder for streams of runtime.Objects over io.Writer/Readers. |