runtime

package
v1.2.0-origin Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2016 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

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:

  1. Your API objects have a common metadata struct member, TypeMeta.
  2. Your code refers to an internal set of API objects.
  3. In a separate package, you have an external set of API objects.
  4. 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).
  5. As your api evolves, you'll make an additional versioned package with every major change.
  6. Versioned packages have conversion functions which convert to and from the internal version.
  7. 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.
  8. 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

View Source
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

View Source
var DefaultStringConversions = []interface{}{
	convertStringSliceToString,
	convertStringSliceToInt,
	convertStringSliceToBool,
	convertStringSliceToInt64,
}

DefaultStringConversions are helpers for converting []string and string to real values.

Functions

func DecodeInto added in v1.2.0

func DecodeInto(d Decoder, data []byte, into Object) error

DecodeInto performs a Decode into the provided object.

func DecodeList added in v0.17.0

func DecodeList(objects []Object, decoders ...Decoder) []error

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 DefaultEmbeddedConversions added in v1.2.0

func DefaultEmbeddedConversions() []interface{}

func Encode added in v1.2.0

func Encode(e Encoder, obj Object, overrides ...unversioned.GroupVersion) ([]byte, error)

Encode is a convenience wrapper for encoding to a []byte from an Encoder

func EncodeList added in v1.2.0

func EncodeList(e Encoder, objects []Object, overrides ...unversioned.GroupVersion) error

EncodeList ensures that each object in an array is converted to a Unknown{} in serialized form. TODO: accept a content type.

func EncodeOrDie

func EncodeOrDie(e Encoder, obj Object) string

EncodeOrDie is a version of Encode which will panic instead of returning an error. For tests.

func FieldPtr added in v0.10.0

func FieldPtr(v reflect.Value, fieldName string, dest interface{}) error

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 added in v0.12.0

func IsMissingKind(err error) bool

IsMissingKind returns true if the error indicates that the provided object is missing a 'Kind' field.

func IsMissingVersion added in v0.12.0

func IsMissingVersion(err error) bool

func IsNotRegisteredError added in v0.7.0

func IsNotRegisteredError(err error) bool

IsNotRegisteredError returns true if the error indicates the provided object or input data is not registered.

func JSONKeyMapper added in v0.14.0

func JSONKeyMapper(key string, sourceTag, destTag reflect.StructTag) (string, string)

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 added in v1.2.0

func NewMissingKindErr(data string) error

func NewMissingVersionErr added in v1.2.0

func NewMissingVersionErr(data string) error

IsMissingVersion returns true if the error indicates that the provided object is missing a 'Versioj' field.

func NewNotRegisteredErr added in v1.2.0

func NewNotRegisteredErr(gvk unversioned.GroupVersionKind, t reflect.Type) error

NewNotRegisteredErr is exposed for testing.

func VerifySwaggerDocsExist added in v1.1.0

func VerifySwaggerDocsExist(kubeTypes []KubeTypes, w io.Writer) (int, error)

VerifySwaggerDocsExist writes in a io.Writer a list of structs and fields that are missing of documentation.

func WriteSwaggerDocFunc added in v1.1.0

func WriteSwaggerDocFunc(kubeTypes []KubeTypes, w io.Writer) error

WriteSwaggerDocFunc writes a declaration of a function as a string. This function is used in Swagger as a documentation source for structs and theirs fields

Types

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.

var UnstructuredJSONScheme Codec = unstructuredJSONScheme{}

UnstructuredJSONScheme is capable of converting JSON data into the Unstructured type, which can be used for generic access to objects without a predefined scheme. TODO: move into serializer/json.

func NewCodec added in v1.2.0

func NewCodec(e Encoder, d Decoder) Codec

NewCodec creates a Codec from an Encoder and Decoder.

type ConversionGenerator added in v0.18.0

type ConversionGenerator interface {
	GenerateConversionsForType(groupVersion unversioned.GroupVersion, reflection reflect.Type) error
	WriteConversionFunctions(w io.Writer) error
	RegisterConversionFunctions(w io.Writer, pkg string) error
	AddImport(pkg string) string
	RepackImports(exclude sets.String)
	WriteImports(w io.Writer) error
	OverwritePackage(pkg, overwrite string)
	AssumePrivateConversions()
}

func NewConversionGenerator added in v0.18.0

func NewConversionGenerator(scheme *Scheme, targetPkg string) ConversionGenerator

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 *unversioned.GroupVersionKind, into Object) (Object, *unversioned.GroupVersionKind, error)
}

type DeepCopyGenerator added in v0.18.0

