meta

package
v0.20.0-alpha11 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2016 License: Apache-2.0, Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package meta provides functions for retrieving API metadata from objects belonging to the Kubernetes API

TODO: move everything in this file to pkg/api/rest

Index

Constants

This section is empty.

Variables

View Source
var RESTScopeNamespace = &restScope{
	name:             RESTScopeNameNamespace,
	paramName:        "namespaces",
	argumentName:     "namespace",
	paramDescription: "object name and auth scope, such as for teams and projects",
}
View Source
var RESTScopeRoot = &restScope{
	name: RESTScopeNameRoot,
}

Functions

func ExtractList added in v1.0.0

func ExtractList(obj runtime.Object) ([]runtime.Object, error)

ExtractList returns obj's Items element as an array of runtime.Objects. Returns an error if obj is not a List type (does not have an Items member).

func GetItemsPtr added in v1.0.0

func GetItemsPtr(list runtime.Object) (interface{}, error)

GetItemsPtr returns a pointer to the list object's Items member. If 'list' doesn't have an Items member, it's not really a list type and an error will be returned. This function will either return a pointer to a slice, or an error, but not both.

func IsAmbiguousResourceError added in v1.0.0

func IsAmbiguousResourceError(err error) bool

func IsListType added in v1.0.0

func IsListType(obj runtime.Object) bool

IsListType returns true if the provided Object has a slice called Items

func IsNoResourceMatchError added in v1.0.0

func IsNoResourceMatchError(err error) bool

func KindToResource added in v0.18.4

KindToResource converts Kind to a resource name.

func SetList added in v1.0.0

func SetList(list runtime.Object, objects []runtime.Object) error

SetList sets the given list object's Items member have the elements given in objects. Returns an error if list is not a List type (does not have an Items member), or if any of the objects are not of the right type.

Types

type AmbiguousResourceError added in v1.0.0

type AmbiguousResourceError struct {
	PartialResource unversioned.GroupVersionResource

	MatchingResources []unversioned.GroupVersionResource
	MatchingKinds     []unversioned.GroupVersionKind
}

AmbiguousResourceError is returned if the RESTMapper finds multiple matches for a resource

func (*AmbiguousResourceError) Error added in v1.0.0

func (e *AmbiguousResourceError) Error() string

type DefaultRESTMapper

type DefaultRESTMapper struct {
	// contains filtered or unexported fields
}

DefaultRESTMapper exposes mappings between the types defined in a runtime.Scheme. It assumes that all types defined the provided scheme can be mapped with the provided MetadataAccessor and Codec interfaces.

The resource name of a Kind is defined as the lowercase, English-plural version of the Kind string. When converting from resource to Kind, the singular version of the resource name is also accepted for convenience.

TODO: Only accept plural for some operations for increased control? (`get pod bar` vs `get pods bar`) TODO these maps should be keyed based on GroupVersionKinds

func NewDefaultRESTMapper

func NewDefaultRESTMapper(defaultGroupVersions []unversioned.GroupVersion, f VersionInterfacesFunc) *DefaultRESTMapper

NewDefaultRESTMapper initializes a mapping between Kind and APIVersion to a resource name and back based on the objects in a runtime.Scheme and the Kubernetes API conventions. Takes a group name, a priority list of the versions to search when an object has no default version (set empty to return an error), and a function that retrieves the correct metadata for a given version.

func (*DefaultRESTMapper) Add

func (*DefaultRESTMapper) AddResourceAlias

func (m *DefaultRESTMapper) AddResourceAlias(alias string, resources ...string)

AddResourceAlias maps aliases to resources

func (*DefaultRESTMapper) AliasesForResource

func (m *DefaultRESTMapper) AliasesForResource(alias string) ([]string, bool)

AliasesForResource returns whether a resource has an alias or not

func (*DefaultRESTMapper) KindFor added in v1.0.0

func (*DefaultRESTMapper) KindsFor added in v1.0.0

func (*DefaultRESTMapper) RESTMapping

func (m *DefaultRESTMapper) RESTMapping(gk unversioned.GroupKind, versions ...string) (*RESTMapping, error)

RESTMapping returns a struct representing the resource path and conversion interfaces a RESTClient should use to operate on the provided group/kind in order of versions. If a version search order is not provided, the search order provided to DefaultRESTMapper will be used to resolve which version should be used to access the named group/kind.

func (*DefaultRESTMapper) ResourceFor added in v1.0.0

func (*DefaultRESTMapper) ResourceSingularizer added in v0.18.4

