Skip to content

Commit 64fdab8

Browse files
committed
MINOR: initial sync period flag sets the first transaction sync period
1 parent 97b2159 commit 64fdab8

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ func main() {
9696
// exit, this is just a job
9797
os.Exit(0)
9898
}
99+
if osArgs.InitialSyncPeriod == 0 {
100+
osArgs.InitialSyncPeriod = osArgs.SyncPeriod
101+
}
99102

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

237241
hostname, err := os.Hostname()

pkg/k8s/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ type k8s struct {
8282
podNamespace string
8383
whiteListedNS []string
8484
syncPeriod time.Duration
85+
initialSyncPeriod time.Duration
8586
cacheResyncPeriod time.Duration
8687
disableSvcExternalName bool // CVE-2021-25740
8788
gatewayAPIInstalled bool
@@ -125,6 +126,7 @@ func New(osArgs utils.OSArgs, whitelist map[string]struct{}, publishSvc *utils.N
125126
podNamespace: os.Getenv("POD_NAMESPACE"),
126127
podPrefix: prefix,
127128
syncPeriod: osArgs.SyncPeriod,
129+
initialSyncPeriod: osArgs.InitialSyncPeriod,
128130
cacheResyncPeriod: osArgs.CacheResyncPeriod,
129131
disableSvcExternalName: osArgs.DisableServiceExternalName,
130132
gatewayClient: gatewayClient,
@@ -170,7 +172,11 @@ func (k k8s) MonitorChanges(eventChan chan k8ssync.SyncDataEvent, stop chan stru
170172
}
171173

172174
syncPeriod := k.syncPeriod
173-
logger.Debugf("Executing syncPeriod every %s", syncPeriod.String())
175+
initialSyncPeriod := k.initialSyncPeriod
176+
logger.Debugf("Executing first transaction after %s", initialSyncPeriod.String())
177+
logger.Debugf("Executing new transaction every %s", syncPeriod.String())
178+
time.Sleep(k.initialSyncPeriod)
179+
eventChan <- k8ssync.SyncDataEvent{SyncType: k8ssync.COMMAND}
174180
for {
175181
time.Sleep(syncPeriod)
176182
eventChan <- k8ssync.SyncDataEvent{SyncType: k8ssync.COMMAND}

pkg/utils/flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ type OSArgs struct {
9898
HTTPBindPort int64 `long:"http-bind-port" default:"8080" description:"port to listen on for HTTP traffic"`
9999
HTTPSBindPort int64 `long:"https-bind-port" default:"8443" description:"port to listen on for HTTPS traffic"`
100100
SyncPeriod time.Duration `long:"sync-period" default:"5s" description:"Sets the period at which the controller syncs HAProxy configuration file"`
101+
InitialSyncPeriod time.Duration `long:"initial-sync-period" description:"Sets the first period at which the controller syncs HAProxy configuration file"`
101102
CacheResyncPeriod time.Duration `long:"cache-resync-period" default:"10m" description:"Sets the underlying Shared Informer resync period: resyncing controller with informers cache"`
102103
HealthzBindPort int64 `long:"healthz-bind-port" default:"1042" description:"port to listen on for probes"`
103104
QuicAnnouncePort int64 `long:"quic-announce-port" description:"sets the port in the alt-svc header"`

0 commit comments

Comments
 (0)