@@ -22,6 +22,7 @@ import (
22
22
routeapi "github.com/openshift/origin/pkg/route/api"
23
23
"github.com/openshift/origin/pkg/router"
24
24
"github.com/openshift/origin/pkg/router/controller"
25
+ "k8s.io/kubernetes/pkg/api/meta"
25
26
)
26
27
27
28
// RouterControllerFactory initializes and manages the watches that drive a router
@@ -56,25 +57,42 @@ func NewDefaultRouterControllerFactory(oc osclient.RoutesNamespacer, kc kclients
56
57
}
57
58
}
58
59
60
+ // routerKeyFn comes from MetaNamespaceKeyFunc in vendor/k8s.io/kubernetes/pkg/client/cache/store.go.
61
+ // It was modified and added here because there is no way to know if an ExplicitKey was passed before
62
+ // adding the UID to prevent an invalid state transistion if deletions and adds happen quickly.
63
+ func routerKeyFn (obj interface {}) (string , error ) {
64
+ if key , ok := obj .(cache.ExplicitKey ); ok {
65
+ return string (key ), nil
66
+ }
67
+ meta , err := meta .Accessor (obj )
68
+ if err != nil {
69
+ return "" , fmt .Errorf ("object has no meta: %v" , err )
70
+ }
71
+ if len (meta .GetNamespace ()) > 0 {
72
+ return meta .GetNamespace () + "/" + meta .GetName () + "/" + string (meta .GetUID ()), nil
73
+ }
74
+ return meta .GetName () + "/" + string (meta .GetUID ()), nil
75
+ }
76
+
59
77
// Create begins listing and watching against the API server for the desired route and endpoint
60
78
// resources. It spawns child goroutines that cannot be terminated.
61
79
func (factory * RouterControllerFactory ) Create (plugin router.Plugin , watchNodes , enableIngress bool ) * controller.RouterController {
62
- routeEventQueue := oscache .NewEventQueue (cache . MetaNamespaceKeyFunc )
80
+ routeEventQueue := oscache .NewEventQueue (routerKeyFn )
63
81
cache .NewReflector (& routeLW {
64
82
client : factory .OSClient ,
65
83
namespace : factory .Namespace ,
66
84
field : factory .Fields ,
67
85
label : factory .Labels ,
68
86
}, & routeapi.Route {}, routeEventQueue , factory .ResyncInterval ).Run ()
69
87
70
- endpointsEventQueue := oscache .NewEventQueue (cache . MetaNamespaceKeyFunc )
88
+ endpointsEventQueue := oscache .NewEventQueue (routerKeyFn )
71
89
cache .NewReflector (& endpointsLW {
72
90
client : factory .KClient ,
73
91
namespace : factory .Namespace ,
74
92
// we do not scope endpoints by labels or fields because the route labels != endpoints labels
75
93
}, & kapi.Endpoints {}, endpointsEventQueue , factory .ResyncInterval ).Run ()
76
94
77
- nodeEventQueue := oscache .NewEventQueue (cache . MetaNamespaceKeyFunc )
95
+ nodeEventQueue := oscache .NewEventQueue (routerKeyFn )
78
96
if watchNodes {
79
97
cache .NewReflector (& nodeLW {
80
98
client : factory .NodeClient ,
@@ -83,8 +101,8 @@ func (factory *RouterControllerFactory) Create(plugin router.Plugin, watchNodes,
83
101
}, & kapi.Node {}, nodeEventQueue , factory .ResyncInterval ).Run ()
84
102
}
85
103
86
- ingressEventQueue := oscache .NewEventQueue (cache . MetaNamespaceKeyFunc )
87
- secretEventQueue := oscache .NewEventQueue (cache . MetaNamespaceKeyFunc )
104
+ ingressEventQueue := oscache .NewEventQueue (routerKeyFn )
105
+ secretEventQueue := oscache .NewEventQueue (routerKeyFn )
88
106
var ingressTranslator * controller.IngressTranslator
89
107
if enableIngress {
90
108
ingressTranslator = controller .NewIngressTranslator (factory .SecretClient )
@@ -195,7 +213,7 @@ func (factory *RouterControllerFactory) Create(plugin router.Plugin, watchNodes,
195
213
// resources. It spawns child goroutines that cannot be terminated. It is a more efficient store of a
196
214
// route system.
197
215
func (factory * RouterControllerFactory ) CreateNotifier (changed func ()) RoutesByHost {
198
- keyFn := cache . MetaNamespaceKeyFunc
216
+ keyFn := routerKeyFn
199
217
routeStore := cache .NewIndexer (keyFn , cache.Indexers {"host" : hostIndexFunc })
200
218
routeEventQueue := oscache .NewEventQueueForStore (keyFn , routeStore )
201
219
cache .NewReflector (& routeLW {
0 commit comments