1/*
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	GetInitializers() *Initializers
59	SetInitializers(initializers *Initializers)
60	GetFinalizers() []string
61	SetFinalizers(finalizers []string)
62	GetOwnerReferences() []OwnerReference
63	SetOwnerReferences([]OwnerReference)
64	GetClusterName() string
65	SetClusterName(clusterName string)
66	GetManagedFields() []ManagedFieldsEntry
67	SetManagedFields(managedFields []ManagedFieldsEntry)
68}
69
70// ListMetaAccessor retrieves the list interface from an object
71type ListMetaAccessor interface {
72	GetListMeta() ListInterface
73}
74
75// Common lets you work with core metadata from any of the versioned or
76// internal API objects. Attempting to set or retrieve a field on an object that does
77// not support that field will be a no-op and return a default value.
78// TODO: move this, and TypeMeta and ListMeta, to a different package
79type Common interface {
80	GetResourceVersion() string
81	SetResourceVersion(version string)
82	GetSelfLink() string
83	SetSelfLink(selfLink string)
84}
85
86// ListInterface lets you work with list metadata from any of the versioned or
87// internal API objects. Attempting to set or retrieve a field on an object that does
88// not support that field will be a no-op and return a default value.
89// TODO: move this, and TypeMeta and ListMeta, to a different package
90type ListInterface interface {
91	GetResourceVersion() string
92	SetResourceVersion(version string)
93	GetSelfLink() string
94	SetSelfLink(selfLink string)
95	GetContinue() string
96	SetContinue(c string)
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
108func (meta *ListMeta) GetResourceVersion() string        { return meta.ResourceVersion }
109func (meta *ListMeta) SetResourceVersion(version string) { meta.ResourceVersion = version }
110func (meta *ListMeta) GetSelfLink() string               { return meta.SelfLink }
111func (meta *ListMeta) SetSelfLink(selfLink string)       { meta.SelfLink = selfLink }
112func (meta *ListMeta) GetContinue() string               { return meta.Continue }
113func (meta *ListMeta) SetContinue(c string)              { meta.Continue = c }
114
115func (obj *TypeMeta) GetObjectKind() schema.ObjectKind { return obj }
116
117// SetGroupVersionKind satisfies the ObjectKind interface for all objects that embed TypeMeta
118func (obj *TypeMeta) SetGroupVersionKind(gvk schema.GroupVersionKind) {
119	obj.APIVersion, obj.Kind = gvk.ToAPIVersionAndKind()
120}
121
122// GroupVersionKind satisfies the ObjectKind interface for all objects that embed TypeMeta
123func (obj *TypeMeta) GroupVersionKind() schema.GroupVersionKind {
124	return schema.FromAPIVersionAndKind(obj.APIVersion, obj.Kind)
125}
126
127func (obj *ListMeta) GetListMeta() ListInterface { return obj }
128
129func (obj *ObjectMeta) GetObjectMeta() Object { return obj }
130
131// Namespace implements metav1.Object for any object with an ObjectMeta typed field. Allows
132// fast, direct access to metadata fields for API objects.
133func (meta *ObjectMeta) GetNamespace() string                { return meta.Namespace }
134func (meta *ObjectMeta) SetNamespace(namespace string)       { meta.Namespace = namespace }
135func (meta *ObjectMeta) GetName() string                     { return meta.Name }
136func (meta *ObjectMeta) SetName(name string)                 { meta.Name = name }
137func (meta *ObjectMeta) GetGenerateName() string             { return meta.GenerateName }
138func (meta *ObjectMeta) SetGenerateName(generateName string) { meta.GenerateName = generateName }
139func (meta *ObjectMeta) GetUID() types.UID                   { return meta.UID }
140func (meta *ObjectMeta) SetUID(uid types.UID)                { meta.UID = uid }
141func (meta *ObjectMeta) GetResourceVersion() string          { return meta.ResourceVersion }
142func (meta *ObjectMeta) SetResourceVersion(version string)   { meta.ResourceVersion = version }
143func (meta *ObjectMeta) GetGeneration() int64                { return meta.Generation }
144func (meta *ObjectMeta) SetGeneration(generation int64)      { meta.Generation = generation }
145func (meta *ObjectMeta) GetSelfLink() string                 { return meta.SelfLink }
146func (meta *ObjectMeta) SetSelfLink(selfLink string)         { meta.SelfLink = selfLink }
147func (meta *ObjectMeta) GetCreationTimestamp() Time          { return meta.CreationTimestamp }
148func (meta *ObjectMeta) SetCreationTimestamp(creationTimestamp Time) {
149	meta.CreationTimestamp = creationTimestamp
150}
151func (meta *ObjectMeta) GetDeletionTimestamp() *Time { return meta.DeletionTimestamp }
152func (meta *ObjectMeta) SetDeletionTimestamp(deletionTimestamp *Time) {
153	meta.DeletionTimestamp = deletionTimestamp
154}
155func (meta *ObjectMeta) GetDeletionGracePeriodSeconds() *int64 { return meta.DeletionGracePeriodSeconds }
156func (meta *ObjectMeta) SetDeletionGracePeriodSeconds(deletionGracePeriodSeconds *int64) {
157	meta.DeletionGracePeriodSeconds = deletionGracePeriodSeconds
158}
159func (meta *ObjectMeta) GetLabels() map[string]string                 { return meta.Labels }
160func (meta *ObjectMeta) SetLabels(labels map[string]string)           { meta.Labels = labels }
161func (meta *ObjectMeta) GetAnnotations() map[string]string            { return meta.Annotations }
162func (meta *ObjectMeta) SetAnnotations(annotations map[string]string) { meta.Annotations = annotations }
163func (meta *ObjectMeta) GetInitializers() *Initializers               { return meta.Initializers }
164func (meta *ObjectMeta) SetInitializers(initializers *Initializers)   { meta.Initializers = initializers }
165func (meta *ObjectMeta) GetFinalizers() []string                      { return meta.Finalizers }
166func (meta *ObjectMeta) SetFinalizers(finalizers []string)            { meta.Finalizers = finalizers }
167func (meta *ObjectMeta) GetOwnerReferences() []OwnerReference         { return meta.OwnerReferences }
168func (meta *ObjectMeta) SetOwnerReferences(references []OwnerReference) {
169	meta.OwnerReferences = references
170}
171func (meta *ObjectMeta) GetClusterName() string                 { return meta.ClusterName }
172func (meta *ObjectMeta) SetClusterName(clusterName string)      { meta.ClusterName = clusterName }
173func (meta *ObjectMeta) GetManagedFields() []ManagedFieldsEntry { return meta.ManagedFields }
174func (meta *ObjectMeta) SetManagedFields(managedFields []ManagedFieldsEntry) {
175	meta.ManagedFields = managedFields
176}
177