func (m *DefaultRESTMapper) ResourceSingularizer(resourceType string) (string, error)

ResourceSingularizer implements RESTMapper It converts a resource name from plural to singular (e.g., from pods to pod)

func (*DefaultRESTMapper) ResourcesFor added in v1.0.0

func (*DefaultRESTMapper) String added in v1.0.0

func (m *DefaultRESTMapper) String() string

type List added in v1.0.0

type List interface {
	GetResourceVersion() string
	SetResourceVersion(version string)
	GetSelfLink() string
	SetSelfLink(selfLink string)
}

List lets you work with list metadata from any of the versioned or internal API objects. Attempting to set or retrieve a field on an object that does not support that field will be a no-op and return a default value.

type MetadataAccessor

type MetadataAccessor interface {
	APIVersion(obj runtime.Object) (string, error)
	SetAPIVersion(obj runtime.Object, version string) error

	Kind(obj runtime.Object) (string, error)
	SetKind(obj runtime.Object, kind string) error

	Namespace(obj runtime.Object) (string, error)
	SetNamespace(obj runtime.Object, namespace string) error

	Name(obj runtime.Object) (string, error)
	SetName(obj runtime.Object, name string) error

	GenerateName(obj runtime.Object) (string, error)
	SetGenerateName(obj runtime.Object, name string) error

	UID(obj runtime.Object) (types.UID, error)
	SetUID(obj runtime.Object, uid types.UID) error

	SelfLink(obj runtime.Object) (string, error)
	SetSelfLink(obj runtime.Object, selfLink string) error

	Labels(obj runtime.Object) (map[string]string, error)
	SetLabels(obj runtime.Object, labels map[string]string) error

	Annotations(obj runtime.Object) (map[string]string, error)
	SetAnnotations(obj runtime.Object, annotations map[string]string) error

	runtime.ResourceVersioner
}

MetadataAccessor lets you work with object and list metadata from any of the versioned or internal API objects. Attempting to set or retrieve a field on an object that does not support that field (Name, UID, Namespace on lists) will be a no-op and return a default value.

MetadataAccessor exposes Interface in a way that can be used with multiple objects.

func NewAccessor

func NewAccessor() MetadataAccessor

NewAccessor returns a MetadataAccessor that can retrieve or manipulate resource version on objects derived from core API metadata concepts.

type MultiRESTMapper

type MultiRESTMapper []RESTMapper

MultiRESTMapper is a wrapper for multiple RESTMappers.

func (MultiRESTMapper) AliasesForResource

func (m MultiRESTMapper) AliasesForResource(alias string) (aliases []string, ok bool)

AliasesForResource finds the first alias response for the provided mappers.

func (MultiRESTMapper) KindFor added in v1.0.0

KindsFor provides the Kind mapping for the REST resources. This implementation supports multiple REST schemas and returns the first match.

func (MultiRESTMapper) KindsFor added in v1.0.0

KindsFor provides the Kind mappings for the REST resources. This implementation supports multiple REST schemas and returns the first match.

func (MultiRESTMapper) RESTMapping

func (m MultiRESTMapper) RESTMapping(gk unversioned.GroupKind, versions ...string) (mapping *RESTMapping, err error)

RESTMapping provides the REST mapping for the resource based on the kind and version. This implementation supports multiple REST schemas and return the first match.

func (MultiRESTMapper) ResourceFor added in v1.0.0

func (MultiRESTMapper) ResourceSingularizer added in v0.18.4

func (m MultiRESTMapper) ResourceSingularizer(resource string) (singular string, err error)

ResourceSingularizer converts a REST resource name from plural to singular (e.g., from pods to pod) This implementation supports multiple REST schemas and return the first match.

func (MultiRESTMapper) ResourcesFor added in v1.0.0

func (MultiRESTMapper) String added in v1.0.0

func (m MultiRESTMapper) String() string

type NoResourceMatchError added in v1.0.0

type NoResourceMatchError struct {
	PartialResource unversioned.GroupVersionResource
}

NoResourceMatchError is returned if the RESTMapper can't find any match for a resource

func (*NoResourceMatchError) Error added in v1.0.0

func (e *NoResourceMatchError) Error() string

type Object added in v1.0.0

type Object interface {
	GetNamespace() string
	SetNamespace(namespace string)
	GetName() string
	SetName(name string)
	GetGenerateName() string
	SetGenerateName(name string)
	GetUID() types.UID
	SetUID(uid types.UID)
	GetResourceVersion() string
	SetResourceVersion(version string)
	GetSelfLink() string
	SetSelfLink(selfLink string)
	GetLabels() map[string]string
	SetLabels(labels map[string]string)
	GetAnnotations() map[string]string
	SetAnnotations(annotations map[string]string)
}

