meta.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. Copyright 2016 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 unversioned
  14. // ListMetaAccessor retrieves the list interface from an object
  15. // TODO: move this, and TypeMeta and ListMeta, to a different package
  16. type ListMetaAccessor interface {
  17. GetListMeta() List
  18. }
  19. // List lets you work with list metadata from any of the versioned or
  20. // internal API objects. Attempting to set or retrieve a field on an object that does
  21. // not support that field will be a no-op and return a default value.
  22. // TODO: move this, and TypeMeta and ListMeta, to a different package
  23. type List interface {
  24. GetResourceVersion() string
  25. SetResourceVersion(version string)
  26. GetSelfLink() string
  27. SetSelfLink(selfLink string)
  28. }
  29. // Type exposes the type and APIVersion of versioned or internal API objects.
  30. // TODO: move this, and TypeMeta and ListMeta, to a different package
  31. type Type interface {
  32. GetAPIVersion() string
  33. SetAPIVersion(version string)
  34. GetKind() string
  35. SetKind(kind string)
  36. }
  37. func (meta *ListMeta) GetResourceVersion() string { return meta.ResourceVersion }
  38. func (meta *ListMeta) SetResourceVersion(version string) { meta.ResourceVersion = version }
  39. func (meta *ListMeta) GetSelfLink() string { return meta.SelfLink }
  40. func (meta *ListMeta) SetSelfLink(selfLink string) { meta.SelfLink = selfLink }
  41. func (obj *TypeMeta) GetObjectKind() ObjectKind { return obj }
  42. // SetGroupVersionKind satisfies the ObjectKind interface for all objects that embed TypeMeta
  43. func (obj *TypeMeta) SetGroupVersionKind(gvk GroupVersionKind) {
  44. obj.APIVersion, obj.Kind = gvk.ToAPIVersionAndKind()
  45. }
  46. // GroupVersionKind satisfies the ObjectKind interface for all objects that embed TypeMeta
  47. func (obj *TypeMeta) GroupVersionKind() GroupVersionKind {
  48. return FromAPIVersionAndKind(obj.APIVersion, obj.Kind)
  49. }
  50. func (obj *ListMeta) GetListMeta() List { return obj }