@@ -194,10 +194,13 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler {
194
194
signal .Notify (sigs , syscall .SIGUSR1 , syscall .SIGUSR2 )
195
195
go handleSignals (ctx , cancel , sigs , client , haproxyOptions , users )
196
196
197
+ ra := configureReloadAgent (ctx , haproxyOptions , client )
198
+
197
199
if ! haproxyOptions .DisableInotify {
198
- if err := startWatcher (ctx , client , haproxyOptions , users ); err != nil {
200
+ if err := startWatcher (ctx , client , haproxyOptions , users , ra ); err != nil {
199
201
haproxyOptions .DisableInotify = true
200
202
client = configureNativeClient (clientCtx , haproxyOptions , mWorker )
203
+ ra = configureReloadAgent (ctx , haproxyOptions , client )
201
204
}
202
205
}
203
206
@@ -206,24 +209,6 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler {
206
209
go cfg .MapSync .SyncAll (client )
207
210
}
208
211
209
- // Initialize reload agent
210
- raParams := haproxy.ReloadAgentParams {
211
- Delay : haproxyOptions .ReloadDelay ,
212
- ReloadCmd : haproxyOptions .ReloadCmd ,
213
- RestartCmd : haproxyOptions .RestartCmd ,
214
- StatusCmd : haproxyOptions .StatusCmd ,
215
- ConfigFile : haproxyOptions .ConfigFile ,
216
- BackupDir : haproxyOptions .BackupsDir ,
217
- Retention : haproxyOptions .ReloadRetention ,
218
- Ctx : ctx ,
219
- }
220
-
221
- ra , e := haproxy .NewReloadAgent (raParams )
222
- if e != nil {
223
- // nolint:gocritic
224
- log .Fatalf ("Cannot initialize reload agent: %v" , e )
225
- }
226
-
227
212
// setup discovery handlers
228
213
api .DiscoveryGetAPIEndpointsHandler = discovery .GetAPIEndpointsHandlerFunc (func (params discovery.GetAPIEndpointsParams , principal interface {}) middleware.Responder {
229
214
ends , err := misc .DiscoverChildPaths ("" , SwaggerJSON )
@@ -816,6 +801,26 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler {
816
801
return setupGlobalMiddleware (api .Serve (setupMiddlewares ), adpts ... )
817
802
}
818
803
804
+ func configureReloadAgent (ctx context.Context , haproxyOptions dataplaneapi_config.HAProxyConfiguration , client client_native.HAProxyClient ) * haproxy.ReloadAgent {
805
+ raParams := haproxy.ReloadAgentParams {
806
+ Delay : haproxyOptions .ReloadDelay ,
807
+ ReloadCmd : haproxyOptions .ReloadCmd ,
808
+ RestartCmd : haproxyOptions .RestartCmd ,
809
+ StatusCmd : haproxyOptions .StatusCmd ,
810
+ ConfigFile : haproxyOptions .ConfigFile ,
811
+ BackupDir : haproxyOptions .BackupsDir ,
812
+ Retention : haproxyOptions .ReloadRetention ,
813
+ Ctx : ctx ,
814
+ }
815
+
816
+ ra , e := haproxy .NewReloadAgent (raParams )
817
+ if e != nil {
818
+ // nolint:gocritic
819
+ log .Fatalf ("Cannot initialize reload agent: %v" , e )
820
+ }
821
+ return ra
822
+ }
823
+
819
824
// The TLS configuration before HTTPS server starts.
820
825
func configureTLS (tlsConfig * tls.Config ) {
821
826
// Make all necessary changes to the TLS configuration here.
@@ -962,12 +967,40 @@ func reloadConfigurationFile(client client_native.HAProxyClient, haproxyOptions
962
967
client .ReplaceConfiguration (confClient )
963
968
}
964
969
965
- func startWatcher (ctx context.Context , client client_native.HAProxyClient , haproxyOptions dataplaneapi_config.HAProxyConfiguration , users * dataplaneapi_config.Users ) error {
970
+ func startWatcher (ctx context.Context , client client_native.HAProxyClient , haproxyOptions dataplaneapi_config.HAProxyConfiguration , users * dataplaneapi_config.Users , reloadAgent * haproxy. ReloadAgent ) error {
966
971
cb := func () {
967
- reloadConfigurationFile (client , haproxyOptions , users )
968
972
configuration , err := client .Configuration ()
969
973
if err != nil {
970
- log .Warningf ("Failed to increment configuration version: %v" , err )
974
+ log .Warningf ("Failed to get configuration: %s" , err )
975
+ return
976
+ }
977
+
978
+ // save old runtime configuration to know if the runtime client must be configured after the new configuration is
979
+ // reloaded by HAProxy. Logic is done by cn.ReconfigureRuntime() function.
980
+ _ , globalConf , err := configuration .GetGlobalConfiguration ("" )
981
+ if err != nil {
982
+ log .Warningf ("Failed to get global configuration section: %s" , err )
983
+ return
984
+ }
985
+ runtimeAPIsOld := globalConf .RuntimeAPIs
986
+
987
+ // reload configuration from config file.
988
+ reloadConfigurationFile (client , haproxyOptions , users )
989
+
990
+ // reload runtime client if necessary.
991
+ callbackNeeded , reconfigureFunc , err := cn .ReconfigureRuntime (client , runtimeAPIsOld )
992
+ if err != nil {
993
+ log .Warningf ("Failed to check if native client need to be reloaded: %s" , err )
994
+ return
995
+ }
996
+ if callbackNeeded {
997
+ reloadAgent .ReloadWithCallback (reconfigureFunc )
998
+ }
999
+
1000
+ // get the last configuration which has been updated by reloadConfigurationFile and increment version in config file.
1001
+ configuration , err = client .Configuration ()
1002
+ if err != nil {
1003
+ log .Warningf ("Failed to get configuration: %s" , err )
971
1004
return
972
1005
}
973
1006
if err := configuration .IncrementVersion (); err != nil {
0 commit comments