resource_quotas.go 4.1 KB

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