Skip to content

Commit 37777d2

Browse files
author
OpenShift Bot
authored
Merge pull request #13494 from JacobTanenbaum/BZ1429823
Merged by openshift-bot
2 parents ac3b692 + fd723fd commit 37777d2

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

pkg/router/controller/factory/factory.go

+24-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,42 @@ func NewDefaultRouterControllerFactory(oc osclient.RoutesNamespacer, kc kclients
5657
}
5758
}
5859

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+
5977
// Create begins listing and watching against the API server for the desired route and endpoint
6078
// resources. It spawns child goroutines that cannot be terminated.
6179
func (factory *RouterControllerFactory) Create(plugin router.Plugin, watchNodes, enableIngress bool) *controller.RouterController {
62-
routeEventQueue := oscache.NewEventQueue(cache.MetaNamespaceKeyFunc)
80+
routeEventQueue := oscache.NewEventQueue(routerKeyFn)
6381
cache.NewReflector(&routeLW{
6482
client: factory.OSClient,
6583
namespace: factory.Namespace,
6684
field: factory.Fields,
6785
label: factory.Labels,
6886
}, &routeapi.Route{}, routeEventQueue, factory.ResyncInterval).Run()
6987

70-
endpointsEventQueue := oscache.NewEventQueue(cache.MetaNamespaceKeyFunc)
88+
endpointsEventQueue := oscache.NewEventQueue(routerKeyFn)
7189
cache.NewReflector(&endpointsLW{
7290
client: factory.KClient,
7391
namespace: factory.Namespace,
7492
// we do not scope endpoints by labels or fields because the route labels != endpoints labels
7593
}, &kapi.Endpoints{}, endpointsEventQueue, factory.ResyncInterval).Run()
7694

77-
nodeEventQueue := oscache.NewEventQueue(cache.MetaNamespaceKeyFunc)
95+
nodeEventQueue := oscache.NewEventQueue(routerKeyFn)
7896
if watchNodes {
7997
cache.NewReflector(&nodeLW{
8098
client: factory.NodeClient,
@@ -83,8 +101,8 @@ func (factory *RouterControllerFactory) Create(plugin router.Plugin, watchNodes,
83101
}, &kapi.Node{}, nodeEventQueue, factory.ResyncInterval).Run()
84102
}
85103

86-
ingressEventQueue := oscache.NewEventQueue(cache.MetaNamespaceKeyFunc)
87-
secretEventQueue := oscache.NewEventQueue(cache.MetaNamespaceKeyFunc)
104+
ingressEventQueue := oscache.NewEventQueue(routerKeyFn)
105+
secretEventQueue := oscache.NewEventQueue(routerKeyFn)
88106
var ingressTranslator *controller.IngressTranslator
89107
if enableIngress {
90108
ingressTranslator = controller.NewIngressTranslator(factory.SecretClient)
@@ -195,7 +213,7 @@ func (factory *RouterControllerFactory) Create(plugin router.Plugin, watchNodes,
195213
// resources. It spawns child goroutines that cannot be terminated. It is a more efficient store of a
196214
// route system.
197215
func (factory *RouterControllerFactory) CreateNotifier(changed func()) RoutesByHost {
198-
keyFn := cache.MetaNamespaceKeyFunc
216+
keyFn := routerKeyFn
199217
routeStore := cache.NewIndexer(keyFn, cache.Indexers{"host": hostIndexFunc})
200218
routeEventQueue := oscache.NewEventQueueForStore(keyFn, routeStore)
201219
cache.NewReflector(&routeLW{

0 commit comments

Comments
 (0)