forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
route.go
91 lines (80 loc) · 2.28 KB
/
route.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
90
91
package test
import (
"errors"
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"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"
)
// RouteRegistry provides an in-memory implementation of
// the route.Registry interface.
type RouteRegistry struct {
Routes *routeapi.RouteList
}
// NewRouteRegistry creates a new RouteRegistry.
func NewRouteRegistry() *RouteRegistry {
return &RouteRegistry{}
}
func (r *RouteRegistry) ListRoutes(ctx kapi.Context, labels labels.Selector) (*routeapi.RouteList, error) {
return r.Routes, nil
}
func (r *RouteRegistry) GetRoute(ctx kapi.Context, id string) (*routeapi.Route, error) {
if r.Routes != nil {
for _, route := range r.Routes.Items {
if route.Name == id {
return &route, nil
}
}
}
return nil, errors.New("Route " + id + " not found")
}
func (r *RouteRegistry) CreateRoute(ctx kapi.Context, route *routeapi.Route) error {
if r.Routes == nil {
r.Routes = &routeapi.RouteList{}
}
newList := []routeapi.Route{}
for _, curRoute := range r.Routes.Items {
newList = append(newList, curRoute)
}
newList = append(newList, *route)
r.Routes.Items = newList
return nil
}
func (r *RouteRegistry) UpdateRoute(ctx kapi.Context, route *routeapi.Route) error {
if r.Routes == nil {
r.Routes = &routeapi.RouteList{}
}
newList := []routeapi.Route{}
found := false
for _, curRoute := range r.Routes.Items {
if curRoute.Name == route.Name {
// route to be updated exists
found = true
} else {
newList = append(newList, curRoute)
}
}
if !found {
return errors.New("Route " + route.Name + " not found")
}
newList = append(newList, *route)
r.Routes.Items = newList
return nil
}
func (r *RouteRegistry) DeleteRoute(ctx kapi.Context, id string) error {
if r.Routes == nil {
r.Routes = &routeapi.RouteList{}
}
newList := []routeapi.Route{}
for _, curRoute := range r.Routes.Items {
if curRoute.Name != id {
newList = append(newList, curRoute)
}
}
r.Routes.Items = newList
return nil
}
func (r *RouteRegistry) WatchRoutes(ctx kapi.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
return nil, nil
}