forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.go
89 lines (77 loc) · 2.98 KB
/
routes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package client
import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
routeapi "github.com/openshift/origin/pkg/route/api"
)
// RoutesNamespacer has methods to work with Route resources in a namespace
type RoutesNamespacer interface {
Routes(namespace string) RouteInterface
}
// RouteInterface exposes methods on Route resources
type RouteInterface interface {
List(label labels.Selector, field fields.Selector) (*routeapi.RouteList, error)
Get(name string) (*routeapi.Route, error)
Create(route *routeapi.Route) (*routeapi.Route, error)
Update(route *routeapi.Route) (*routeapi.Route, error)
Delete(name string) error
Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error)
}
// routes implements RouteInterface interface
type routes struct {
r *Client
ns string
}
// newRoutes returns a routes
func newRoutes(c *Client, namespace string) *routes {
return &routes{
r: c,
ns: namespace,
}
}
// List takes a label and field selector, and returns the list of routes that match that selectors
func (c *routes) List(label labels.Selector, field fields.Selector) (result *routeapi.RouteList, err error) {
result = &routeapi.RouteList{}
err = c.r.Get().
Namespace(c.ns).
Resource("routes").
LabelsSelectorParam(label).
FieldsSelectorParam(field).
Do().
Into(result)
return
}
// Get takes the name of the route, and returns the corresponding Route object, and an error if it occurs
func (c *routes) Get(name string) (result *routeapi.Route, err error) {
result = &routeapi.Route{}
err = c.r.Get().Namespace(c.ns).Resource("routes").Name(name).Do().Into(result)
return
}
// Delete takes the name of the route, and returns an error if one occurs
func (c *routes) Delete(name string) error {
return c.r.Delete().Namespace(c.ns).Resource("routes").Name(name).Do().Error()
}
// Create takes the representation of a route. Returns the server's representation of the route, and an error, if it occurs
func (c *routes) Create(route *routeapi.Route) (result *routeapi.Route, err error) {
result = &routeapi.Route{}
err = c.r.Post().Namespace(c.ns).Resource("routes").Body(route).Do().Into(result)
return
}
// Update takes the representation of a route to update. Returns the server's representation of the route, and an error, if it occurs
func (c *routes) Update(route *routeapi.Route) (result *routeapi.Route, err error) {
result = &routeapi.Route{}
err = c.r.Put().Namespace(c.ns).Resource("routes").Name(route.Name).Body(route).Do().Into(result)
return
}
// Watch returns a watch.Interface that watches the requested routes.
func (c *routes) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
return c.r.Get().
Prefix("watch").
Namespace(c.ns).
Resource("routes").
Param("resourceVersion", resourceVersion).
LabelsSelectorParam(label).
FieldsSelectorParam(field).
Watch()
}