diff --git a/main.go b/main.go index 8b549944..00ba2bcc 100644 --- a/main.go +++ b/main.go @@ -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) @@ -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() diff --git a/pkg/k8s/main.go b/pkg/k8s/main.go index ea03f93f..daa14b15 100644 --- a/pkg/k8s/main.go +++ b/pkg/k8s/main.go @@ -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 @@ -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, @@ -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} diff --git a/pkg/utils/flags.go b/pkg/utils/flags.go index bb1e65b8..75130adb 100644 --- a/pkg/utils/flags.go +++ b/pkg/utils/flags.go @@ -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"`