replication_controllers.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. Copyright 2014 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/watch"
  17. )
  18. // ReplicationControllersNamespacer has methods to work with ReplicationController resources in a namespace
  19. type ReplicationControllersNamespacer interface {
  20. ReplicationControllers(namespace string) ReplicationControllerInterface
  21. }
  22. // ReplicationControllerInterface has methods to work with ReplicationController resources.
  23. type ReplicationControllerInterface interface {
  24. List(opts api.ListOptions) (*api.ReplicationControllerList, error)
  25. Get(name string) (*api.ReplicationController, error)
  26. Create(ctrl *api.ReplicationController) (*api.ReplicationController, error)
  27. Update(ctrl *api.ReplicationController) (*api.ReplicationController, error)
  28. UpdateStatus(ctrl *api.ReplicationController) (*api.ReplicationController, error)
  29. Delete(name string, options *api.DeleteOptions) error
  30. Watch(opts api.ListOptions) (watch.Interface, error)
  31. }
  32. // replicationControllers implements ReplicationControllersNamespacer interface
  33. type replicationControllers struct {
  34. r *Client
  35. ns string
  36. }
  37. // newReplicationControllers returns a PodsClient
  38. func newReplicationControllers(c *Client, namespace string) *replicationControllers {
  39. return &replicationControllers{c, namespace}
  40. }
  41. // List takes a selector, and returns the list of replication controllers that match that selector.
  42. func (c *replicationControllers) List(opts api.ListOptions) (result *api.ReplicationControllerList, err error) {
  43. result = &api.ReplicationControllerList{}
  44. err = c.r.Get().Namespace(c.ns).Resource("replicationControllers").VersionedParams(&opts, api.ParameterCodec).Do().Into(result)
  45. return
  46. }
  47. // Get returns information about a particular replication controller.
  48. func (c *replicationControllers) Get(name string) (result *api.ReplicationController, err error) {
  49. result = &api.ReplicationController{}
  50. err = c.r.Get().Namespace(c.ns).Resource("replicationControllers").Name(name).Do().Into(result)
  51. return
  52. }
  53. // Create creates a new replication controller.
  54. func (c *replicationControllers) Create(controller *api.ReplicationController) (result *api.ReplicationController, err error) {
  55. result = &api.ReplicationController{}
  56. err = c.r.Post().Namespace(c.ns).Resource("replicationControllers").Body(controller).Do().Into(result)
  57. return
  58. }
  59. // Update updates an existing replication controller.
  60. func (c *replicationControllers) Update(controller *api.ReplicationController) (result *api.ReplicationController, err error) {
  61. result = &api.ReplicationController{}
  62. err = c.r.Put().Namespace(c.ns).Resource("replicationControllers").Name(controller.Name).Body(controller).Do().Into(result)
  63. return
  64. }
  65. // UpdateStatus updates an existing replication controller status
  66. func (c *replicationControllers) UpdateStatus(controller *api.ReplicationController) (result *api.ReplicationController, err error) {
  67. result = &api.ReplicationController{}
  68. err = c.r.Put().Namespace(c.ns).Resource("replicationControllers").Name(controller.Name).SubResource("status").Body(controller).Do().Into(result)
  69. return
  70. }
  71. // Delete deletes an existing replication controller.
  72. func (c *replicationControllers) Delete(name string, options *api.DeleteOptions) error {
  73. return c.r.Delete().Namespace(c.ns).Resource("replicationControllers").Name(name).Body(options).Do().Error()
  74. }
  75. // Watch returns a watch.Interface that watches the requested controllers.
  76. func (c *replicationControllers) Watch(opts api.ListOptions) (watch.Interface, error) {
  77. return c.r.Get().
  78. Prefix("watch").
  79. Namespace(c.ns).
  80. Resource("replicationControllers").
  81. VersionedParams(&opts, api.ParameterCodec).
  82. Watch()
  83. }