Object lets you work with object metadata from any of the versioned or internal API objects. Attempting to set or retrieve a field on an object that does not support that field (Name, UID, Namespace on lists) will be a no-op and return a default value.

func Accessor

func Accessor(obj interface{}) (Object, error)

Accessor takes an arbitrary object pointer and returns meta.Interface. obj must be a pointer to an API type. An error is returned if the minimum required fields are missing. Fields that are not required return the default value and are a no-op if set.

type ObjectMetaAccessor added in v1.0.0

type ObjectMetaAccessor interface {
	GetObjectMeta() Object
}

type RESTMapper

type RESTMapper interface {
	// KindFor takes a partial resource and returns back the single match.  Returns an error if there are multiple matches
	KindFor(resource unversioned.GroupVersionResource) (unversioned.GroupVersionKind, error)

	// KindsFor takes a partial resource and returns back the list of potential kinds in priority order
	KindsFor(resource unversioned.GroupVersionResource) ([]unversioned.GroupVersionKind, error)

	// ResourceFor takes a partial resource and returns back the single match.  Returns an error if there are multiple matches
	ResourceFor(input unversioned.GroupVersionResource) (unversioned.GroupVersionResource, error)

	// ResourcesFor takes a partial resource and returns back the list of potential resource in priority order
	ResourcesFor(input unversioned.GroupVersionResource) ([]unversioned.GroupVersionResource, error)

	RESTMapping(gk unversioned.GroupKind, versions ...string) (*RESTMapping, error)

	AliasesForResource(resource string) ([]string, bool)
	ResourceSingularizer(resource string) (singular string, err error)
}

RESTMapper allows clients to map resources to kind, and map kind and version to interfaces for manipulating those objects. It is primarily intended for consumers of Kubernetes compatible REST APIs as defined in docs/devel/api-conventions.md.

The Kubernetes API provides versioned resources and object kinds which are scoped to API groups. In other words, kinds and resources should not be assumed to be unique across groups.

TODO(caesarxuchao): Add proper multi-group support so that kinds & resources are scoped to groups. See http://issues.k8s.io/12413 and http://issues.k8s.io/10009.

type RESTMapping

type RESTMapping struct {
	// Resource is a string representing the name of this resource as a REST client would see it
	Resource string

	GroupVersionKind unversioned.GroupVersionKind

	// Scope contains the information needed to deal with REST Resources that are in a resource hierarchy
	Scope RESTScope

	runtime.ObjectConvertor
	MetadataAccessor
}

RESTMapping contains the information needed to deal with objects of a specific resource and kind in a RESTful manner.

type RESTScope

type RESTScope interface {
	// Name of the scope
	Name() RESTScopeName
	// ParamName is the optional name of the parameter that should be inserted in the resource url
	// If empty, no param will be inserted
	ParamName() string
	// ArgumentName is the optional name that should be used for the variable holding the value.
	ArgumentName() string
	// ParamDescription is the optional description to use to document the parameter in api documentation
	ParamDescription() string
}

RESTScope contains the information needed to deal with REST resources that are in a resource hierarchy

type RESTScopeName

type RESTScopeName string
const (
	RESTScopeNameNamespace RESTScopeName = "namespace"
	RESTScopeNameRoot      RESTScopeName = "root"
)

type Type added in v1.0.0

type Type interface {
	GetAPIVersion() string
	SetAPIVersion(version string)
	GetKind() string
	SetKind(kind string)
}

Type exposes the type and APIVersion of versioned or internal API objects.

func TypeAccessor

func TypeAccessor(obj interface{}) (Type, error)

TypeAccessor returns an interface that allows retrieving and modifying the APIVersion and Kind of an in-memory internal object. TODO: this interface is used to test code that does not have ObjectMeta or ListMeta in round tripping (objects which can use apiVersion/kind, but do not fit the Kube api conventions).

type VersionInterfaces

type VersionInterfaces struct {
	runtime.ObjectConvertor
	MetadataAccessor
}

VersionInterfaces contains the interfaces one should use for dealing with types of a particular version.

type VersionInterfacesFunc

type VersionInterfacesFunc func(version unversioned.GroupVersion) (*VersionInterfaces, error)

VersionInterfacesFunc returns the appropriate typer, and metadata accessor for a given api version, or an error if no such api version exists.

Jump to

Keyboard shortcuts

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