pod_templates.go 3.5 KB

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