diff --git a/cmd/internal/core/core.go b/cmd/internal/core/core.go index f87a0e85..f547a332 100644 --- a/cmd/internal/core/core.go +++ b/cmd/internal/core/core.go @@ -2,6 +2,7 @@ package core import ( "log/slog" + "time" v1 "github.com/metal-stack/metal-api/pkg/api/v1" "github.com/metal-stack/metal-core/cmd/internal/metrics" @@ -19,6 +20,7 @@ type Core struct { partitionID string rackID string enableReconfigureSwitch bool + syncDelay time.Duration managementGateway string additionalBridgePorts []string additionalBridgeVIDs []string @@ -42,6 +44,7 @@ type Config struct { PartitionID string RackID string ReconfigureSwitch bool + SyncDelay time.Duration ManagementGateway string AdditionalBridgePorts []string AdditionalBridgeVIDs []string diff --git a/cmd/internal/core/reconfigure-switch.go b/cmd/internal/core/reconfigure-switch.go index de804414..d890bd3d 100644 --- a/cmd/internal/core/reconfigure-switch.go +++ b/cmd/internal/core/reconfigure-switch.go @@ -17,13 +17,23 @@ import ( ) type ReconfigureSwitch struct { - Core *Core + Core *Core + lastSync time.Time } // ReconfigureSwitch reconfigures the switch. func (r *ReconfigureSwitch) Run() { host, _ := os.Hostname() r.Core.log.Info("trigger reconfiguration") + + // Max every 5 Seconds, TODO configurable ? + if time.Since(r.lastSync) < 5*time.Second { + r.Core.log.Info("skiping reconfiguration because of last reconfiguration was too recent") + return + } + + time.Sleep(r.Core.syncDelay) + start := time.Now() err := r.Core.reconfigureSwitch(host) elapsed := time.Since(start) @@ -42,6 +52,7 @@ func (r *ReconfigureSwitch) Run() { r.Core.metrics.CountError("switch-reconfiguration") } else { r.Core.log.Info("reconfiguration succeeded") + r.lastSync = time.Now() } params.Body = nr diff --git a/cmd/server.go b/cmd/server.go index 273014cf..24e471c9 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -100,6 +100,7 @@ func Run() { PartitionID: cfg.PartitionID, RackID: cfg.RackID, ReconfigureSwitch: cfg.ReconfigureSwitch, + SyncDelay: cfg.SyncDelay, ManagementGateway: cfg.ManagementGateway, AdditionalBridgePorts: cfg.AdditionalBridgePorts, AdditionalBridgeVIDs: cfg.AdditionalBridgeVIDs,