diff --git a/internal/controller/istio/controller.go b/internal/controller/istio/controller.go index 69b988cb..66490139 100644 --- a/internal/controller/istio/controller.go +++ b/internal/controller/istio/controller.go @@ -84,10 +84,6 @@ func (c *Controller) Run(stop <-chan struct{}) { go c.configCache.Run(stop) go func() { c.connectIstio() - for { - time.Sleep(30 * time.Minute) - c.reconnectIstio() - } }() } @@ -125,9 +121,10 @@ func (c *Controller) connectIstio() { sm, err := c.newSecretManager() if err != nil { controllerLog.Errorf("failed to create SecretManager %s %v", c.options.IstiodAddr, err) - } else { - config.SecretManager = sm + time.Sleep(5 * time.Second) + continue } + config.SecretManager = sm } c.xdsMCP, err = adsc.New(c.options.IstiodAddr, &config) if err != nil { @@ -139,6 +136,7 @@ func (c *Controller) connectIstio() { c.xdsMCP.Store = configController if err = c.xdsMCP.Run(); err != nil { controllerLog.Errorf("adsc: failed running %v", err) + c.closeConnection() time.Sleep(5 * time.Second) continue } diff --git a/internal/xds/cache_mgr.go b/internal/xds/cache_mgr.go index 96096280..a84db9b2 100644 --- a/internal/xds/cache_mgr.go +++ b/internal/xds/cache_mgr.go @@ -455,6 +455,10 @@ func (c *CacheMgr) initNode(_ string) { c.pushChannel <- istiomodel.EventUpdate } +func (c *CacheMgr) clearNode(node string) { + c.routeCache.ClearSnapshot(node) +} + func (c *CacheMgr) hasNode(node string) bool { if _, err := c.routeCache.GetSnapshot(node); err != nil { return false diff --git a/internal/xds/callbacks.go b/internal/xds/callbacks.go index ea7c5f36..19f4de65 100644 --- a/internal/xds/callbacks.go +++ b/internal/xds/callbacks.go @@ -47,6 +47,7 @@ func (cb *callbacks) OnStreamOpen(_ context.Context, id int64, typ string) error } func (cb *callbacks) OnStreamClosed(id int64, node *core.Node) { xdsLog.Infof("node %s stream %d closed\n", node.Id, id) + cb.cacheMgr.clearNode(node.Id) } func (cb *callbacks) OnDeltaStreamOpen(_ context.Context, id int64, typ string) error { diff --git a/internal/xds/server.go b/internal/xds/server.go index 2bfb0496..5ca68cd7 100644 --- a/internal/xds/server.go +++ b/internal/xds/server.go @@ -35,6 +35,7 @@ type cacheMgr interface { initNode(node string) hasNode(node string) bool cache() cachev3.SnapshotCache + clearNode(node string) } // Server serves xDS resources to Envoy sidecars