limit_ranges.go 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. // LimitRangesNamespacer has methods to work with LimitRange resources in a namespace
  19. type LimitRangesNamespacer interface {
  20. LimitRanges(namespace string) LimitRangeInterface
  21. }
  22. // LimitRangeInterface has methods to work with LimitRange resources.
  23. type LimitRangeInterface interface {
  24. List(opts api.ListOptions) (*api.LimitRangeList, error)
  25. Get(name string) (*api.LimitRange, error)
  26. Delete(name string) error
  27. Create(limitRange *api.LimitRange) (*api.LimitRange, error)
  28. Update(limitRange *api.LimitRange) (*api.LimitRange, error)
  29. Watch(opts api.ListOptions) (watch.Interface, error)
  30. }
  31. // limitRanges implements LimitRangesNamespacer interface
  32. type limitRanges struct {
  33. r *Client
  34. ns string
  35. }
  36. // newLimitRanges returns a limitRanges
  37. func newLimitRanges(c *Client, namespace string) *limitRanges {
  38. return &limitRanges{
  39. r: c,
  40. ns: namespace,
  41. }
  42. }
  43. // List takes a selector, and returns the list of limitRanges that match that selector.
  44. func (c *limitRanges) List(opts api.ListOptions) (result *api.LimitRangeList, err error) {
  45. result = &api.LimitRangeList{}
  46. err = c.r.Get().Namespace(c.ns).Resource("limitRanges").VersionedParams(&opts, api.ParameterCodec).Do().Into(result)
  47. return
  48. }
  49. // Get takes the name of the limitRange, and returns the corresponding Pod object, and an error if it occurs
  50. func (c *limitRanges) Get(name string) (result *api.LimitRange, err error) {
  51. result = &api.LimitRange{}
  52. err = c.r.Get().Namespace(c.ns).Resource("limitRanges").Name(name).Do().Into(result)
  53. return
  54. }
  55. // Delete takes the name of the limitRange, and returns an error if one occurs
  56. func (c *limitRanges) Delete(name string) error {
  57. return c.r.Delete().Namespace(c.ns).Resource("limitRanges").Name(name).Do().Error()
  58. }
  59. // Create takes the representation of a limitRange. Returns the server's representation of the limitRange, and an error, if it occurs.
  60. func (c *limitRanges) Create(limitRange *api.LimitRange) (result *api.LimitRange, err error) {
  61. result = &api.LimitRange{}
  62. err = c.r.Post().Namespace(c.ns).Resource("limitRanges").Body(limitRange).Do().Into(result)
  63. return
  64. }
  65. // Update takes the representation of a limitRange to update. Returns the server's representation of the limitRange, and an error, if it occurs.
  66. func (c *limitRanges) Update(limitRange *api.LimitRange) (result *api.LimitRange, err error) {
  67. result = &api.LimitRange{}
  68. err = c.r.Put().Namespace(c.ns).Resource("limitRanges").Name(limitRange.Name).Body(limitRange).Do().Into(result)
  69. return
  70. }
  71. // Watch returns a watch.Interface that watches the requested resource
  72. func (c *limitRanges) Watch(opts api.ListOptions) (watch.Interface, error) {
  73. return c.r.Get().
  74. Prefix("watch").
  75. Namespace(c.ns).
  76. Resource("limitRanges").
  77. VersionedParams(&opts, api.ParameterCodec).
  78. Watch()
  79. }