@@ -94,8 +94,8 @@ func (c *HAProxyController) SyncData() {
9494 change := false
9595 switch job .SyncType {
9696 case COMMAND :
97- c .reload = c .auxCfgUpdated ()
98- if hadChanges || c .reload {
97+ c .restart , c . reload = c .auxCfgManager ()
98+ if hadChanges || c .reload || c . restart {
9999 c .updateHAProxy ()
100100 hadChanges = false
101101 continue
@@ -199,28 +199,52 @@ func (c *HAProxyController) getWhitelistedNamespaces() []string {
199199 return namespaces
200200}
201201
202- // auxCfgUpdate returns true if auxiliary HAProxy config file was updated, false otherwise .
203- func (c * HAProxyController ) auxCfgUpdated () bool {
202+ // auxCfgManager returns restart or reload requirement based on state and transition of auxiliary configuration file .
203+ func (c * HAProxyController ) auxCfgManager () ( restart , reload bool ) {
204204 info , errStat := os .Stat (c .Cfg .Env .AuxCFGFile )
205+ var (
206+ modifTime int64
207+ auxCfgFile string = c .Cfg .Env .AuxCFGFile
208+ useAuxFile bool
209+ )
210+
211+ defer func () {
212+ // Nothing changed
213+ if c .AuxCfgModTime == modifTime {
214+ return
215+ }
216+ // Apply decisions
217+ c .Client .SetAuxCfgFile (auxCfgFile )
218+ c .haproxyProcess .UseAuxFile (useAuxFile )
219+ // The file exists now (modifTime !=0 otherwise nothing changed case).
220+ if c .AuxCfgModTime == 0 {
221+ restart = true
222+ } else {
223+ // File already exists,
224+ // already in command line parameters just need to reload for modifications.
225+ reload = true
226+ }
227+ c .AuxCfgModTime = modifTime
228+ if c .AuxCfgModTime != 0 {
229+ logger .Infof ("Auxiliary HAProxy config '%s' updated" , auxCfgFile )
230+ }
231+ }()
232+
205233 // File does not exist
206234 if errStat != nil {
235+ // nullify it
236+ auxCfgFile = ""
207237 if c .AuxCfgModTime == 0 {
208- return false
238+ // never existed before
239+ return
209240 }
210241 logger .Infof ("Auxiliary HAProxy config '%s' removed" , c .Cfg .Env .AuxCFGFile )
211- c .AuxCfgModTime = 0
212- c .Client .SetAuxCfgFile ("" )
213- c .haproxyProcess .UseAuxFile (false )
214- return true
215- }
216- // Check modification time
217- modifTime := info .ModTime ().Unix ()
218- if c .AuxCfgModTime == modifTime {
219- return false
242+ // but existed so need to restart
243+ restart = true
244+ return
220245 }
221- logger .Infof ("Auxiliary HAProxy config '%s' updated" , c .Cfg .Env .AuxCFGFile )
222- c .AuxCfgModTime = modifTime
223- c .Client .SetAuxCfgFile (c .Cfg .Env .AuxCFGFile )
224- c .haproxyProcess .UseAuxFile (true )
225- return true
246+ // File exists
247+ useAuxFile = true
248+ modifTime = info .ModTime ().Unix ()
249+ return
226250}
0 commit comments