github.com/timstclair/heapster@v0.20.0-alpha1/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/endpoints.go (about) 1 /* 2 Copyright 2014 The Kubernetes Authors All rights reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package unversioned 18 19 import ( 20 "fmt" 21 22 "k8s.io/kubernetes/pkg/api" 23 "k8s.io/kubernetes/pkg/fields" 24 "k8s.io/kubernetes/pkg/labels" 25 "k8s.io/kubernetes/pkg/watch" 26 ) 27 28 // EndpointsNamespacer has methods to work with Endpoints resources in a namespace 29 type EndpointsNamespacer interface { 30 Endpoints(namespace string) EndpointsInterface 31 } 32 33 // EndpointsInterface has methods to work with Endpoints resources 34 type EndpointsInterface interface { 35 Create(endpoints *api.Endpoints) (*api.Endpoints, error) 36 List(label labels.Selector, field fields.Selector) (*api.EndpointsList, error) 37 Get(name string) (*api.Endpoints, error) 38 Delete(name string) error 39 Update(endpoints *api.Endpoints) (*api.Endpoints, error) 40 Watch(label labels.Selector, field fields.Selector, opts api.ListOptions) (watch.Interface, error) 41 } 42 43 // endpoints implements EndpointsInterface 44 type endpoints struct { 45 r *Client 46 ns string 47 } 48 49 // newEndpoints returns a endpoints 50 func newEndpoints(c *Client, namespace string) *endpoints { 51 return &endpoints{c, namespace} 52 } 53 54 // Create creates a new endpoint. 55 func (c *endpoints) Create(endpoints *api.Endpoints) (*api.Endpoints, error) { 56 result := &api.Endpoints{} 57 err := c.r.Post().Namespace(c.ns).Resource("endpoints").Body(endpoints).Do().Into(result) 58 return result, err 59 } 60 61 // List takes a selector, and returns the list of endpoints that match that selector 62 func (c *endpoints) List(label labels.Selector, field fields.Selector) (result *api.EndpointsList, err error) { 63 result = &api.EndpointsList{} 64 err = c.r.Get(). 65 Namespace(c.ns). 66 Resource("endpoints"). 67 LabelsSelectorParam(label). 68 FieldsSelectorParam(field). 69 Do(). 70 Into(result) 71 return 72 } 73 74 // Get returns information about the endpoints for a particular service. 75 func (c *endpoints) Get(name string) (result *api.Endpoints, err error) { 76 result = &api.Endpoints{} 77 err = c.r.Get().Namespace(c.ns).Resource("endpoints").Name(name).Do().Into(result) 78 return 79 } 80 81 // Delete takes the name of the endpoint, and returns an error if one occurs 82 func (c *endpoints) Delete(name string) error { 83 return c.r.Delete().Namespace(c.ns).Resource("endpoints").Name(name).Do().Error() 84 } 85 86 // Watch returns a watch.Interface that watches the requested endpoints for a service. 87 func (c *endpoints) Watch(label labels.Selector, field fields.Selector, opts api.ListOptions) (watch.Interface, error) { 88 return c.r.Get(). 89 Prefix("watch"). 90 Namespace(c.ns). 91 Resource("endpoints"). 92 VersionedParams(&opts, api.Scheme). 93 LabelsSelectorParam(label). 94 FieldsSelectorParam(field). 95 Watch() 96 } 97 98 func (c *endpoints) Update(endpoints *api.Endpoints) (*api.Endpoints, error) { 99 result := &api.Endpoints{} 100 if len(endpoints.ResourceVersion) == 0 { 101 return nil, fmt.Errorf("invalid update object, missing resource version: %v", endpoints) 102 } 103 err := c.r.Put(). 104 Namespace(c.ns). 105 Resource("endpoints"). 106 Name(endpoints.Name). 107 Body(endpoints). 108 Do(). 109 Into(result) 110 return result, err 111 }