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