interfaces.go 6.9 KB

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