interfaces.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  16. "k8s.io/apimachinery/pkg/runtime"
  17. "k8s.io/apimachinery/pkg/runtime/schema"
  18. "k8s.io/apimachinery/pkg/types"
  19. )
  20. type ListMetaAccessor interface {
  21. GetListMeta() List
  22. }
  23. // List lets you work with list metadata from any of the versioned or
  24. // internal API objects. Attempting to set or retrieve a field on an object that does
  25. // not support that field will be a no-op and return a default value.
  26. type List metav1.ListInterface
  27. // Type exposes the type and APIVersion of versioned or internal API objects.
  28. type Type metav1.Type
  29. // MetadataAccessor lets you work with object and list metadata from any of the versioned or
  30. // internal API objects. Attempting to set or retrieve a field on an object that does
  31. // not support that field (Name, UID, Namespace on lists) will be a no-op and return
  32. // a default value.
  33. //
  34. // MetadataAccessor exposes Interface in a way that can be used with multiple objects.
  35. type MetadataAccessor interface {
  36. APIVersion(obj runtime.Object) (string, error)
  37. SetAPIVersion(obj runtime.Object, version string) error
  38. Kind(obj runtime.Object) (string, error)
  39. SetKind(obj runtime.Object, kind string) error
  40. Namespace(obj runtime.Object) (string, error)
  41. SetNamespace(obj runtime.Object, namespace string) error
  42. Name(obj runtime.Object) (string, error)
  43. SetName(obj runtime.Object, name string) error
  44. GenerateName(obj runtime.Object) (string, error)
  45. SetGenerateName(obj runtime.Object, name string) error
  46. UID(obj runtime.Object) (types.UID, error)
  47. SetUID(obj runtime.Object, uid types.UID) error
  48. SelfLink(obj runtime.Object) (string, error)
  49. SetSelfLink(obj runtime.Object, selfLink string) error
  50. Labels(obj runtime.Object) (map[string]string, error)
  51. SetLabels(obj runtime.Object, labels map[string]string) error
  52. Annotations(obj runtime.Object) (map[string]string, error)
  53. SetAnnotations(obj runtime.Object, annotations map[string]string) error
  54. Continue(obj runtime.Object) (string, error)
  55. SetContinue(obj runtime.Object, c string) error
  56. runtime.ResourceVersioner
  57. }
  58. type RESTScopeName string
  59. const (
  60. RESTScopeNameNamespace RESTScopeName = "namespace"
  61. RESTScopeNameRoot RESTScopeName = "root"
  62. )
  63. // RESTScope contains the information needed to deal with REST resources that are in a resource hierarchy
  64. type RESTScope interface {
  65. // Name of the scope
  66. Name() RESTScopeName
  67. }
  68. // RESTMapping contains the information needed to deal with objects of a specific
  69. // resource and kind in a RESTful manner.
  70. type RESTMapping struct {
  71. // Resource is the GroupVersionResource (location) for this endpoint
  72. Resource schema.GroupVersionResource
  73. // GroupVersionKind is the GroupVersionKind (data format) to submit to this endpoint
  74. GroupVersionKind schema.GroupVersionKind
  75. // Scope contains the information needed to deal with REST Resources that are in a resource hierarchy
  76. Scope RESTScope
  77. }
  78. // RESTMapper allows clients to map resources to kind, and map kind and version
  79. // to interfaces for manipulating those objects. It is primarily intended for
  80. // consumers of Kubernetes compatible REST APIs as defined in docs/devel/api-conventions.md.
  81. //
  82. // The Kubernetes API provides versioned resources and object kinds which are scoped
  83. // to API groups. In other words, kinds and resources should not be assumed to be
  84. // unique across groups.
  85. //
  86. // TODO: split into sub-interfaces
  87. type RESTMapper interface {
  88. // KindFor takes a partial resource and returns the single match. Returns an error if there are multiple matches
  89. KindFor(resource schema.GroupVersionResource) (schema.GroupVersionKind, error)
  90. // KindsFor takes a partial resource and returns the list of potential kinds in priority order
  91. KindsFor(resource schema.GroupVersionResource) ([]schema.GroupVersionKind, error)
  92. // ResourceFor takes a partial resource and returns the single match. Returns an error if there are multiple matches
  93. ResourceFor(input schema.GroupVersionResource) (schema.GroupVersionResource, error)
  94. // ResourcesFor takes a partial resource and returns the list of potential resource in priority order
  95. ResourcesFor(input schema.GroupVersionResource) ([]schema.GroupVersionResource, error)
  96. // RESTMapping identifies a preferred resource mapping for the provided group kind.
  97. RESTMapping(gk schema.GroupKind, versions ...string) (*RESTMapping, error)
  98. // RESTMappings returns all resource mappings for the provided group kind if no
  99. // version search is provided. Otherwise identifies a preferred resource mapping for
  100. // the provided version(s).
  101. RESTMappings(gk schema.GroupKind, versions ...string) ([]*RESTMapping, error)
  102. ResourceSingularizer(resource string) (singular string, err error)
  103. }