| 1 |
/* |
| 2 |
Copyright 2016 The Kubernetes Authors. |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
package v1 |
| 18 |
|
| 19 |
import ( |
| 20 |
"k8s.io/apimachinery/pkg/runtime/schema" |
| 21 |
"k8s.io/apimachinery/pkg/types" |
| 22 |
) |
| 23 |
|
| 24 |
// TODO: move this, Object, List, and Type to a different package |
| 25 |
type ObjectMetaAccessor interface { |
| 26 |
GetObjectMeta() Object |
| 27 |
} |
| 28 |
|
| 29 |
// Object lets you work with object 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 |
type Object interface { |
| 34 |
GetNamespace() string |
| 35 |
SetNamespace(namespace string) |
| 36 |
GetName() string |
| 37 |
SetName(name string) |
| 38 |
GetGenerateName() string |
| 39 |
SetGenerateName(name string) |
| 40 |
GetUID() types.UID |
| 41 |
SetUID(uid types.UID) |
| 42 |
GetResourceVersion() string |
| 43 |
SetResourceVersion(version string) |
| 44 |
GetGeneration() int64 |
| 45 |
SetGeneration(generation int64) |
| 46 |
GetSelfLink() string |
| 47 |
SetSelfLink(selfLink string) |
| 48 |
GetCreationTimestamp() Time |
| 49 |
SetCreationTimestamp(timestamp Time) |
| 50 |
GetDeletionTimestamp() *Time |
| 51 |
SetDeletionTimestamp(timestamp *Time) |
| 52 |
GetDeletionGracePeriodSeconds() *int64 |
| 53 |
SetDeletionGracePeriodSeconds(*int64) |
| 54 |
GetLabels() map[string]string |
| 55 |
SetLabels(labels map[string]string) |
| 56 |
GetAnnotations() map[string]string |
| 57 |
SetAnnotations(annotations map[string]string) |
| 58 |
GetFinalizers() []string |
| 59 |
SetFinalizers(finalizers []string) |
| 60 |
GetOwnerReferences() []OwnerReference |
| 61 |
SetOwnerReferences([]OwnerReference) |
| 62 |
GetManagedFields() []ManagedFieldsEntry |
| 63 |
SetManagedFields(managedFields []ManagedFieldsEntry) |
| 64 |
} |
| 65 |
|
| 66 |
// ListMetaAccessor retrieves the list interface from an object |
| 67 |
type ListMetaAccessor interface { |
| 68 |
GetListMeta() ListInterface |
| 69 |
} |
| 70 |
|
| 71 |
// Common lets you work with core metadata from any of the versioned or |
| 72 |
// internal API objects. Attempting to set or retrieve a field on an object that does |
| 73 |
// not support that field will be a no-op and return a default value. |
| 74 |
// TODO: move this, and TypeMeta and ListMeta, to a different package |
| 75 |
type Common interface { |
| 76 |
GetResourceVersion() string |
| 77 |
SetResourceVersion(version string) |
| 78 |
GetSelfLink() string |
| 79 |
SetSelfLink(selfLink string) |
| 80 |
} |
| 81 |
|
| 82 |
// ListInterface lets you work with list metadata from any of the versioned or |
| 83 |
// internal API objects. Attempting to set or retrieve a field on an object that does |
| 84 |
// not support that field will be a no-op and return a default value. |
| 85 |
// TODO: move this, and TypeMeta and ListMeta, to a different package |
| 86 |
type ListInterface interface { |
| 87 |
GetResourceVersion() string |
| 88 |
SetResourceVersion(version string) |
| 89 |
GetSelfLink() string |
| 90 |
SetSelfLink(selfLink string) |
| 91 |
GetContinue() string |
| 92 |
SetContinue(c string) |
| 93 |
GetRemainingItemCount() *int64 |
| 94 |
SetRemainingItemCount(c *int64) |
| 95 |
} |
| 96 |
|
| 97 |
// Type exposes the type and APIVersion of versioned or internal API objects. |
| 98 |
// TODO: move this, and TypeMeta and ListMeta, to a different package |
| 99 |
type Type interface { |
| 100 |
GetAPIVersion() string |
| 101 |
SetAPIVersion(version string) |
| 102 |
GetKind() string |
| 103 |
SetKind(kind string) |
| 104 |
} |
| 105 |
|
| 106 |
var _ ListInterface = &ListMeta{} |
| 107 |
|
| 108 |
func (meta *ListMeta) GetResourceVersion() string { return meta.ResourceVersion } |
| 109 |
func (meta *ListMeta) SetResourceVersion(version string) { meta.ResourceVersion = version } |
| 110 |
func (meta *ListMeta) GetSelfLink() string { return meta.SelfLink } |
| 111 |
func (meta *ListMeta) SetSelfLink(selfLink string) { meta.SelfLink = selfLink } |
| 112 |
func (meta *ListMeta) GetContinue() string { return meta.Continue } |
| 113 |
func (meta *ListMeta) SetContinue(c string) { meta.Continue = c } |
| 114 |
func (meta *ListMeta) GetRemainingItemCount() *int64 { return meta.RemainingItemCount } |
| 115 |
func (meta *ListMeta) SetRemainingItemCount(c *int64) { meta.RemainingItemCount = c } |
| 116 |
|
| 117 |
func (obj *TypeMeta) GetObjectKind() schema.ObjectKind { return obj } |
| 118 |
|
| 119 |
// SetGroupVersionKind satisfies the ObjectKind interface for all objects that embed TypeMeta |
| 120 |
func (obj *TypeMeta) SetGroupVersionKind(gvk schema.GroupVersionKind) { |
| 121 |
obj.APIVersion, obj.Kind = gvk.ToAPIVersionAndKind() |
| 122 |
} |
| 123 |
|
| 124 |
// GroupVersionKind satisfies the ObjectKind interface for all objects that embed TypeMeta |
| 125 |
func (obj *TypeMeta) GroupVersionKind() schema.GroupVersionKind { |
| 126 |
return schema.FromAPIVersionAndKind(obj.APIVersion, obj.Kind) |
| 127 |
} |
| 128 |
|
| 129 |
func (obj *ListMeta) GetListMeta() ListInterface { return obj } |
| 130 |
|
| 131 |
func (obj *ObjectMeta) GetObjectMeta() Object { return obj } |
| 132 |
|
| 133 |
// Namespace implements metav1.Object for any object with an ObjectMeta typed field. Allows |
| 134 |
// fast, direct access to metadata fields for API objects. |
| 135 |
func (meta *ObjectMeta) GetNamespace() string { return meta.Namespace } |
| 136 |
func (meta *ObjectMeta) SetNamespace(namespace string) { meta.Namespace = namespace } |
| 137 |
func (meta *ObjectMeta) GetName() string { return meta.Name } |
| 138 |
func (meta *ObjectMeta) SetName(name string) { meta.Name = name } |
| 139 |
func (meta *ObjectMeta) GetGenerateName() string { return meta.GenerateName } |
| 140 |
func (meta *ObjectMeta) SetGenerateName(generateName string) { meta.GenerateName = generateName } |
| 141 |
func (meta *ObjectMeta) GetUID() types.UID { return meta.UID } |
| 142 |
func (meta *ObjectMeta) SetUID(uid types.UID) { meta.UID = uid } |
| 143 |
func (meta *ObjectMeta) GetResourceVersion() string { return meta.ResourceVersion } |
| 144 |
func (meta *ObjectMeta) SetResourceVersion(version string) { meta.ResourceVersion = version } |
| 145 |
func (meta *ObjectMeta) GetGeneration() int64 { return meta.Generation } |
| 146 |
func (meta *ObjectMeta) SetGeneration(generation int64) { meta.Generation = generation } |
| 147 |
func (meta *ObjectMeta) GetSelfLink() string { return meta.SelfLink } |
| 148 |
func (meta *ObjectMeta) SetSelfLink(selfLink string) { meta.SelfLink = selfLink } |
| 149 |
func (meta *ObjectMeta) GetCreationTimestamp() Time { return meta.CreationTimestamp } |
| 150 |
func (meta *ObjectMeta) SetCreationTimestamp(creationTimestamp Time) { |
| 151 |
meta.CreationTimestamp = creationTimestamp |
| 152 |
} |
| 153 |
func (meta *ObjectMeta) GetDeletionTimestamp() *Time { return meta.DeletionTimestamp } |
| 154 |
func (meta *ObjectMeta) SetDeletionTimestamp(deletionTimestamp *Time) { |
| 155 |
meta.DeletionTimestamp = deletionTimestamp |
| 156 |
} |
| 157 |
func (meta *ObjectMeta) GetDeletionGracePeriodSeconds() *int64 { |
| 158 |
return meta.DeletionGracePeriodSeconds |
| 159 |
} |
| 160 |
func (meta *ObjectMeta) SetDeletionGracePeriodSeconds(deletionGracePeriodSeconds *int64) { |
| 161 |
meta.DeletionGracePeriodSeconds = deletionGracePeriodSeconds |
| 162 |
} |
| 163 |
func (meta *ObjectMeta) GetLabels() map[string]string { return meta.Labels } |
| 164 |
func (meta *ObjectMeta) SetLabels(labels map[string]string) { meta.Labels = labels } |
| 165 |
func (meta *ObjectMeta) GetAnnotations() map[string]string { return meta.Annotations } |
| 166 |
func (meta *ObjectMeta) SetAnnotations(annotations map[string]string) { meta.Annotations = annotations } |
| 167 |
func (meta *ObjectMeta) GetFinalizers() []string { return meta.Finalizers } |
| 168 |
func (meta *ObjectMeta) SetFinalizers(finalizers []string) { meta.Finalizers = finalizers } |
| 169 |
func (meta *ObjectMeta) GetOwnerReferences() []OwnerReference { return meta.OwnerReferences } |
| 170 |
func (meta *ObjectMeta) SetOwnerReferences(references []OwnerReference) { |
| 171 |
meta.OwnerReferences = references |
| 172 |
} |
| 173 |
func (meta *ObjectMeta) GetManagedFields() []ManagedFieldsEntry { return meta.ManagedFields } |
| 174 |
func (meta *ObjectMeta) SetManagedFields(managedFields []ManagedFieldsEntry) { |
| 175 |
meta.ManagedFields = managedFields |
| 176 |
} |