Skip to content

Commit

Permalink
More
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Jan 17, 2024
1 parent a3e3487 commit ae2bc37
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/internal/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -19,6 +20,7 @@ type Core struct {
partitionID string
rackID string
enableReconfigureSwitch bool
syncDelay time.Duration
managementGateway string
additionalBridgePorts []string
additionalBridgeVIDs []string
Expand All @@ -42,6 +44,7 @@ type Config struct {
PartitionID string
RackID string
ReconfigureSwitch bool
SyncDelay time.Duration
ManagementGateway string
AdditionalBridgePorts []string
AdditionalBridgeVIDs []string
Expand Down
13 changes: 12 additions & 1 deletion cmd/internal/core/reconfigure-switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ae2bc37

Please sign in to comment.