endpoints.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. // EndpointsNamespacer has methods to work with Endpoints resources in a namespace
  19. type EndpointsNamespacer interface {
  20. Endpoints(namespace string) EndpointsInterface
  21. }
  22. // EndpointsInterface has methods to work with Endpoints resources
  23. type EndpointsInterface interface {
  24. Create(endpoints *api.Endpoints) (*api.Endpoints, error)
  25. List(opts api.ListOptions) (*api.EndpointsList, error)
  26. Get(name string) (*api.Endpoints, error)
  27. Delete(name string) error
  28. Update(endpoints *api.Endpoints) (*api.Endpoints, error)
  29. Watch(opts api.ListOptions) (watch.Interface, error)
  30. }
  31. // endpoints implements EndpointsInterface
  32. type endpoints struct {
  33. r *Client
  34. ns string
  35. }
  36. // newEndpoints returns a endpoints
  37. func newEndpoints(c *Client, namespace string) *endpoints {
  38. return &endpoints{c, namespace}
  39. }
  40. // Create creates a new endpoint.
  41. func (c *endpoints) Create(endpoints *api.Endpoints) (*api.Endpoints, error) {
  42. result := &api.Endpoints{}
  43. err := c.r.Post().Namespace(c.ns).Resource("endpoints").Body(endpoints).Do().Into(result)
  44. return result, err
  45. }
  46. // List takes a selector, and returns the list of endpoints that match that selector
  47. func (c *endpoints) List(opts api.ListOptions) (result *api.EndpointsList, err error) {
  48. result = &api.EndpointsList{}
  49. err = c.r.Get().
  50. Namespace(c.ns).
  51. Resource("endpoints").
  52. VersionedParams(&opts, api.ParameterCodec).
  53. Do().
  54. Into(result)
  55. return
  56. }
  57. // Get returns information about the endpoints for a particular service.
  58. func (c *endpoints) Get(name string) (result *api.Endpoints, err error) {
  59. result = &api.Endpoints{}
  60. err = c.r.Get().Namespace(c.ns).Resource("endpoints").Name(name).Do().Into(result)
  61. return
  62. }
  63. // Delete takes the name of the endpoint, and returns an error if one occurs
  64. func (c *endpoints) Delete(name string) error {
  65. return c.r.Delete().Namespace(c.ns).Resource("endpoints").Name(name).Do().Error()
  66. }
  67. // Watch returns a watch.Interface that watches the requested endpoints for a service.
  68. func (c *endpoints) Watch(opts api.ListOptions) (watch.Interface, error) {
  69. return c.r.Get().
  70. Prefix("watch").
  71. Namespace(c.ns).
  72. Resource("endpoints").
  73. VersionedParams(&opts, api.ParameterCodec).
  74. Watch()
  75. }
  76. func (c *endpoints) Update(endpoints *api.Endpoints) (*api.Endpoints, error) {
  77. result := &api.Endpoints{}
  78. err := c.r.Put().
  79. Namespace(c.ns).
  80. Resource("endpoints").
  81. Name(endpoints.Name).
  82. Body(endpoints).
  83. Do().
  84. Into(result)
  85. return result, err
  86. }