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