Skip to content

Commit

Permalink
MINOR: initial sync period flag sets the first transaction sync period
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmatmati committed Nov 22, 2024
1 parent 97b2159 commit 64fdab8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ func main() {
// exit, this is just a job
os.Exit(0)
}
if osArgs.InitialSyncPeriod == 0 {
osArgs.InitialSyncPeriod = osArgs.SyncPeriod
}

logger.ShowFilename(false)
exit := logInfo(logger, osArgs)
Expand Down Expand Up @@ -232,6 +235,7 @@ func logInfo(logger utils.Logger, osArgs utils.OSArgs) bool {
logger.Printf("Disabling the delayed writing of files to disk only in case of haproxy reload (write to disk even if no reload)")
}
logger.Debugf("Kubernetes Informers resync period: %s", osArgs.CacheResyncPeriod.String())
logger.Printf("Controller initial sync period: %s", osArgs.InitialSyncPeriod.String())
logger.Printf("Controller sync period: %s\n", osArgs.SyncPeriod.String())

hostname, err := os.Hostname()
Expand Down
8 changes: 7 additions & 1 deletion pkg/k8s/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type k8s struct {
podNamespace string
whiteListedNS []string
syncPeriod time.Duration
initialSyncPeriod time.Duration
cacheResyncPeriod time.Duration
disableSvcExternalName bool // CVE-2021-25740
gatewayAPIInstalled bool
Expand Down Expand Up @@ -125,6 +126,7 @@ func New(osArgs utils.OSArgs, whitelist map[string]struct{}, publishSvc *utils.N
podNamespace: os.Getenv("POD_NAMESPACE"),
podPrefix: prefix,
syncPeriod: osArgs.SyncPeriod,
initialSyncPeriod: osArgs.InitialSyncPeriod,
cacheResyncPeriod: osArgs.CacheResyncPeriod,
disableSvcExternalName: osArgs.DisableServiceExternalName,
gatewayClient: gatewayClient,
Expand Down Expand Up @@ -170,7 +172,11 @@ func (k k8s) MonitorChanges(eventChan chan k8ssync.SyncDataEvent, stop chan stru
}

syncPeriod := k.syncPeriod
logger.Debugf("Executing syncPeriod every %s", syncPeriod.String())
initialSyncPeriod := k.initialSyncPeriod
logger.Debugf("Executing first transaction after %s", initialSyncPeriod.String())
logger.Debugf("Executing new transaction every %s", syncPeriod.String())
time.Sleep(k.initialSyncPeriod)
eventChan <- k8ssync.SyncDataEvent{SyncType: k8ssync.COMMAND}
for {
time.Sleep(syncPeriod)
eventChan <- k8ssync.SyncDataEvent{SyncType: k8ssync.COMMAND}
Expand Down
1 change: 1 addition & 0 deletions pkg/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ type OSArgs struct {
HTTPBindPort int64 `long:"http-bind-port" default:"8080" description:"port to listen on for HTTP traffic"`
HTTPSBindPort int64 `long:"https-bind-port" default:"8443" description:"port to listen on for HTTPS traffic"`
SyncPeriod time.Duration `long:"sync-period" default:"5s" description:"Sets the period at which the controller syncs HAProxy configuration file"`
InitialSyncPeriod time.Duration `long:"initial-sync-period" description:"Sets the first period at which the controller syncs HAProxy configuration file"`
CacheResyncPeriod time.Duration `long:"cache-resync-period" default:"10m" description:"Sets the underlying Shared Informer resync period: resyncing controller with informers cache"`
HealthzBindPort int64 `long:"healthz-bind-port" default:"1042" description:"port to listen on for probes"`
QuicAnnouncePort int64 `long:"quic-announce-port" description:"sets the port in the alt-svc header"`
Expand Down

0 comments on commit 64fdab8

Please sign in to comment.