meta.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. GetFinalizers() []string
  52. SetFinalizers(finalizers []string)
  53. GetOwnerReferences() []OwnerReference
  54. SetOwnerReferences([]OwnerReference)
  55. GetManagedFields() []ManagedFieldsEntry
  56. SetManagedFields(managedFields []ManagedFieldsEntry)
  57. }
  58. // ListMetaAccessor retrieves the list interface from an object
  59. type ListMetaAccessor interface {
  60. GetListMeta() ListInterface
  61. }
  62. // Common lets you work with core 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. // TODO: move this, and TypeMeta and ListMeta, to a different package
  66. type Common interface {
  67. GetResourceVersion() string
  68. SetResourceVersion(version string)
  69. GetSelfLink() string
  70. SetSelfLink(selfLink string)
  71. }
  72. // ListInterface lets you work with list metadata from any of the versioned or
  73. // internal API objects. Attempting to set or retrieve a field on an object that does
  74. // not support that field will be a no-op and return a default value.
  75. // TODO: move this, and TypeMeta and ListMeta, to a different package
  76. type ListInterface interface {
  77. GetResourceVersion() string
  78. SetResourceVersion(version string)
  79. GetSelfLink() string
  80. SetSelfLink(selfLink string)
  81. GetContinue() string
  82. SetContinue(c string)
  83. GetRemainingItemCount() *int64
  84. SetRemainingItemCount(c *int64)
  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. var _ ListInterface = &ListMeta{}
  95. func (meta *ListMeta) GetResourceVersion() string { return meta.ResourceVersion }
  96. func (meta *ListMeta) SetResourceVersion(version string) { meta.ResourceVersion = version }
  97. func (meta *ListMeta) GetSelfLink() string { return meta.SelfLink }
  98. func (meta *ListMeta) SetSelfLink(selfLink string) { meta.SelfLink = selfLink }
  99. func (meta *ListMeta) GetContinue() string { return meta.Continue }
  100. func (meta *ListMeta) SetContinue(c string) { meta.Continue = c }
  101. func (meta *ListMeta) GetRemainingItemCount() *int64 { return meta.RemainingItemCount }
  102. func (meta *ListMeta) SetRemainingItemCount(c *int64) { meta.RemainingItemCount = c }
  103. func (obj *TypeMeta) GetObjectKind() schema.ObjectKind { return obj }
  104. // SetGroupVersionKind satisfies the ObjectKind interface for all objects that embed TypeMeta
  105. func (obj *TypeMeta) SetGroupVersionKind(gvk schema.GroupVersionKind) {
  106. obj.APIVersion, obj.Kind = gvk.ToAPIVersionAndKind()
  107. }
  108. // GroupVersionKind satisfies the ObjectKind interface for all objects that embed TypeMeta
  109. func (obj *TypeMeta) GroupVersionKind() schema.GroupVersionKind {
  110. return schema.FromAPIVersionAndKind(obj.APIVersion, obj.Kind)
  111. }
  112. func (obj *ListMeta) GetListMeta() ListInterface { return obj }
  113. func (obj *ObjectMeta) GetObjectMeta() Object { return obj }
  114. // Namespace implements metav1.Object for any object with an ObjectMeta typed field. Allows
  115. // fast, direct access to metadata fields for API objects.
  116. func (meta *ObjectMeta) GetNamespace() string { return meta.Namespace }
  117. func (meta *ObjectMeta) SetNamespace(namespace string) { meta.Namespace = namespace }
  118. func (meta *ObjectMeta) GetName() string { return meta.Name }
  119. func (meta *ObjectMeta) SetName(name string) { meta.Name = name }
  120. func (meta *ObjectMeta) GetGenerateName() string { return meta.GenerateName }
  121. func (meta *ObjectMeta) SetGenerateName(generateName string) { meta.GenerateName = generateName }
  122. func (meta *ObjectMeta) GetUID() types.UID { return meta.UID }
  123. func (meta *ObjectMeta) SetUID(uid types.UID) { meta.UID = uid }
  124. func (meta *ObjectMeta) GetResourceVersion() string { return meta.ResourceVersion }
  125. func (meta *ObjectMeta) SetResourceVersion(version string) { meta.ResourceVersion = version }
  126. func (meta *ObjectMeta) GetGeneration() int64 { return meta.Generation }
  127. func (meta *ObjectMeta) SetGeneration(generation int64) { meta.Generation = generation }
  128. func (meta *ObjectMeta) GetSelfLink() string { return meta.SelfLink }
  129. func (meta *ObjectMeta) SetSelfLink(selfLink string) { meta.SelfLink = selfLink }
  130. func (meta *ObjectMeta) GetCreationTimestamp() Time { return meta.CreationTimestamp }
  131. func (meta *ObjectMeta) SetCreationTimestamp(creationTimestamp Time) {
  132. meta.CreationTimestamp = creationTimestamp
  133. }
  134. func (meta *ObjectMeta) GetDeletionTimestamp() *Time { return meta.DeletionTimestamp }
  135. func (meta *ObjectMeta) SetDeletionTimestamp(deletionTimestamp *Time) {
  136. meta.DeletionTimestamp = deletionTimestamp
  137. }
  138. func (meta *ObjectMeta) GetDeletionGracePeriodSeconds() *int64 {
  139. return meta.DeletionGracePeriodSeconds
  140. }
  141. func (meta *ObjectMeta) SetDeletionGracePeriodSeconds(deletionGracePeriodSeconds *int64) {
  142. meta.DeletionGracePeriodSeconds = deletionGracePeriodSeconds
  143. }
  144. func (meta *ObjectMeta) GetLabels() map[string]string { return meta.Labels }
  145. func (meta *ObjectMeta) SetLabels(labels map[string]string) { meta.Labels = labels }
  146. func (meta *ObjectMeta) GetAnnotations() map[string]string { return meta.Annotations }
  147. func (meta *ObjectMeta) SetAnnotations(annotations map[string]string) { meta.Annotations = annotations }
  148. func (meta *ObjectMeta) GetFinalizers() []string { return meta.Finalizers }
  149. func (meta *ObjectMeta) SetFinalizers(finalizers []string) { meta.Finalizers = finalizers }
  150. func (meta *ObjectMeta) GetOwnerReferences() []OwnerReference { return meta.OwnerReferences }
  151. func (meta *ObjectMeta) SetOwnerReferences(references []OwnerReference) {
  152. meta.OwnerReferences = references
  153. }
  154. func (meta *ObjectMeta) GetManagedFields() []ManagedFieldsEntry { return meta.ManagedFields }
  155. func (meta *ObjectMeta) SetManagedFields(managedFields []ManagedFieldsEntry) {
  156. meta.ManagedFields = managedFields
  157. }