meta.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. Copyright 2016 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 v1
  14. import (
  15. "k8s.io/apimachinery/pkg/runtime/schema"
  16. "k8s.io/apimachinery/pkg/types"
  17. )
  18. // TODO: move this, Object, List, and Type to a different package
  19. type ObjectMetaAccessor interface {
  20. GetObjectMeta() Object
  21. }
  22. // Object lets you work with object metadata from any of the versioned or
  23. // internal API objects. Attempting to set or retrieve a field on an object that does
  24. // not support that field (Name, UID, Namespace on lists) will be a no-op and return
  25. // a default value.
  26. type Object interface {
  27. GetNamespace() string
  28. SetNamespace(namespace string)
  29. GetName() string
  30. SetName(name string)
  31. GetGenerateName() string
  32. SetGenerateName(name string)
  33. GetUID() types.UID
  34. SetUID(uid types.UID)
  35. GetResourceVersion() string
  36. SetResourceVersion(version string)
  37. GetGeneration() int64
  38. SetGeneration(generation int64)
  39. GetSelfLink() string
  40. SetSelfLink(selfLink string)
  41. GetCreationTimestamp() Time
  42. SetCreationTimestamp(timestamp Time)
  43. GetDeletionTimestamp() *Time
  44. SetDeletionTimestamp(timestamp *Time)
  45. GetDeletionGracePeriodSeconds() *int64
  46. SetDeletionGracePeriodSeconds(*int64)
  47. GetLabels() map[string]string
  48. SetLabels(labels map[string]string)
  49. GetAnnotations() map[string]string
  50. SetAnnotations(annotations map[string]string)
  51. GetInitializers() *Initializers
  52. SetInitializers(initializers *Initializers)
  53. GetFinalizers() []string
  54. SetFinalizers(finalizers []string)
  55. GetOwnerReferences() []OwnerReference
  56. SetOwnerReferences([]OwnerReference)
  57. GetClusterName() string
  58. SetClusterName(clusterName string)
  59. }
  60. // ListMetaAccessor retrieves the list interface from an object
  61. type ListMetaAccessor interface {
  62. GetListMeta() ListInterface
  63. }
  64. // Common lets you work with core 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. // TODO: move this, and TypeMeta and ListMeta, to a different package
  68. type Common interface {
  69. GetResourceVersion() string
  70. SetResourceVersion(version string)
  71. GetSelfLink() string
  72. SetSelfLink(selfLink string)
  73. }
  74. // ListInterface lets you work with list metadata from any of the versioned or
  75. // internal API objects. Attempting to set or retrieve a field on an object that does
  76. // not support that field will be a no-op and return a default value.
  77. // TODO: move this, and TypeMeta and ListMeta, to a different package
  78. type ListInterface interface {
  79. GetResourceVersion() string
  80. SetResourceVersion(version string)
  81. GetSelfLink() string
  82. SetSelfLink(selfLink string)
  83. GetContinue() string
  84. SetContinue(c string)
  85. }
  86. // Type exposes the type and APIVersion of versioned or internal API objects.
  87. // TODO: move this, and TypeMeta and ListMeta, to a different package
  88. type Type interface {
  89. GetAPIVersion() string
  90. SetAPIVersion(version string)
  91. GetKind() string
  92. SetKind(kind string)
  93. }
  94. func (meta *ListMeta) GetResourceVersion() string { return meta.ResourceVersion }
  95. func (meta *ListMeta) SetResourceVersion(version string) { meta.ResourceVersion = version }
  96. func (meta *ListMeta) GetSelfLink() string { return meta.SelfLink }
  97. func (meta *ListMeta) SetSelfLink(selfLink string) { meta.SelfLink = selfLink }
  98. func (meta *ListMeta) GetContinue() string { return meta.Continue }
  99. func (meta *ListMeta) SetContinue(c string) { meta.Continue = c }
  100. func (obj *TypeMeta) GetObjectKind() schema.ObjectKind { return obj }
  101. // SetGroupVersionKind satisfies the ObjectKind interface for all objects that embed TypeMeta
  102. func (obj *TypeMeta) SetGroupVersionKind(gvk schema.GroupVersionKind) {
  103. obj.APIVersion, obj.Kind = gvk.ToAPIVersionAndKind()
  104. }
  105. // GroupVersionKind satisfies the ObjectKind interface for all objects that embed TypeMeta
  106. func (obj *TypeMeta) GroupVersionKind() schema.GroupVersionKind {
  107. return schema.FromAPIVersionAndKind(obj.APIVersion, obj.Kind)
  108. }
  109. func (obj *ListMeta) GetListMeta() ListInterface { return obj }
  110. func (obj *ObjectMeta) GetObjectMeta() Object { return obj }
  111. // Namespace implements metav1.Object for any object with an ObjectMeta typed field. Allows
  112. // fast, direct access to metadata fields for API objects.
  113. func (meta *ObjectMeta) GetNamespace() string { return meta.Namespace }
  114. func (meta *ObjectMeta) SetNamespace(namespace string) { meta.Namespace = namespace }
  115. func (meta *ObjectMeta) GetName() string { return meta.Name }
  116. func (meta *ObjectMeta) SetName(name string) { meta.Name = name }
  117. func (meta *ObjectMeta) GetGenerateName() string { return meta.GenerateName }
  118. func (meta *ObjectMeta) SetGenerateName(generateName string) { meta.GenerateName = generateName }
  119. func (meta *ObjectMeta) GetUID() types.UID { return meta.UID }
  120. func (meta *ObjectMeta) SetUID(uid types.UID) { meta.UID = uid }
  121. func (meta *ObjectMeta) GetResourceVersion() string { return meta.ResourceVersion }
  122. func (meta *ObjectMeta) SetResourceVersion(version string) { meta.ResourceVersion = version }
  123. func (meta *ObjectMeta) GetGeneration() int64 { return meta.Generation }
  124. func (meta *ObjectMeta) SetGeneration(generation int64) { meta.Generation = generation }
  125. func (meta *ObjectMeta) GetSelfLink() string { return meta.SelfLink }
  126. func (meta *ObjectMeta) SetSelfLink(selfLink string) { meta.SelfLink = selfLink }
  127. func (meta *ObjectMeta) GetCreationTimestamp() Time { return meta.CreationTimestamp }
  128. func (meta *ObjectMeta) SetCreationTimestamp(creationTimestamp Time) {
  129. meta.CreationTimestamp = creationTimestamp
  130. }
  131. func (meta *ObjectMeta) GetDeletionTimestamp() *Time { return meta.DeletionTimestamp }
  132. func (meta *ObjectMeta) SetDeletionTimestamp(deletionTimestamp *Time) {
  133. meta.DeletionTimestamp = deletionTimestamp
  134. }
  135. func (meta *ObjectMeta) GetDeletionGracePeriodSeconds() *int64 { return meta.DeletionGracePeriodSeconds }
  136. func (meta *ObjectMeta) SetDeletionGracePeriodSeconds(deletionGracePeriodSeconds *int64) {
  137. meta.DeletionGracePeriodSeconds = deletionGracePeriodSeconds
  138. }
  139. func (meta *ObjectMeta) GetLabels() map[string]string { return meta.Labels }
  140. func (meta *ObjectMeta) SetLabels(labels map[string]string) { meta.Labels = labels }
  141. func (meta *ObjectMeta) GetAnnotations() map[string]string { return meta.Annotations }
  142. func (meta *ObjectMeta) SetAnnotations(annotations map[string]string) { meta.Annotations = annotations }
  143. func (meta *ObjectMeta) GetInitializers() *Initializers { return meta.Initializers }
  144. func (meta *ObjectMeta) SetInitializers(initializers *Initializers) { meta.Initializers = initializers }
  145. func (meta *ObjectMeta) GetFinalizers() []string { return meta.Finalizers }
  146. func (meta *ObjectMeta) SetFinalizers(finalizers []string) { meta.Finalizers = finalizers }
  147. func (meta *ObjectMeta) GetOwnerReferences() []OwnerReference { return meta.OwnerReferences }
  148. func (meta *ObjectMeta) SetOwnerReferences(references []OwnerReference) {
  149. meta.OwnerReferences = references
  150. }
  151. func (meta *ObjectMeta) GetClusterName() string { return meta.ClusterName }
  152. func (meta *ObjectMeta) SetClusterName(clusterName string) { meta.ClusterName = clusterName }