Skip to content

Commit 7c42b7e

Browse files
change the router eventqueue key function
changing the router eventqueue key function so that there is a higher chance that each item will have a unique key so the router does not panic. originally the thought was to add the creation timestamp because it was not user editable but the accessor function meta.CreationTimestamp() only gives the timestamp to the second and since these actions need to occur quickly a second is too long. Only adding creation timestamp I was able to observe the panic with the test script. I decided to use UID because it is much more likely that the UID is unique. Bug: 1429823
1 parent 1e2d71b commit 7c42b7e

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

pkg/router/controller/factory/factory.go

+21-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
routeapi "github.com/openshift/origin/pkg/route/api"
2323
"github.com/openshift/origin/pkg/router"
2424
"github.com/openshift/origin/pkg/router/controller"
25+
"k8s.io/kubernetes/pkg/api/meta"
2526
)
2627

2728
// RouterControllerFactory initializes and manages the watches that drive a router
@@ -56,25 +57,39 @@ func NewDefaultRouterControllerFactory(oc osclient.RoutesNamespacer, kc kclients
5657
}
5758
}
5859

60+
func routerKeyFn(obj interface{}) (string, error) {
61+
if key, ok := obj.(cache.ExplicitKey); ok {
62+
return string(key), nil
63+
}
64+
meta, err := meta.Accessor(obj)
65+
if err != nil {
66+
return "", fmt.Errorf("object has no meta: %v", err)
67+
}
68+
if len(meta.GetNamespace()) > 0 {
69+
return meta.GetNamespace() + "/" + meta.GetName() + "/" + string(meta.GetUID()), nil
70+
}
71+
return meta.GetName() + "/" + string(meta.GetUID()), nil
72+
}
73+
5974
// Create begins listing and watching against the API server for the desired route and endpoint
6075
// resources. It spawns child goroutines that cannot be terminated.
6176
func (factory *RouterControllerFactory) Create(plugin router.Plugin, watchNodes, enableIngress bool) *controller.RouterController {
62-
routeEventQueue := oscache.NewEventQueue(cache.MetaNamespaceKeyFunc)
77+
routeEventQueue := oscache.NewEventQueue(routerKeyFn)
6378
cache.NewReflector(&routeLW{
6479
client: factory.OSClient,
6580
namespace: factory.Namespace,
6681
field: factory.Fields,
6782
label: factory.Labels,
6883
}, &routeapi.Route{}, routeEventQueue, factory.ResyncInterval).Run()
6984

70-
endpointsEventQueue := oscache.NewEventQueue(cache.MetaNamespaceKeyFunc)
85+
endpointsEventQueue := oscache.NewEventQueue(routerKeyFn)
7186
cache.NewReflector(&endpointsLW{
7287
client: factory.KClient,
7388
namespace: factory.Namespace,
7489
// we do not scope endpoints by labels or fields because the route labels != endpoints labels
7590
}, &kapi.Endpoints{}, endpointsEventQueue, factory.ResyncInterval).Run()
7691

77-
nodeEventQueue := oscache.NewEventQueue(cache.MetaNamespaceKeyFunc)
92+
nodeEventQueue := oscache.NewEventQueue(routerKeyFn)
7893
if watchNodes {
7994
cache.NewReflector(&nodeLW{
8095
client: factory.NodeClient,
@@ -83,8 +98,8 @@ func (factory *RouterControllerFactory) Create(plugin router.Plugin, watchNodes,
8398
}, &kapi.Node{}, nodeEventQueue, factory.ResyncInterval).Run()
8499
}
85100

86-
ingressEventQueue := oscache.NewEventQueue(cache.MetaNamespaceKeyFunc)
87-
secretEventQueue := oscache.NewEventQueue(cache.MetaNamespaceKeyFunc)
101+
ingressEventQueue := oscache.NewEventQueue(routerKeyFn)
102+
secretEventQueue := oscache.NewEventQueue(routerKeyFn)
88103
var ingressTranslator *controller.IngressTranslator
89104
if enableIngress {
90105
ingressTranslator = controller.NewIngressTranslator(factory.SecretClient)
@@ -195,7 +210,7 @@ func (factory *RouterControllerFactory) Create(plugin router.Plugin, watchNodes,
195210
// resources. It spawns child goroutines that cannot be terminated. It is a more efficient store of a
196211
// route system.
197212
func (factory *RouterControllerFactory) CreateNotifier(changed func()) RoutesByHost {
198-
keyFn := cache.MetaNamespaceKeyFunc
213+
keyFn := routerKeyFn
199214
routeStore := cache.NewIndexer(keyFn, cache.Indexers{"host": hostIndexFunc})
200215
routeEventQueue := oscache.NewEventQueueForStore(keyFn, routeStore)
201216
cache.NewReflector(&routeLW{

0 commit comments

Comments
 (0)