github.com/timstclair/heapster@v0.20.0-alpha1/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/namespaces.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 type NamespacesInterface interface { 29 Namespaces() NamespaceInterface 30 } 31 32 type NamespaceInterface interface { 33 Create(item *api.Namespace) (*api.Namespace, error) 34 Get(name string) (result *api.Namespace, err error) 35 List(label labels.Selector, field fields.Selector) (*api.NamespaceList, error) 36 Delete(name string) error 37 Update(item *api.Namespace) (*api.Namespace, error) 38 Watch(label labels.Selector, field fields.Selector, opts api.ListOptions) (watch.Interface, error) 39 Finalize(item *api.Namespace) (*api.Namespace, error) 40 Status(item *api.Namespace) (*api.Namespace, error) 41 } 42 43 // namespaces implements NamespacesInterface 44 type namespaces struct { 45 r *Client 46 } 47 48 // newNamespaces returns a namespaces object. 49 func newNamespaces(c *Client) *namespaces { 50 return &namespaces{r: c} 51 } 52 53 // Create creates a new namespace. 54 func (c *namespaces) Create(namespace *api.Namespace) (*api.Namespace, error) { 55 result := &api.Namespace{} 56 err := c.r.Post().Resource("namespaces").Body(namespace).Do().Into(result) 57 return result, err 58 } 59 60 // List lists all the namespaces in the cluster. 61 func (c *namespaces) List(label labels.Selector, field fields.Selector) (*api.NamespaceList, error) { 62 result := &api.NamespaceList{} 63 err := c.r.Get(). 64 Resource("namespaces"). 65 LabelsSelectorParam(label). 66 FieldsSelectorParam(field). 67 Do().Into(result) 68 return result, err 69 } 70 71 // Update takes the representation of a namespace to update. Returns the server's representation of the namespace, and an error, if it occurs. 72 func (c *namespaces) Update(namespace *api.Namespace) (result *api.Namespace, err error) { 73 result = &api.Namespace{} 74 if len(namespace.ResourceVersion) == 0 { 75 err = fmt.Errorf("invalid update object, missing resource version: %v", namespace) 76 return 77 } 78 err = c.r.Put().Resource("namespaces").Name(namespace.Name).Body(namespace).Do().Into(result) 79 return 80 } 81 82 // Finalize takes the representation of a namespace to update. Returns the server's representation of the namespace, and an error, if it occurs. 83 func (c *namespaces) Finalize(namespace *api.Namespace) (result *api.Namespace, err error) { 84 result = &api.Namespace{} 85 if len(namespace.ResourceVersion) == 0 { 86 err = fmt.Errorf("invalid update object, missing resource version: %v", namespace) 87 return 88 } 89 err = c.r.Put().Resource("namespaces").Name(namespace.Name).SubResource("finalize").Body(namespace).Do().Into(result) 90 return 91 } 92 93 // Status takes the representation of a namespace to update. Returns the server's representation of the namespace, and an error, if it occurs. 94 func (c *namespaces) Status(namespace *api.Namespace) (result *api.Namespace, err error) { 95 result = &api.Namespace{} 96 if len(namespace.ResourceVersion) == 0 { 97 err = fmt.Errorf("invalid update object, missing resource version: %v", namespace) 98 return 99 } 100 err = c.r.Put().Resource("namespaces").Name(namespace.Name).SubResource("status").Body(namespace).Do().Into(result) 101 return 102 } 103 104 // Get gets an existing namespace 105 func (c *namespaces) Get(name string) (*api.Namespace, error) { 106 result := &api.Namespace{} 107 err := c.r.Get().Resource("namespaces").Name(name).Do().Into(result) 108 return result, err 109 } 110 111 // Delete deletes an existing namespace. 112 func (c *namespaces) Delete(name string) error { 113 return c.r.Delete().Resource("namespaces").Name(name).Do().Error() 114 } 115 116 // Watch returns a watch.Interface that watches the requested namespaces. 117 func (c *namespaces) Watch(label labels.Selector, field fields.Selector, opts api.ListOptions) (watch.Interface, error) { 118 return c.r.Get(). 119 Prefix("watch"). 120 Resource("namespaces"). 121 VersionedParams(&opts, api.Scheme). 122 LabelsSelectorParam(label). 123 FieldsSelectorParam(field). 124 Watch() 125 }