github.com/aclisp/heapster@v0.19.2-0.20160613100040-51756f899a96/Godeps/_workspace/src/k8s.io/kubernetes/pkg/api/meta/interfaces.go (about)

     1  /*
     2  Copyright 2014 The Kubernetes Authors All rights reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package meta
    18  
    19  import (
    20  	"k8s.io/kubernetes/pkg/api/unversioned"
    21  	"k8s.io/kubernetes/pkg/runtime"
    22  	"k8s.io/kubernetes/pkg/types"
    23  )
    24  
    25  // VersionInterfaces contains the interfaces one should use for dealing with types of a particular version.
    26  type VersionInterfaces struct {
    27  	runtime.ObjectConvertor
    28  	MetadataAccessor
    29  }
    30  
    31  type ObjectMetaAccessor interface {
    32  	GetObjectMeta() Object
    33  }
    34  
    35  // Object lets you work with object metadata from any of the versioned or
    36  // internal API objects. Attempting to set or retrieve a field on an object that does
    37  // not support that field (Name, UID, Namespace on lists) will be a no-op and return
    38  // a default value.
    39  type Object interface {
    40  	GetNamespace() string
    41  	SetNamespace(namespace string)
    42  	GetName() string
    43  	SetName(name string)
    44  	GetGenerateName() string
    45  	SetGenerateName(name string)
    46  	GetUID() types.UID
    47  	SetUID(uid types.UID)
    48  	GetResourceVersion() string
    49  	SetResourceVersion(version string)
    50  	GetSelfLink() string
    51  	SetSelfLink(selfLink string)
    52  	GetCreationTimestamp() unversioned.Time
    53  	SetCreationTimestamp(timestamp unversioned.Time)
    54  	GetDeletionTimestamp() *unversioned.Time
    55  	SetDeletionTimestamp(timestamp *unversioned.Time)
    56  	GetLabels() map[string]string
    57  	SetLabels(labels map[string]string)
    58  	GetAnnotations() map[string]string
    59  	SetAnnotations(annotations map[string]string)
    60  }
    61  
    62  // List lets you work with list metadata from any of the versioned or
    63  // internal API objects. Attempting to set or retrieve a field on an object that does
    64  // not support that field will be a no-op and return a default value.
    65  type List interface {
    66  	GetResourceVersion() string
    67  	SetResourceVersion(version string)
    68  	GetSelfLink() string
    69  	SetSelfLink(selfLink string)
    70  }
    71  
    72  // Type exposes the type and APIVersion of versioned or internal API objects.
    73  type Type interface {
    74  	GetAPIVersion() string
    75  	SetAPIVersion(version string)
    76  	GetKind() string
    77  	SetKind(kind string)
    78  }
    79  
    80  // MetadataAccessor lets you work with object and list metadata from any of the versioned or
    81  // internal API objects. Attempting to set or retrieve a field on an object that does
    82  // not support that field (Name, UID, Namespace on lists) will be a no-op and return
    83  // a default value.
    84  //
    85  // MetadataAccessor exposes Interface in a way that can be used with multiple objects.
    86  type MetadataAccessor interface {
    87  	APIVersion(obj runtime.Object) (string, error)
    88  	SetAPIVersion(obj runtime.Object, version string) error
    89  
    90  	Kind(obj runtime.Object) (string, error)
    91  	SetKind(obj runtime.Object, kind string) error
    92  
    93  	Namespace(obj runtime.Object) (string, error)
    94  	SetNamespace(obj runtime.Object, namespace string) error
    95  
    96  	Name(obj runtime.Object) (string, error)
    97  	SetName(obj runtime.Object, name string) error
    98  
    99  	GenerateName(obj runtime.Object) (string, error)
   100  	SetGenerateName(obj runtime.Object, name string) error
   101  
   102  	UID(obj runtime.Object) (types.UID, error)
   103  	SetUID(obj runtime.Object, uid types.UID) error
   104  
   105  	SelfLink(obj runtime.Object) (string, error)
   106  	SetSelfLink(obj runtime.Object, selfLink string) error
   107  
   108  	Labels(obj runtime.Object) (map[string]string, error)
   109  	SetLabels(obj runtime.Object, labels map[string]string) error
   110  
   111  	Annotations(obj runtime.Object) (map[string]string, error)
   112  	SetAnnotations(obj runtime.Object, annotations map[string]string) error
   113  
   114  	runtime.ResourceVersioner
   115  }
   116  
   117  type RESTScopeName string
   118  
   119  const (
   120  	RESTScopeNameNamespace RESTScopeName = "namespace"
   121  	RESTScopeNameRoot      RESTScopeName = "root"
   122  )
   123  
   124  // RESTScope contains the information needed to deal with REST resources that are in a resource hierarchy
   125  type RESTScope interface {
   126  	// Name of the scope
   127  	Name() RESTScopeName
   128  	// ParamName is the optional name of the parameter that should be inserted in the resource url
   129  	// If empty, no param will be inserted
   130  	ParamName() string
   131  	// ArgumentName is the optional name that should be used for the variable holding the value.
   132  	ArgumentName() string
   133  	// ParamDescription is the optional description to use to document the parameter in api documentation
   134  	ParamDescription() string
   135  }
   136  
   137  // RESTMapping contains the information needed to deal with objects of a specific
   138  // resource and kind in a RESTful manner.
   139  type RESTMapping struct {
   140  	// Resource is a string representing the name of this resource as a REST client would see it
   141  	Resource string
   142  
   143  	GroupVersionKind unversioned.GroupVersionKind
   144  
   145  	// Scope contains the information needed to deal with REST Resources that are in a resource hierarchy
   146  	Scope RESTScope
   147  
   148  	runtime.ObjectConvertor
   149  	MetadataAccessor
   150  }
   151  
   152  // RESTMapper allows clients to map resources to kind, and map kind and version
   153  // to interfaces for manipulating those objects. It is primarily intended for
   154  // consumers of Kubernetes compatible REST APIs as defined in docs/devel/api-conventions.md.
   155  //
   156  // The Kubernetes API provides versioned resources and object kinds which are scoped
   157  // to API groups. In other words, kinds and resources should not be assumed to be
   158  // unique across groups.
   159  //
   160  // TODO(caesarxuchao): Add proper multi-group support so that kinds & resources are
   161  // scoped to groups. See http://issues.k8s.io/12413 and http://issues.k8s.io/10009.
   162  type RESTMapper interface {
   163  	// KindFor takes a partial resource and returns back the single match.  Returns an error if there are multiple matches
   164  	KindFor(resource unversioned.GroupVersionResource) (unversioned.GroupVersionKind, error)
   165  
   166  	// KindsFor takes a partial resource and returns back the list of potential kinds in priority order
   167  	KindsFor(resource unversioned.GroupVersionResource) ([]unversioned.GroupVersionKind, error)
   168  
   169  	// ResourceFor takes a partial resource and returns back the single match.  Returns an error if there are multiple matches
   170  	ResourceFor(input unversioned.GroupVersionResource) (unversioned.GroupVersionResource, error)
   171  
   172  	// ResourcesFor takes a partial resource and returns back the list of potential resource in priority order
   173  	ResourcesFor(input unversioned.GroupVersionResource) ([]unversioned.GroupVersionResource, error)
   174  
   175  	RESTMapping(gk unversioned.GroupKind, versions ...string) (*RESTMapping, error)
   176  
   177  	AliasesForResource(resource string) ([]string, bool)
   178  	ResourceSingularizer(resource string) (singular string, err error)
   179  }
   180  
   181  var _ Object = &runtime.Unstructured{}