type DeepCopyGenerator interface {
	// Adds a type to a generator.
	// If the type is non-struct, it will return an error, otherwise deep-copy
	// functions for this type and all nested types will be generated.
	AddType(inType reflect.Type) error

	// ReplaceType registers a type that should be used instead of the type
	// with the provided pkgPath and name.
	ReplaceType(pkgPath, name string, in interface{})

	// AddImport registers a package name with the generator and returns its
	// short name.
	AddImport(pkgPath string) string

	// RepackImports creates a stable ordering of import short names
	RepackImports()

	// Writes all imports that are necessary for deep-copy function and
	// their registration.
	WriteImports(w io.Writer) error

	// Writes deel-copy functions for all types added via AddType() method
	// and their nested types.
	WriteDeepCopyFunctions(w io.Writer) error

	// Writes an init() function that registers all the generated deep-copy
	// functions.
	RegisterDeepCopyFunctions(w io.Writer, pkg string) error

	// When generating code, all references to "pkg" package name will be
	// replaced with "overwrite". It is used mainly to replace references
	// to name of the package in which the code will be created with empty
	// string.
	OverwritePackage(pkg, overwrite string)
}

TODO(wojtek-t): As suggested in #8320, we should consider the strategy to first do the shallow copy and then recurse into things that need a deep copy (maps, pointers, slices). That sort of copy function would need one parameter - a pointer to the thing it's supposed to expand, and it would involve a lot less memory copying.

func NewDeepCopyGenerator added in v0.18.0

func NewDeepCopyGenerator(scheme *Scheme, targetPkg string, include sets.String) DeepCopyGenerator

type Encoder

type Encoder interface {
	// EncodeToStream writes an object to a stream. Override versions may be provided for each group
	// that enforce a certain versioning. Implementations may return errors if the versions are incompatible,
	// or if no conversion is defined.
	EncodeToStream(obj Object, stream io.Writer, overrides ...unversioned.GroupVersion) error
}

type FieldLabelConversionFunc added in v0.12.0

type FieldLabelConversionFunc func(label, value string) (internalLabel, internalValue string, err error)

Function to convert a field selector to internal representation.

type KubeTypes added in v1.1.0

type KubeTypes []Pair

KubeTypes is an array to represent all available types in a parsed file. [0] is for the type itself

func ParseDocumentationFrom added in v1.1.0

func ParseDocumentationFrom(src string) []KubeTypes

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 MultiObjectTyper added in v0.16.0

type MultiObjectTyper []ObjectTyper

MultiObjectTyper returns the types of objects across multiple schemes in order.

func (MultiObjectTyper) IsUnversioned added in v1.2.0

func (m MultiObjectTyper) IsUnversioned(obj Object) (bool, bool)

func (MultiObjectTyper) ObjectKind added in v1.2.0

func (m MultiObjectTyper) ObjectKind(obj Object) (gvk unversioned.GroupVersionKind, err error)

func (MultiObjectTyper) ObjectKinds added in v1.2.0

func (m MultiObjectTyper) ObjectKinds(obj Object) (gvks []unversioned.GroupVersionKind, err error)

func (MultiObjectTyper) Recognizes added in v0.17.0

type NegotiatedSerializer added in v1.2.0

type NegotiatedSerializer interface {
	SupportedMediaTypes() []string
	SerializerForMediaType(mediaType string, options map[string]string) (Serializer, bool)
	EncoderForVersion(serializer Serializer, gv unversioned.GroupVersion) Encoder
	DecoderToVersion(serializer Serializer, gv unversioned.GroupVersion) Decoder
}

NegotiatedSerializer is an interface used for obtaining encoders, decoders, and serializers for multiple supported media types.

type NoopDecoder added in v1.2.0

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 added in v1.2.0

type NoopEncoder added in v1.2.0

type NoopEncoder struct {
	Decoder
}

NoopEncoder converts an Decoder to a Serializer or Codec for code that expects them but only uses decoding.

func (NoopEncoder) EncodeToStream added in v1.2.0

func (n NoopEncoder) EncodeToStream(obj Object, w io.Writer, overrides ...unversioned.GroupVersion) error

type Object

type Object interface {
	GetObjectKind() unversioned.ObjectKind
}

All API types registered with Scheme must support the Object interface. 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 Decode added in v1.2.0

func Decode(d Decoder, data []byte) (Object, error)

Decode is a convenience wrapper for decoding data into an Object.

func NewEncodable added in v1.2.0

