github.com/timstclair/heapster@v0.20.0-alpha1/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/ingress.go (about) 1 /* 2 Copyright 2015 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 "k8s.io/kubernetes/pkg/api" 21 "k8s.io/kubernetes/pkg/apis/extensions" 22 "k8s.io/kubernetes/pkg/fields" 23 "k8s.io/kubernetes/pkg/labels" 24 "k8s.io/kubernetes/pkg/watch" 25 ) 26 27 // IngressNamespacer has methods to work with Ingress resources in a namespace 28 type IngressNamespacer interface { 29 Ingress(namespace string) IngressInterface 30 } 31 32 // IngressInterface exposes methods to work on Ingress resources. 33 type IngressInterface interface { 34 List(label labels.Selector, field fields.Selector) (*extensions.IngressList, error) 35 Get(name string) (*extensions.Ingress, error) 36 Create(ingress *extensions.Ingress) (*extensions.Ingress, error) 37 Update(ingress *extensions.Ingress) (*extensions.Ingress, error) 38 Delete(name string, options *api.DeleteOptions) error 39 Watch(label labels.Selector, field fields.Selector, opts api.ListOptions) (watch.Interface, error) 40 UpdateStatus(ingress *extensions.Ingress) (*extensions.Ingress, error) 41 } 42 43 // ingress implements IngressNamespacer interface 44 type ingress struct { 45 r *ExtensionsClient 46 ns string 47 } 48 49 // newIngress returns a ingress 50 func newIngress(c *ExtensionsClient, namespace string) *ingress { 51 return &ingress{c, namespace} 52 } 53 54 // List returns a list of ingress that match the label and field selectors. 55 func (c *ingress) List(label labels.Selector, field fields.Selector) (result *extensions.IngressList, err error) { 56 result = &extensions.IngressList{} 57 err = c.r.Get().Namespace(c.ns).Resource("ingresses").LabelsSelectorParam(label).FieldsSelectorParam(field).Do().Into(result) 58 return 59 } 60 61 // Get returns information about a particular ingress. 62 func (c *ingress) Get(name string) (result *extensions.Ingress, err error) { 63 result = &extensions.Ingress{} 64 err = c.r.Get().Namespace(c.ns).Resource("ingresses").Name(name).Do().Into(result) 65 return 66 } 67 68 // Create creates a new ingress. 69 func (c *ingress) Create(ingress *extensions.Ingress) (result *extensions.Ingress, err error) { 70 result = &extensions.Ingress{} 71 err = c.r.Post().Namespace(c.ns).Resource("ingresses").Body(ingress).Do().Into(result) 72 return 73 } 74 75 // Update updates an existing ingress. 76 func (c *ingress) Update(ingress *extensions.Ingress) (result *extensions.Ingress, err error) { 77 result = &extensions.Ingress{} 78 err = c.r.Put().Namespace(c.ns).Resource("ingresses").Name(ingress.Name).Body(ingress).Do().Into(result) 79 return 80 } 81 82 // Delete deletes a ingress, returns error if one occurs. 83 func (c *ingress) Delete(name string, options *api.DeleteOptions) (err error) { 84 if options == nil { 85 return c.r.Delete().Namespace(c.ns).Resource("ingresses").Name(name).Do().Error() 86 } 87 88 body, err := api.Scheme.EncodeToVersion(options, c.r.APIVersion()) 89 if err != nil { 90 return err 91 } 92 return c.r.Delete().Namespace(c.ns).Resource("ingresses").Name(name).Body(body).Do().Error() 93 } 94 95 // Watch returns a watch.Interface that watches the requested ingress. 96 func (c *ingress) Watch(label labels.Selector, field fields.Selector, opts api.ListOptions) (watch.Interface, error) { 97 return c.r.Get(). 98 Prefix("watch"). 99 Namespace(c.ns). 100 Resource("ingresses"). 101 Param("resourceVersion", opts.ResourceVersion). 102 TimeoutSeconds(TimeoutFromListOptions(opts)). 103 LabelsSelectorParam(label). 104 FieldsSelectorParam(field). 105 Watch() 106 } 107 108 // UpdateStatus takes the name of the ingress and the new status. Returns the server's representation of the ingress, and an error, if it occurs. 109 func (c *ingress) UpdateStatus(ingress *extensions.Ingress) (result *extensions.Ingress, err error) { 110 result = &extensions.Ingress{} 111 err = c.r.Put().Namespace(c.ns).Resource("ingresses").Name(ingress.Name).SubResource("status").Body(ingress).Do().Into(result) 112 return 113 }