Skip to content

Commit c5a29a8

Browse files
committed
router: simplify detection of initial sync
1 parent aaf8e0a commit c5a29a8

13 files changed

+8
-67
lines changed

pkg/router/controller/controller.go

-6
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,6 @@ func (c *RouterController) handleFirstSync() bool {
7979
return false
8080
}
8181

82-
err := c.Plugin.SetSyncedAtLeastOnce()
83-
if err != nil {
84-
utilruntime.HandleError(err)
85-
return false
86-
}
87-
8882
// If either of the event queues were empty after the initial
8983
// List, the tracking listConsumed variable's default value of
9084
// 'false' may prevent the router from committing the readiness

pkg/router/controller/controller_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ func (p *fakeRouterPlugin) Commit() error {
3232
return nil
3333
}
3434

35-
func (p *fakeRouterPlugin) SetSyncedAtLeastOnce() error {
36-
return nil
37-
}
38-
3935
type fakeNamespaceLister struct {
4036
}
4137

pkg/router/controller/extended_validator.go

-4
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,3 @@ func (p *ExtendedValidator) HandleNamespaces(namespaces sets.String) error {
8282
func (p *ExtendedValidator) Commit() error {
8383
return p.plugin.Commit()
8484
}
85-
86-
func (p *ExtendedValidator) SetSyncedAtLeastOnce() error {
87-
return p.plugin.SetSyncedAtLeastOnce()
88-
}

pkg/router/controller/host_admitter.go

-4
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@ func (p *HostAdmitter) Commit() error {
152152
return p.plugin.Commit()
153153
}
154154

155-
func (p *HostAdmitter) SetSyncedAtLeastOnce() error {
156-
return p.plugin.SetSyncedAtLeastOnce()
157-
}
158-
159155
// addRoute admits routes based on subdomain ownership - returns errors if the route is not admitted.
160156
func (p *HostAdmitter) addRoute(route *routeapi.Route) error {
161157
// Find displaced routes (or error if an existing route displaces us)

pkg/router/controller/status.go

-4
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,3 @@ func (a *StatusAdmitter) HandleNamespaces(namespaces sets.String) error {
315315
func (a *StatusAdmitter) Commit() error {
316316
return a.plugin.Commit()
317317
}
318-
319-
func (a *StatusAdmitter) SetSyncedAtLeastOnce() error {
320-
return a.plugin.SetSyncedAtLeastOnce()
321-
}

pkg/router/controller/status_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ func (p *fakePlugin) Commit() error {
4343
return fmt.Errorf("not expected")
4444
}
4545

46-
func (p *fakePlugin) SetSyncedAtLeastOnce() error {
47-
return fmt.Errorf("not expected")
48-
}
49-
5046
func TestStatusNoOp(t *testing.T) {
5147
now := nowFn()
5248
touched := unversioned.Time{Time: now.Add(-time.Minute)}

pkg/router/controller/unique_host.go

-4
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,6 @@ func (p *UniqueHost) Commit() error {
259259
return p.plugin.Commit()
260260
}
261261

262-
func (p *UniqueHost) SetSyncedAtLeastOnce() error {
263-
return p.plugin.SetSyncedAtLeastOnce()
264-
}
265-
266262
// routeKeys returns the internal router key to use for the given Route.
267263
func routeKeys(route *routeapi.Route) []string {
268264
keys := make([]string, 1+len(route.Spec.AlternateBackends))

pkg/router/f5/plugin.go

-5
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,3 @@ func (p *F5Plugin) HandleRoute(eventType watch.EventType,
633633
func (p *F5Plugin) Commit() error {
634634
return nil
635635
}
636-
637-
// No-op since f5 has its own concept of what 'ready' means
638-
func (p *F5Plugin) SetSyncedAtLeastOnce() error {
639-
return nil
640-
}

pkg/router/interfaces.go

-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ type Plugin interface {
1717
HandleNamespaces(namespaces sets.String) error
1818
HandleNode(watch.EventType, *kapi.Node) error
1919
Commit() error
20-
SetSyncedAtLeastOnce() error
2120
}

pkg/router/template/plugin.go

-8
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ type routerInterface interface {
8383
// Commit applies the changes in the background. It kicks off a rate-limited
8484
// commit (persist router state + refresh the backend) that coalesces multiple changes.
8585
Commit()
86-
87-
// SetSyncedAtLeastOnce indicates to the router that state has been read from the api at least once
88-
SetSyncedAtLeastOnce()
8986
}
9087

9188
func env(name, defaultValue string) string {
@@ -227,11 +224,6 @@ func (p *TemplatePlugin) Commit() error {
227224
return nil
228225
}
229226

230-
func (p *TemplatePlugin) SetSyncedAtLeastOnce() error {
231-
p.Router.SetSyncedAtLeastOnce()
232-
return nil
233-
}
234-
235227
// routeKeys returns the internal router keys to use for the given Route.
236228
// A route can have several services that it can point to, now
237229
func routeKeys(route *routeapi.Route) ([]string, []int32) {

pkg/router/template/plugin_test.go

-3
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,6 @@ func (r *TestRouter) Commit() {
245245
r.Committed = true
246246
}
247247

248-
func (r *TestRouter) SetSyncedAtLeastOnce() {
249-
}
250-
251248
// TestHandleEndpoints test endpoint watch events
252249
func TestHandleEndpoints(t *testing.T) {
253250
testCases := []struct {

pkg/router/template/router.go

+8-13
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ type templateRouter struct {
8787
// If true, haproxy should only bind ports when it has route and endpoint state
8888
bindPortsAfterSync bool
8989
// whether the router state has been read from the api at least once
90-
syncedAtLeastOnce bool
90+
synced bool
9191
// whether a state change has occurred
9292
stateChanged bool
9393
}
@@ -351,6 +351,12 @@ func (r *templateRouter) Commit() {
351351
r.lock.Lock()
352352
defer r.lock.Unlock()
353353

354+
if !r.synced {
355+
glog.V(4).Infof("Router state synchronized for the first time")
356+
r.synced = true
357+
r.stateChanged = true
358+
}
359+
354360
if r.stateChanged {
355361
r.rateLimitedCommitFunction.Invoke(r.rateLimitedCommitFunction)
356362
r.stateChanged = false
@@ -418,7 +424,7 @@ func (r *templateRouter) writeConfig() error {
418424
StatsUser: r.statsUser,
419425
StatsPassword: r.statsPassword,
420426
StatsPort: r.statsPort,
421-
BindPorts: !r.bindPortsAfterSync || r.syncedAtLeastOnce,
427+
BindPorts: !r.bindPortsAfterSync || r.synced,
422428
}
423429
if err := template.Execute(file, data); err != nil {
424430
file.Close()
@@ -745,17 +751,6 @@ func (r *templateRouter) shouldWriteCerts(cfg *ServiceAliasConfig) bool {
745751
return false
746752
}
747753

748-
// SetSyncedAtLeastOnce indicates to the router that state has been
749-
// read from the api.
750-
func (r *templateRouter) SetSyncedAtLeastOnce() {
751-
r.lock.Lock()
752-
defer r.lock.Unlock()
753-
754-
glog.V(4).Infof("Router state synchronized for the first time")
755-
r.syncedAtLeastOnce = true
756-
r.stateChanged = true
757-
}
758-
759754
// HasRoute indicates whether the given route is known to this router.
760755
func (r *templateRouter) HasRoute(route *routeapi.Route) bool {
761756
r.lock.Lock()

test/integration/router_stress_test.go

-7
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,6 @@ func (p *DelayPlugin) Commit() error {
288288
return p.plugin.Commit()
289289
}
290290

291-
func (p *DelayPlugin) SetSyncedAtLeastOnce() error {
292-
if p.committed {
293-
return nil
294-
}
295-
return p.plugin.SetSyncedAtLeastOnce()
296-
}
297-
298291
// launchRouter launches a template router that communicates with the
299292
// api via the provided clients.
300293
func launchRouter(oc osclient.Interface, kc kclientset.Interface, maxDelay int32, name string, reloadInterval int, reloadedMap map[string]bool) (templatePlugin *templateplugin.TemplatePlugin) {

0 commit comments

Comments
 (0)