func NewEncodable(e Encoder, obj Object, versions ...unversioned.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 added in v1.2.0

func NewEncodableList(e Encoder, objects []Object, versions ...unversioned.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 added in v1.2.0

func UseOrCreateObject(t Typer, c ObjectCreater, gvk unversioned.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 added in v0.5.1

type ObjectConvertor interface {
	// Convert attempts to convert one object into another, or returns an error. This method does
	// not guarantee the in object is not mutated.
	Convert(in, out interface{}) error
	// ConvertToVersion takes the provided object and converts it the provided version. This
	// method does not guarantee that the in object is not mutated.
	ConvertToVersion(in Object, outVersion string) (out Object, err error)
	ConvertFieldLabel(version, kind, label, value string) (string, string, error)
}

ObjectConvertor converts an object to a different version.

type ObjectCopier added in v0.17.0

type ObjectCopier interface {
	// Copy returns an exact copy of the provided Object, or an error if the
	// copy could not be completed.
	Copy(Object) (Object, error)
}

ObjectCopier duplicates an object.

type ObjectCreater added in v0.13.0

type ObjectCreater interface {
	New(kind unversioned.GroupVersionKind) (out Object, err error)
}

ObjectCreater contains methods for instantiating an object by kind and version.

type ObjectTyper added in v0.5.1

type ObjectTyper interface {
	// ObjectKind returns the default group,version,kind of the provided object, or an
	// error if the object is not recognized (IsNotRegisteredError will return true).
	ObjectKind(Object) (unversioned.GroupVersionKind, error)
	// ObjectKinds returns the all possible group,version,kind of the provided object, or an
	// error if the object is not recognized (IsNotRegisteredError will return true).
	ObjectKinds(Object) ([]unversioned.GroupVersionKind, 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 unversioned.GroupVersionKind) bool
	// IsUnversioned returns true if the provided object is considered unversioned and thus
	// should have Version and Group suppressed in the output. If the object is not recognized
	// in the scheme, ok is false.
	IsUnversioned(Object) (unversioned bool, ok bool)
}

ObjectTyper contains methods for extracting the APIVersion and Kind of objects.

type ObjectVersioner added in v1.2.0

type ObjectVersioner interface {
	ConvertToVersion(in Object, outVersion string) (out Object, err error)
}

type Pair added in v1.1.0

type Pair struct {
	Name, Doc string
}

Pair of strings. We keed the name of fields and the doc

type ParameterCodec added in v1.2.0

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 unversioned.GroupVersion, into Object) error
	// EncodeParameters encodes the provided object as query parameters or returns an error.
	EncodeParameters(obj Object, to unversioned.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 added in v1.2.0

func NewParameterCodec(scheme *Scheme) ParameterCodec

NewParameterCodec creates a ParameterCodec capable of transforming url values into versioned objects and back.

type RawExtension

type RawExtension struct {
	// RawJSON is the underlying serialization of this object.
	RawJSON []byte
	// 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.)

+protobuf=true

func (RawExtension) MarshalJSON

func (re RawExtension) MarshalJSON() ([]byte, error)

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 (*RawExtension) UnmarshalJSON

func (re *RawExtension) UnmarshalJSON(in []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) AddConversionFuncs

func (s *Scheme) AddConversionFuncs(conversionFuncs ...interface{}) error

AddConversionFuncs adds functions to the list of conversion functions. The given functions should know how to convert between two of your API objects, or their sub-objects. We deduce how to call these functions from the types of their two parameters; see the comment for Converter.Register.

Note that, if you need to copy sub-objects that didn't change, you can use the conversion.Scope object that will be passed to your conversion function. Additionally, all conversions started by Scheme will set the SrcVersion and DestVersion fields on the Meta object. Example:

s.AddConversionFuncs(

func(in *InternalObject, out *ExternalObject, scope conversion.Scope) error {
	// You can depend on Meta() being non-nil, and this being set to
	// the source version, e.g., ""
	s.Meta().SrcVersion
	// You can depend on this being set to the destination version,
	// e.g., "v1".
	s.Meta().DestVersion
	// Call scope.Convert to copy sub-fields.
	s.Convert(&in.SubFieldThatMoved, &out.NewLocation.NewName, 0)
	return nil
},

)

(For more detail about conversion functions, see Converter.Register's comment.)

Also note that the default behavior, if you don't add a conversion function, is to sanely copy fields that have the same names and same type names. It's OK if the destination type has extra fields, but it must not remove any. So you only need to add conversion functions for things with changed/removed fields.

func (*Scheme) AddDeepCopyFuncs added in v0.18.0

func (s *Scheme) AddDeepCopyFuncs(deepCopyFuncs ...interface{}) error

AddDeepCopyFuncs adds a function to the list of deep-copy functions. For the expected format of deep-copy function, see the comment for Copier.RegisterDeepCopyFunction.

func (*Scheme) AddDefaultingFuncs added in v0.11.0

func (s *Scheme) AddDefaultingFuncs(defaultingFuncs ...interface{}) error

AddDefaultingFuncs adds functions to the list of default-value functions. Each of the given functions is responsible for applying default values when converting an instance of a versioned API object into an internal API object. These functions do not need to handle sub-objects. We deduce how to call these functions from the types of their two parameters.

s.AddDefaultingFuncs(

func(obj *v1.Pod) {
	if obj.OptionalField == "" {
		obj.OptionalField = "DefaultValue"
	}
},

)

func (*Scheme) AddFieldLabelConversionFunc added in v0.12.0

func (s *Scheme) AddFieldLabelConversionFunc(version, kind string, 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) AddGeneratedConversionFuncs added in v0.16.0

func (s *Scheme) AddGeneratedConversionFuncs(conversionFuncs ...interface{}) error

Similar to AddConversionFuncs, but registers conversion functions that were automatically generated.

func (*Scheme) AddGeneratedDeepCopyFuncs added in v0.18.0

func (s *Scheme) AddGeneratedDeepCopyFuncs(deepCopyFuncs ...interface{}) error

Similar to AddDeepCopyFuncs, but registers deep-copy functions that were automatically generated.

func (*Scheme) AddIgnoredConversionType added in v1.2.0

func (s *Scheme) AddIgnoredConversionType(from, to interface{}) error

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 unversioned.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 unversioned.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) AddStructFieldConversion added in v0.6.0

func (s *Scheme) AddStructFieldConversion(srcFieldType interface{}, srcFieldName string, destFieldType interface{}, destFieldName string) error

AddStructFieldConversion allows you to specify a mechanical copy for a moved or renamed struct field without writing an entire conversion function. See the comment in conversion.Converter.SetStructFieldCopy for parameter details. Call as many times as needed, even on the same fields.

func (*Scheme) AddUnversionedTypes added in v1.2.0

func (s *Scheme) AddUnversionedTypes(version unversioned.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 tihs method at that point.

func (*Scheme) Convert

func (s *Scheme) Convert(in, out interface{}) error

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), but in that case, the conversion.Scope object passed to your conversion functions won't have SrcVersion or DestVersion fields set correctly in Meta().

func (*Scheme) ConvertFieldLabel added in v0.12.0

func (s *Scheme) ConvertFieldLabel(version, kind, label, value string) (string, string, error)

Converts the given field label and value for an kind field selector from versioned representation to an unversioned one.

func (*Scheme) ConvertToVersion added in v0.5.1

func (s *Scheme) ConvertToVersion(in Object, outVersion string) (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. The serializer handles loading/serializing nested objects.

func (*Scheme) Converter added in v1.2.0

func (s *Scheme) Converter() *conversion.Converter

Converter allows access to the converter for the scheme

func (*Scheme) Copy

func (s *Scheme) Copy(src Object) (Object, error)

Copy does a deep copy of an API object.

func (*Scheme) DeepCopy added in v0.18.0

func (s *Scheme) DeepCopy(src interface{}) (interface{}, error)

Performs a deep copy of the given object.

func (*Scheme) IsUnversioned added in v1.2.0

func (s *Scheme) IsUnversioned(obj Object) (bool, bool)

func (*Scheme) KnownTypes

func (s *Scheme) KnownTypes(gv unversioned.GroupVersion) map[string]reflect.Type

KnownTypes returns the types known for the given version.

func (*Scheme) Log

func (s *Scheme) Log(l conversion.DebugLogger)

Log sets a logger on the scheme. For test purposes only

func (*Scheme) New

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) ObjectKind added in v1.2.0

func (s *Scheme) ObjectKind(obj Object) (unversioned.GroupVersionKind, error)

ObjectKind returns the group,version,kind of the go object, or an error if it's not a pointer or is unregistered.

func (*Scheme) ObjectKinds added in v1.2.0

func (s *Scheme) ObjectKinds(obj Object) ([]unversioned.GroupVersionKind, error)

ObjectKinds returns all possible group,version,kind of the go object, or an error if it's not a pointer or is unregistered.

func (*Scheme) Recognizes added in v0.17.0

func (s *Scheme) Recognizes(gvk unversioned.GroupVersionKind) bool

Recognizes returns true if the scheme is able to handle the provided group,version,kind of an object.

func (*Scheme) RegisterInputDefaults added in v1.2.0

func (s *Scheme) RegisterInputDefaults(in interface{}, fn conversion.FieldMappingFunc, defaultFlags conversion.FieldMatchingFlags) error

RegisterInputDefaults sets the provided field mapping function and field matching as the defaults for the provided input type. The fn may be nil, in which case no mapping will happen by default. Use this method to register a mechanism for handling a specific input type in conversion, such as a map[string]string to structs.

type SelfLinker

type SelfLinker interface {
	SetSelfLink(obj Object, selfLink string) error
	SelfLink(obj Object) (string, error)

	// Knowing Name is sometimes necessary to use a SelfLinker.
	Name(obj Object) (string, error)
	// Knowing Namespace is sometimes necessary to use a SelfLinker
	Namespace(obj Object) (string, error)
}

SelfLinker provides methods for setting and retrieving the SelfLink field of an API object.

type Serializer added in v1.2.0

type Serializer interface {
	Encoder
	Decoder
}

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.

type TypeMeta

type TypeMeta struct {
	APIVersion string `json:"apiVersion,omitempty" yaml:"apiVersion,omitempty"`
	Kind       string `json:"kind,omitempty" yaml:"kind,omitempty"`
}

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 *unversioned.GroupVersionKind) { unversioned.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.

+protobuf=true

func (*TypeMeta) GroupVersionKind added in v1.2.0

func (obj *TypeMeta) GroupVersionKind() *unversioned.GroupVersionKind

GroupVersionKind satisfies the ObjectKind interface for all objects that embed TypeMeta

func (*TypeMeta) SetGroupVersionKind added in v1.2.0

func (obj *TypeMeta) SetGroupVersionKind(gvk *unversioned.GroupVersionKind)

SetGroupVersionKind satisfies the ObjectKind interface for all objects that embed TypeMeta

type Typer added in v1.2.0

type Typer interface {
	// ObjectKind returns the version and kind of the provided object, or an
	// error if the object is not recognized (IsNotRegisteredError will return true).
	// It returns whether the object is considered unversioned at the same time.
	// TODO: align the signature of ObjectTyper with this interface
	ObjectKind(Object) (*unversioned.GroupVersionKind, bool, error)
}

Typer retrieves information about an object's group, version, and kind.

func ObjectTyperToTyper added in v1.2.0

func ObjectTyperToTyper(typer ObjectTyper) Typer

type Unknown

type Unknown struct {
	TypeMeta `json:",inline"`
	// RawJSON will hold the complete JSON of the 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.
	RawJSON []byte
}

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.

+protobuf=true

func (*Unknown) GetObjectKind added in v1.2.0

func (obj *Unknown) GetObjectKind() unversioned.ObjectKind

func (Unknown) MarshalJSON added in v1.2.0

func (re Unknown) MarshalJSON() ([]byte, error)

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) UnmarshalJSON added in v1.2.0

func (re *Unknown) UnmarshalJSON(in []byte) error

type Unstructured added in v0.17.0

type Unstructured struct {
	TypeMeta `json:",inline"`
	// Object is a JSON compatible map with string, float, int, []interface{}, or map[string]interface{}
	// children.
	Object map[string]interface{}
}

Unstructured allows objects that do not have Golang structs registered to be manipulated generically. This can be used to deal with the API objects from a plug-in. Unstructured 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.

func (*Unstructured) GetObjectKind added in v1.2.0

func (obj *Unstructured) GetObjectKind() unversioned.ObjectKind

type VersionedObjects added in v1.2.0

type VersionedObjects struct {
	// Objects is the set of objects retrieved during decoding, in order of conversion.
	// The 0 index is the object as serialized on the wire. If conversion has occured,
	// other objects may be present. The right most object is the same as would be returned
	// by a normal Decode call.
	Objects []Object
}

VersionedObjects is used by Decoders to give callers a way to access all versions of an object during the decoding process.

func (*VersionedObjects) First added in v1.2.0

func (obj *VersionedObjects) First() Object

First returns the leftmost object in the VersionedObjects array, which is usually the object as serialized on the wire.

func (*VersionedObjects) GetObjectKind added in v1.2.0

func (obj *VersionedObjects) GetObjectKind() unversioned.ObjectKind

GetObjectKind implements Object for VersionedObjects, returning an empty ObjectKind interface if no objects are provided, or the ObjectKind interface of the object in the highest array position.

func (*VersionedObjects) Last added in v1.2.0

func (obj *VersionedObjects) Last() Object

Last is the rightmost object in the VersionedObjects array, which is the object after all transformations have been applied. This is the same object that would be returned by Decode in a normal invocation (without VersionedObjects in the into argument).

Directories

Path Synopsis
Package protobuf implements ProtoBuf serialization and deserialization.
Package protobuf implements ProtoBuf serialization and deserialization.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL