pet_sets.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. Copyright 2015 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. import (
  15. "k8s.io/kubernetes/pkg/api"
  16. "k8s.io/kubernetes/pkg/apis/apps"
  17. "k8s.io/kubernetes/pkg/watch"
  18. )
  19. // PetSetNamespacer has methods to work with PetSet resources in a namespace
  20. type PetSetNamespacer interface {
  21. PetSets(namespace string) PetSetInterface
  22. }
  23. // PetSetInterface exposes methods to work on PetSet resources.
  24. type PetSetInterface interface {
  25. List(opts api.ListOptions) (*apps.PetSetList, error)
  26. Get(name string) (*apps.PetSet, error)
  27. Create(petSet *apps.PetSet) (*apps.PetSet, error)
  28. Update(petSet *apps.PetSet) (*apps.PetSet, error)
  29. Delete(name string, options *api.DeleteOptions) error
  30. Watch(opts api.ListOptions) (watch.Interface, error)
  31. UpdateStatus(petSet *apps.PetSet) (*apps.PetSet, error)
  32. }
  33. // petSet implements PetSetNamespacer interface
  34. type petSet struct {
  35. r *AppsClient
  36. ns string
  37. }
  38. // newPetSet returns a petSet
  39. func newPetSet(c *AppsClient, namespace string) *petSet {
  40. return &petSet{c, namespace}
  41. }
  42. // List returns a list of petSet that match the label and field selectors.
  43. func (c *petSet) List(opts api.ListOptions) (result *apps.PetSetList, err error) {
  44. result = &apps.PetSetList{}
  45. err = c.r.Get().Namespace(c.ns).Resource("petsets").VersionedParams(&opts, api.ParameterCodec).Do().Into(result)
  46. return
  47. }
  48. // Get returns information about a particular petSet.
  49. func (c *petSet) Get(name string) (result *apps.PetSet, err error) {
  50. result = &apps.PetSet{}
  51. err = c.r.Get().Namespace(c.ns).Resource("petsets").Name(name).Do().Into(result)
  52. return
  53. }
  54. // Create creates a new petSet.
  55. func (c *petSet) Create(petSet *apps.PetSet) (result *apps.PetSet, err error) {
  56. result = &apps.PetSet{}
  57. err = c.r.Post().Namespace(c.ns).Resource("petsets").Body(petSet).Do().Into(result)
  58. return
  59. }
  60. // Update updates an existing petSet.
  61. func (c *petSet) Update(petSet *apps.PetSet) (result *apps.PetSet, err error) {
  62. result = &apps.PetSet{}
  63. err = c.r.Put().Namespace(c.ns).Resource("petsets").Name(petSet.Name).Body(petSet).Do().Into(result)
  64. return
  65. }
  66. // Delete deletes a petSet, returns error if one occurs.
  67. func (c *petSet) Delete(name string, options *api.DeleteOptions) (err error) {
  68. return c.r.Delete().Namespace(c.ns).Resource("petsets").Name(name).Body(options).Do().Error()
  69. }
  70. // Watch returns a watch.Interface that watches the requested petSet.
  71. func (c *petSet) Watch(opts api.ListOptions) (watch.Interface, error) {
  72. return c.r.Get().
  73. Prefix("watch").
  74. Namespace(c.ns).
  75. Resource("petsets").
  76. VersionedParams(&opts, api.ParameterCodec).
  77. Watch()
  78. }
  79. // UpdateStatus takes the name of the petSet and the new status. Returns the server's representation of the petSet, and an error, if it occurs.
  80. func (c *petSet) UpdateStatus(petSet *apps.PetSet) (result *apps.PetSet, err error) {
  81. result = &apps.PetSet{}
  82. err = c.r.Put().Namespace(c.ns).Resource("petsets").Name(petSet.Name).SubResource("status").Body(petSet).Do().Into(result)
  83. return
  84. }