meta.go 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 v1
  14. import (
  15. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  16. "k8s.io/apimachinery/pkg/types"
  17. )
  18. func (obj *ObjectMeta) GetObjectMeta() metav1.Object { return obj }
  19. // Namespace implements metav1.Object for any object with an ObjectMeta typed field. Allows
  20. // fast, direct access to metadata fields for API objects.
  21. func (meta *ObjectMeta) GetNamespace() string { return meta.Namespace }
  22. func (meta *ObjectMeta) SetNamespace(namespace string) { meta.Namespace = namespace }
  23. func (meta *ObjectMeta) GetName() string { return meta.Name }
  24. func (meta *ObjectMeta) SetName(name string) { meta.Name = name }
  25. func (meta *ObjectMeta) GetGenerateName() string { return meta.GenerateName }
  26. func (meta *ObjectMeta) SetGenerateName(generateName string) { meta.GenerateName = generateName }
  27. func (meta *ObjectMeta) GetUID() types.UID { return meta.UID }
  28. func (meta *ObjectMeta) SetUID(uid types.UID) { meta.UID = uid }
  29. func (meta *ObjectMeta) GetResourceVersion() string { return meta.ResourceVersion }
  30. func (meta *ObjectMeta) SetResourceVersion(version string) { meta.ResourceVersion = version }
  31. func (meta *ObjectMeta) GetSelfLink() string { return meta.SelfLink }
  32. func (meta *ObjectMeta) SetSelfLink(selfLink string) { meta.SelfLink = selfLink }
  33. func (meta *ObjectMeta) GetCreationTimestamp() metav1.Time { return meta.CreationTimestamp }
  34. func (meta *ObjectMeta) SetCreationTimestamp(creationTimestamp metav1.Time) {
  35. meta.CreationTimestamp = creationTimestamp
  36. }
  37. func (meta *ObjectMeta) GetDeletionTimestamp() *metav1.Time { return meta.DeletionTimestamp }
  38. func (meta *ObjectMeta) SetDeletionTimestamp(deletionTimestamp *metav1.Time) {
  39. meta.DeletionTimestamp = deletionTimestamp
  40. }
  41. func (meta *ObjectMeta) GetLabels() map[string]string { return meta.Labels }
  42. func (meta *ObjectMeta) SetLabels(labels map[string]string) { meta.Labels = labels }
  43. func (meta *ObjectMeta) GetAnnotations() map[string]string { return meta.Annotations }
  44. func (meta *ObjectMeta) SetAnnotations(annotations map[string]string) { meta.Annotations = annotations }
  45. func (meta *ObjectMeta) GetFinalizers() []string { return meta.Finalizers }
  46. func (meta *ObjectMeta) SetFinalizers(finalizers []string) { meta.Finalizers = finalizers }
  47. func (meta *ObjectMeta) GetOwnerReferences() []metav1.OwnerReference {
  48. ret := make([]metav1.OwnerReference, len(meta.OwnerReferences))
  49. for i := 0; i < len(meta.OwnerReferences); i++ {
  50. ret[i].Kind = meta.OwnerReferences[i].Kind
  51. ret[i].Name = meta.OwnerReferences[i].Name
  52. ret[i].UID = meta.OwnerReferences[i].UID
  53. ret[i].APIVersion = meta.OwnerReferences[i].APIVersion
  54. if meta.OwnerReferences[i].Controller != nil {
  55. value := *meta.OwnerReferences[i].Controller
  56. ret[i].Controller = &value
  57. }
  58. if meta.OwnerReferences[i].BlockOwnerDeletion != nil {
  59. value := *meta.OwnerReferences[i].BlockOwnerDeletion
  60. ret[i].BlockOwnerDeletion = &value
  61. }
  62. }
  63. return ret
  64. }
  65. func (meta *ObjectMeta) SetOwnerReferences(references []metav1.OwnerReference) {
  66. newReferences := make([]metav1.OwnerReference, len(references))
  67. for i := 0; i < len(references); i++ {
  68. newReferences[i].Kind = references[i].Kind
  69. newReferences[i].Name = references[i].Name
  70. newReferences[i].UID = references[i].UID
  71. newReferences[i].APIVersion = references[i].APIVersion
  72. if references[i].Controller != nil {
  73. value := *references[i].Controller
  74. newReferences[i].Controller = &value
  75. }
  76. if references[i].BlockOwnerDeletion != nil {
  77. value := *references[i].BlockOwnerDeletion
  78. newReferences[i].BlockOwnerDeletion = &value
  79. }
  80. }
  81. meta.OwnerReferences = newReferences
  82. }
  83. func (meta *ObjectMeta) GetClusterName() string {
  84. return meta.ClusterName
  85. }
  86. func (meta *ObjectMeta) SetClusterName(clusterName string) {
  87. meta.ClusterName = clusterName
  88. }