horizontalpodautoscaler.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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/autoscaling"
  17. "k8s.io/kubernetes/pkg/watch"
  18. )
  19. // HorizontalPodAutoscalersNamespacer has methods to work with HorizontalPodAutoscaler resources in a namespace
  20. type HorizontalPodAutoscalersNamespacer interface {
  21. HorizontalPodAutoscalers(namespace string) HorizontalPodAutoscalerInterface
  22. }
  23. // HorizontalPodAutoscalerInterface has methods to work with HorizontalPodAutoscaler resources.
  24. type HorizontalPodAutoscalerInterface interface {
  25. List(opts api.ListOptions) (*autoscaling.HorizontalPodAutoscalerList, error)
  26. Get(name string) (*autoscaling.HorizontalPodAutoscaler, error)
  27. Delete(name string, options *api.DeleteOptions) error
  28. Create(horizontalPodAutoscaler *autoscaling.HorizontalPodAutoscaler) (*autoscaling.HorizontalPodAutoscaler, error)
  29. Update(horizontalPodAutoscaler *autoscaling.HorizontalPodAutoscaler) (*autoscaling.HorizontalPodAutoscaler, error)
  30. UpdateStatus(horizontalPodAutoscaler *autoscaling.HorizontalPodAutoscaler) (*autoscaling.HorizontalPodAutoscaler, error)
  31. Watch(opts api.ListOptions) (watch.Interface, error)
  32. }
  33. // horizontalPodAutoscalers implements HorizontalPodAutoscalersNamespacer interface using AutoscalingClient internally
  34. type horizontalPodAutoscalers struct {
  35. client *AutoscalingClient
  36. ns string
  37. }
  38. // newHorizontalPodAutoscalers returns a horizontalPodAutoscalers
  39. func newHorizontalPodAutoscalers(c *AutoscalingClient, namespace string) *horizontalPodAutoscalers {
  40. return &horizontalPodAutoscalers{
  41. client: c,
  42. ns: namespace,
  43. }
  44. }
  45. // List takes label and field selectors, and returns the list of horizontalPodAutoscalers that match those selectors.
  46. func (c *horizontalPodAutoscalers) List(opts api.ListOptions) (result *autoscaling.HorizontalPodAutoscalerList, err error) {
  47. result = &autoscaling.HorizontalPodAutoscalerList{}
  48. err = c.client.Get().Namespace(c.ns).Resource("horizontalPodAutoscalers").VersionedParams(&opts, api.ParameterCodec).Do().Into(result)
  49. return
  50. }
  51. // Get takes the name of the horizontalPodAutoscaler, and returns the corresponding HorizontalPodAutoscaler object, and an error if it occurs
  52. func (c *horizontalPodAutoscalers) Get(name string) (result *autoscaling.HorizontalPodAutoscaler, err error) {
  53. result = &autoscaling.HorizontalPodAutoscaler{}
  54. err = c.client.Get().Namespace(c.ns).Resource("horizontalPodAutoscalers").Name(name).Do().Into(result)
  55. return
  56. }
  57. // Delete takes the name of the horizontalPodAutoscaler and deletes it. Returns an error if one occurs.
  58. func (c *horizontalPodAutoscalers) Delete(name string, options *api.DeleteOptions) error {
  59. return c.client.Delete().Namespace(c.ns).Resource("horizontalPodAutoscalers").Name(name).Body(options).Do().Error()
  60. }
  61. // Create takes the representation of a horizontalPodAutoscaler and creates it. Returns the server's representation of the horizontalPodAutoscaler, and an error, if it occurs.
  62. func (c *horizontalPodAutoscalers) Create(horizontalPodAutoscaler *autoscaling.HorizontalPodAutoscaler) (result *autoscaling.HorizontalPodAutoscaler, err error) {
  63. result = &autoscaling.HorizontalPodAutoscaler{}
  64. err = c.client.Post().Namespace(c.ns).Resource("horizontalPodAutoscalers").Body(horizontalPodAutoscaler).Do().Into(result)
  65. return
  66. }
  67. // Update takes the representation of a horizontalPodAutoscaler and updates it. Returns the server's representation of the horizontalPodAutoscaler, and an error, if it occurs.
  68. func (c *horizontalPodAutoscalers) Update(horizontalPodAutoscaler *autoscaling.HorizontalPodAutoscaler) (result *autoscaling.HorizontalPodAutoscaler, err error) {
  69. result = &autoscaling.HorizontalPodAutoscaler{}
  70. err = c.client.Put().Namespace(c.ns).Resource("horizontalPodAutoscalers").Name(horizontalPodAutoscaler.Name).Body(horizontalPodAutoscaler).Do().Into(result)
  71. return
  72. }
  73. // UpdateStatus takes the representation of a horizontalPodAutoscaler and updates it. Returns the server's representation of the horizontalPodAutoscaler, and an error, if it occurs.
  74. func (c *horizontalPodAutoscalers) UpdateStatus(horizontalPodAutoscaler *autoscaling.HorizontalPodAutoscaler) (result *autoscaling.HorizontalPodAutoscaler, err error) {
  75. result = &autoscaling.HorizontalPodAutoscaler{}
  76. err = c.client.Put().Namespace(c.ns).Resource("horizontalPodAutoscalers").Name(horizontalPodAutoscaler.Name).SubResource("status").Body(horizontalPodAutoscaler).Do().Into(result)
  77. return
  78. }
  79. // Watch returns a watch.Interface that watches the requested horizontalPodAutoscalers.
  80. func (c *horizontalPodAutoscalers) Watch(opts api.ListOptions) (watch.Interface, error) {
  81. return c.client.Get().
  82. Prefix("watch").
  83. Namespace(c.ns).
  84. Resource("horizontalPodAutoscalers").
  85. VersionedParams(&opts, api.ParameterCodec).
  86. Watch()
  87. }