github.com/aclisp/heapster@v0.19.2-0.20160613100040-51756f899a96/Godeps/_workspace/src/k8s.io/kubernetes/pkg/api/meta.go (about) 1 /* 2 Copyright 2014 The Kubernetes Authors All rights reserved. 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 api 18 19 import ( 20 "k8s.io/kubernetes/pkg/api/unversioned" 21 "k8s.io/kubernetes/pkg/conversion" 22 "k8s.io/kubernetes/pkg/runtime" 23 "k8s.io/kubernetes/pkg/types" 24 "k8s.io/kubernetes/pkg/util" 25 ) 26 27 // FillObjectMetaSystemFields populates fields that are managed by the system on ObjectMeta. 28 func FillObjectMetaSystemFields(ctx Context, meta *ObjectMeta) { 29 meta.CreationTimestamp = unversioned.Now() 30 meta.UID = util.NewUUID() 31 meta.SelfLink = "" 32 } 33 34 // HasObjectMetaSystemFieldValues returns true if fields that are managed by the system on ObjectMeta have values. 35 func HasObjectMetaSystemFieldValues(meta *ObjectMeta) bool { 36 return !meta.CreationTimestamp.Time.IsZero() || 37 len(meta.UID) != 0 38 } 39 40 // ObjectMetaFor returns a pointer to a provided object's ObjectMeta. 41 // TODO: allow runtime.Unknown to extract this object 42 // TODO: Remove this function and use meta.Accessor() instead. 43 func ObjectMetaFor(obj runtime.Object) (*ObjectMeta, error) { 44 v, err := conversion.EnforcePtr(obj) 45 if err != nil { 46 return nil, err 47 } 48 var meta *ObjectMeta 49 err = runtime.FieldPtr(v, "ObjectMeta", &meta) 50 return meta, err 51 } 52 53 // ListMetaFor returns a pointer to a provided object's ListMeta, 54 // or an error if the object does not have that pointer. 55 // TODO: allow runtime.Unknown to extract this object 56 func ListMetaFor(obj runtime.Object) (*unversioned.ListMeta, error) { 57 v, err := conversion.EnforcePtr(obj) 58 if err != nil { 59 return nil, err 60 } 61 var meta *unversioned.ListMeta 62 err = runtime.FieldPtr(v, "ListMeta", &meta) 63 return meta, err 64 } 65 66 // Namespace implements meta.Object for any object with an ObjectMeta typed field. Allows 67 // fast, direct access to metadata fields for API objects. 68 func (meta *ObjectMeta) GetNamespace() string { return meta.Namespace } 69 func (meta *ObjectMeta) SetNamespace(namespace string) { meta.Namespace = namespace } 70 func (meta *ObjectMeta) GetName() string { return meta.Name } 71 func (meta *ObjectMeta) SetName(name string) { meta.Name = name } 72 func (meta *ObjectMeta) GetGenerateName() string { return meta.GenerateName } 73 func (meta *ObjectMeta) SetGenerateName(generateName string) { meta.GenerateName = generateName } 74 func (meta *ObjectMeta) GetUID() types.UID { return meta.UID } 75 func (meta *ObjectMeta) SetUID(uid types.UID) { meta.UID = uid } 76 func (meta *ObjectMeta) GetResourceVersion() string { return meta.ResourceVersion } 77 func (meta *ObjectMeta) SetResourceVersion(version string) { meta.ResourceVersion = version } 78 func (meta *ObjectMeta) GetSelfLink() string { return meta.SelfLink } 79 func (meta *ObjectMeta) SetSelfLink(selfLink string) { meta.SelfLink = selfLink } 80 func (meta *ObjectMeta) GetCreationTimestamp() unversioned.Time { return meta.CreationTimestamp } 81 func (meta *ObjectMeta) SetCreationTimestamp(creationTimestamp unversioned.Time) { 82 meta.CreationTimestamp = creationTimestamp 83 } 84 func (meta *ObjectMeta) GetDeletionTimestamp() *unversioned.Time { return meta.DeletionTimestamp } 85 func (meta *ObjectMeta) SetDeletionTimestamp(deletionTimestamp *unversioned.Time) { 86 meta.DeletionTimestamp = deletionTimestamp 87 } 88 func (meta *ObjectMeta) GetLabels() map[string]string { return meta.Labels } 89 func (meta *ObjectMeta) SetLabels(labels map[string]string) { meta.Labels = labels } 90 func (meta *ObjectMeta) GetAnnotations() map[string]string { return meta.Annotations } 91 func (meta *ObjectMeta) SetAnnotations(annotations map[string]string) { meta.Annotations = annotations }