github.com/timstclair/heapster@v0.20.0-alpha1/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.Codec
    28  	runtime.ObjectConvertor
    29  	MetadataAccessor
    30  }
    31  
    32  // Interface lets you work with object and list metadata from any of the versioned or
    33  // internal API objects. Attempting to set or retrieve a field on an object that does
    34  // not support that field (Name, UID, Namespace on lists) will be a no-op and return
    35  // a default value.
    36  // TODO: rename to ObjectInterface when we clear up these interfaces.
    37  type Interface interface {
    38  	TypeInterface
    39  
    40  	Namespace() string
    41  	SetNamespace(namespace string)
    42  	Name() string
    43  	SetName(name string)
    44  	GenerateName() string
    45  	SetGenerateName(name string)
    46  	UID() types.UID
    47  	SetUID(uid types.UID)
    48  	ResourceVersion() string
    49  	SetResourceVersion(version string)
    50  	SelfLink() string
    51  	SetSelfLink(selfLink string)
    52  	Labels() map[string]string
    53  	SetLabels(labels map[string]string)
    54  	Annotations() map[string]string
    55  	SetAnnotations(annotations map[string]string)
    56  }
    57  
    58  // TypeInterface exposes the type and APIVersion of versioned or internal API objects.
    59  type TypeInterface interface {
    60  	APIVersion() string
    61  	SetAPIVersion(version string)
    62  	Kind() string
    63  	SetKind(kind string)
    64  }
    65  
    66  // MetadataAccessor lets you work with object and list metadata from any of the versioned or
    67  // internal API objects. Attempting to set or retrieve a field on an object that does
    68  // not support that field (Name, UID, Namespace on lists) will be a no-op and return
    69  // a default value.
    70  //
    71  // MetadataAccessor exposes Interface in a way that can be used with multiple objects.
    72  type MetadataAccessor interface {
    73  	APIVersion(obj runtime.Object) (string, error)
    74  	SetAPIVersion(obj runtime.Object, version string) error
    75  
    76  	Kind(obj runtime.Object) (string, error)
    77  	SetKind(obj runtime.Object, kind string) error
    78  
    79  	Namespace(obj runtime.Object) (string, error)
    80  	SetNamespace(obj runtime.Object, namespace string) error
    81  
    82  	Name(obj runtime.Object) (string, error)
    83  	SetName(obj runtime.Object, name string) error
    84  
    85  	GenerateName(obj runtime.Object) (string, error)
    86  	SetGenerateName(obj runtime.Object, name string) error
    87  
    88  	UID(obj runtime.Object) (types.UID, error)
    89  	SetUID(obj runtime.Object, uid types.UID) error
    90  
    91  	SelfLink(obj runtime.Object) (string, error)
    92  	SetSelfLink(obj runtime.Object, selfLink string) error
    93  
    94  	Labels(obj runtime.Object) (map[string]string, error)
    95  	SetLabels(obj runtime.Object, labels map[string]string) error
    96  
    97  	Annotations(obj runtime.Object) (map[string]string, error)
    98  	SetAnnotations(obj runtime.Object, annotations map[string]string) error
    99  
   100  	runtime.ResourceVersioner
   101  }
   102  
   103  type RESTScopeName string
   104  
   105  const (
   106  	RESTScopeNameNamespace RESTScopeName = "namespace"
   107  	RESTScopeNameRoot      RESTScopeName = "root"
   108  )
   109  
   110  // RESTScope contains the information needed to deal with REST resources that are in a resource hierarchy
   111  type RESTScope interface {
   112  	// Name of the scope
   113  	Name() RESTScopeName
   114  	// ParamName is the optional name of the parameter that should be inserted in the resource url
   115  	// If empty, no param will be inserted
   116  	ParamName() string
   117  	// ArgumentName is the optional name that should be used for the variable holding the value.
   118  	ArgumentName() string
   119  	// ParamDescription is the optional description to use to document the parameter in api documentation
   120  	ParamDescription() string
   121  }
   122  
   123  // RESTMapping contains the information needed to deal with objects of a specific
   124  // resource and kind in a RESTful manner.
   125  type RESTMapping struct {
   126  	// Resource is a string representing the name of this resource as a REST client would see it
   127  	Resource string
   128  
   129  	GroupVersionKind unversioned.GroupVersionKind
   130  
   131  	// Scope contains the information needed to deal with REST Resources that are in a resource hierarchy
   132  	Scope RESTScope
   133  
   134  	runtime.Codec
   135  	runtime.ObjectConvertor
   136  	MetadataAccessor
   137  }
   138  
   139  // RESTMapper allows clients to map resources to kind, and map kind and version
   140  // to interfaces for manipulating those objects. It is primarily intended for
   141  // consumers of Kubernetes compatible REST APIs as defined in docs/devel/api-conventions.md.
   142  //
   143  // The Kubernetes API provides versioned resources and object kinds which are scoped
   144  // to API groups. In other words, kinds and resources should not be assumed to be
   145  // unique across groups.
   146  //
   147  // TODO(caesarxuchao): Add proper multi-group support so that kinds & resources are
   148  // scoped to groups. See http://issues.k8s.io/12413 and http://issues.k8s.io/10009.
   149  type RESTMapper interface {
   150  	VersionAndKindForResource(resource string) (defaultVersion, kind string, err error)
   151  	// TODO(caesarxuchao): Remove GroupForResource when multi-group support is in (since
   152  	// group will be part of the version).
   153  	GroupForResource(resource string) (string, error)
   154  	RESTMapping(kind string, versions ...string) (*RESTMapping, error)
   155  	AliasesForResource(resource string) ([]string, bool)
   156  	ResourceSingularizer(resource string) (singular string, err error)
   157  	ResourceIsValid(resource string) bool
   158  }