replica_sets.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. import (
  15. "k8s.io/kubernetes/pkg/api"
  16. "k8s.io/kubernetes/pkg/apis/extensions"
  17. "k8s.io/kubernetes/pkg/watch"
  18. )
  19. // ReplicaSetsNamespacer has methods to work with ReplicaSet resources in a namespace
  20. type ReplicaSetsNamespacer interface {
  21. ReplicaSets(namespace string) ReplicaSetInterface
  22. }
  23. // ReplicaSetInterface has methods to work with ReplicaSet resources.
  24. type ReplicaSetInterface interface {
  25. List(opts api.ListOptions) (*extensions.ReplicaSetList, error)
  26. Get(name string) (*extensions.ReplicaSet, error)
  27. Create(ctrl *extensions.ReplicaSet) (*extensions.ReplicaSet, error)
  28. Update(ctrl *extensions.ReplicaSet) (*extensions.ReplicaSet, error)
  29. UpdateStatus(ctrl *extensions.ReplicaSet) (*extensions.ReplicaSet, error)
  30. Delete(name string, options *api.DeleteOptions) error
  31. Watch(opts api.ListOptions) (watch.Interface, error)
  32. }
  33. // replicaSets implements ReplicaSetsNamespacer interface
  34. type replicaSets struct {
  35. client *ExtensionsClient
  36. ns string
  37. }
  38. // newReplicaSets returns a ReplicaSetClient
  39. func newReplicaSets(c *ExtensionsClient, namespace string) *replicaSets {
  40. return &replicaSets{c, namespace}
  41. }
  42. // List takes a selector, and returns the list of ReplicaSets that match that selector.
  43. func (c *replicaSets) List(opts api.ListOptions) (result *extensions.ReplicaSetList, err error) {
  44. result = &extensions.ReplicaSetList{}
  45. err = c.client.Get().Namespace(c.ns).Resource("replicasets").VersionedParams(&opts, api.ParameterCodec).Do().Into(result)
  46. return
  47. }
  48. // Get returns information about a particular ReplicaSet.
  49. func (c *replicaSets) Get(name string) (result *extensions.ReplicaSet, err error) {
  50. result = &extensions.ReplicaSet{}
  51. err = c.client.Get().Namespace(c.ns).Resource("replicasets").Name(name).Do().Into(result)
  52. return
  53. }
  54. // Create creates a new ReplicaSet.
  55. func (c *replicaSets) Create(rs *extensions.ReplicaSet) (result *extensions.ReplicaSet, err error) {
  56. result = &extensions.ReplicaSet{}
  57. err = c.client.Post().Namespace(c.ns).Resource("replicasets").Body(rs).Do().Into(result)
  58. return
  59. }
  60. // Update updates an existing ReplicaSet.
  61. func (c *replicaSets) Update(rs *extensions.ReplicaSet) (result *extensions.ReplicaSet, err error) {
  62. result = &extensions.ReplicaSet{}
  63. err = c.client.Put().Namespace(c.ns).Resource("replicasets").Name(rs.Name).Body(rs).Do().Into(result)
  64. return
  65. }
  66. // UpdateStatus updates an existing ReplicaSet status
  67. func (c *replicaSets) UpdateStatus(rs *extensions.ReplicaSet) (result *extensions.ReplicaSet, err error) {
  68. result = &extensions.ReplicaSet{}
  69. err = c.client.Put().Namespace(c.ns).Resource("replicasets").Name(rs.Name).SubResource("status").Body(rs).Do().Into(result)
  70. return
  71. }
  72. // Delete deletes an existing ReplicaSet.
  73. func (c *replicaSets) Delete(name string, options *api.DeleteOptions) (err error) {
  74. return c.client.Delete().Namespace(c.ns).Resource("replicasets").Name(name).Body(options).Do().Error()
  75. }
  76. // Watch returns a watch.Interface that watches the requested ReplicaSets.
  77. func (c *replicaSets) Watch(opts api.ListOptions) (watch.Interface, error) {
  78. return c.client.Get().
  79. Prefix("watch").
  80. Namespace(c.ns).
  81. Resource("replicasets").
  82. VersionedParams(&opts, api.ParameterCodec).
  83. Watch()
  84. }