cmd/kg,pkg: add --resync-period flag
This commit introduces a new `--resync-period` flag to control how often the Kilo controllers should reconcile. Signed-off-by: Lucas Servén Marín <lserven@gmail.com>
This commit is contained in:
@@ -65,6 +65,7 @@ type Mesh struct {
|
||||
priv []byte
|
||||
privIface int
|
||||
pub []byte
|
||||
resyncPeriod time.Duration
|
||||
stop chan struct{}
|
||||
subnet *net.IPNet
|
||||
table *route.Table
|
||||
@@ -85,7 +86,7 @@ type Mesh struct {
|
||||
}
|
||||
|
||||
// New returns a new Mesh instance.
|
||||
func New(backend Backend, enc encapsulation.Encapsulator, granularity Granularity, hostname string, port uint32, subnet *net.IPNet, local, cni bool, cniPath, iface string, cleanUpIface bool, createIface bool, logger log.Logger) (*Mesh, error) {
|
||||
func New(backend Backend, enc encapsulation.Encapsulator, granularity Granularity, hostname string, port uint32, subnet *net.IPNet, local, cni bool, cniPath, iface string, cleanUpIface bool, createIface bool, resyncPeriod time.Duration, logger log.Logger) (*Mesh, error) {
|
||||
if err := os.MkdirAll(kiloPath, 0700); err != nil {
|
||||
return nil, fmt.Errorf("failed to create directory to store configuration: %v", err)
|
||||
}
|
||||
@@ -143,7 +144,7 @@ func New(backend Backend, enc encapsulation.Encapsulator, granularity Granularit
|
||||
level.Debug(logger).Log("msg", "running without a private IP address")
|
||||
}
|
||||
level.Debug(logger).Log("msg", fmt.Sprintf("using %s as the public IP address", publicIP.String()))
|
||||
ipTables, err := iptables.New(iptables.WithLogger(log.With(logger, "component", "iptables")))
|
||||
ipTables, err := iptables.New(iptables.WithLogger(log.With(logger, "component", "iptables")), iptables.WithResyncPeriod(resyncPeriod))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to IP tables controller: %v", err)
|
||||
}
|
||||
@@ -234,7 +235,8 @@ func (m *Mesh) Run() error {
|
||||
}
|
||||
}()
|
||||
defer m.cleanUp()
|
||||
t := time.NewTimer(resyncPeriod)
|
||||
resync := time.NewTimer(m.resyncPeriod)
|
||||
checkIn := time.NewTimer(checkInPeriod)
|
||||
nw := m.Nodes().Watch()
|
||||
pw := m.Peers().Watch()
|
||||
var ne *NodeEvent
|
||||
@@ -245,13 +247,15 @@ func (m *Mesh) Run() error {
|
||||
m.syncNodes(ne)
|
||||
case pe = <-pw:
|
||||
m.syncPeers(pe)
|
||||
case <-t.C:
|
||||
case <-checkIn.C:
|
||||
m.checkIn()
|
||||
checkIn.Reset(checkInPeriod)
|
||||
case <-resync.C:
|
||||
if m.cni {
|
||||
m.updateCNIConfig()
|
||||
}
|
||||
m.applyTopology()
|
||||
t.Reset(resyncPeriod)
|
||||
resync.Reset(m.resyncPeriod)
|
||||
case <-m.stop:
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user