Skip to content

Commit

Permalink
BUG/MINOR: check files with -W when in master-worker mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mjuraga committed Apr 15, 2020
1 parent f6c08f5 commit 284d34b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
14 changes: 9 additions & 5 deletions configure_data_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ var loggingOptions struct {
LogFormat string `long:"log-format" description:"Logging format" default:"text" choice:"text" choice:"JSON"`
}

var mWorker bool = false
var logFile *os.File

func configureFlags(api *operations.DataPlaneAPI) {
Expand All @@ -110,6 +111,7 @@ func configureFlags(api *operations.DataPlaneAPI) {
}

func configureAPI(api *operations.DataPlaneAPI) http.Handler {

configureLogging()

defer func() {
Expand All @@ -136,7 +138,7 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler {

api.ServerShutdown = serverShutdown

client := configureNativeClient()
client := configureNativeClient(mWorker)

// Handle reload signals
sigs := make(chan os.Signal, 1)
Expand Down Expand Up @@ -493,9 +495,10 @@ func serverShutdown() {
}
}

func configureNativeClient() *client_native.HAProxyClient {
func configureNativeClient(mWorker bool) *client_native.HAProxyClient {
// Override options with env variables
if os.Getenv("HAPROXY_MWORKER") == "1" {
mWorker = true
masterRuntime := os.Getenv("HAPROXY_MASTER_CLI")
if masterRuntime != "" && !strings.HasPrefix(masterRuntime, "ipv4@") {
haproxyOptions.MasterRuntime = masterRuntime
Expand All @@ -507,7 +510,7 @@ func configureNativeClient() *client_native.HAProxyClient {
haproxyOptions.ConfigFile = cfg[0]
}
// Initialize HAProxy native client
confClient, err := configureConfigurationClient()
confClient, err := configureConfigurationClient(mWorker)
if err != nil {
log.Fatalf("Error initializing configuration client: %v", err)
}
Expand All @@ -521,7 +524,7 @@ func configureNativeClient() *client_native.HAProxyClient {
return client
}

func configureConfigurationClient() (*configuration.Client, error) {
func configureConfigurationClient(mWorker bool) (*configuration.Client, error) {
confClient := &configuration.Client{}
confParams := configuration.ClientParams{
ConfigurationFile: haproxyOptions.ConfigFile,
Expand All @@ -530,6 +533,7 @@ func configureConfigurationClient() (*configuration.Client, error) {
UseValidation: false,
PersistentTransactions: true,
TransactionDir: haproxyOptions.TransactionDir,
MasterWorker: true,
}
err := confClient.Init(confParams)
if err != nil {
Expand Down Expand Up @@ -589,7 +593,7 @@ func handleSignals(sigs chan os.Signal, client *client_native.HAProxyClient) {
client.Runtime = configureRuntimeClient(client.Configuration)
log.Info("Reloaded Data Plane API")
} else if sig == syscall.SIGUSR2 {
confClient, err := configureConfigurationClient()
confClient, err := configureConfigurationClient(mWorker)
if err != nil {
log.Fatalf(err.Error())
}
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@ go 1.12

require (
github.com/GehirnInc/crypt v0.0.0-20190301055215-6c0105aabd46
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/docker/go-units v0.4.0
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/go-openapi/errors v0.19.0
github.com/go-openapi/loads v0.19.0
github.com/go-openapi/runtime v0.19.0
github.com/go-openapi/spec v0.19.0
github.com/go-openapi/strfmt v0.19.0
github.com/go-openapi/swag v0.19.0
github.com/go-openapi/validate v0.19.0
github.com/haproxytech/client-native v1.2.7-0.20191217143845-4e118a2d28a5
github.com/haproxytech/client-native v1.2.7
github.com/haproxytech/config-parser v1.2.0
github.com/haproxytech/models v1.2.5-0.20191122125615-30d0235b81ec
github.com/jessevdk/go-flags v1.4.0
github.com/rs/cors v1.6.0
github.com/shirou/gopsutil v2.18.12+incompatible
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect
github.com/sirupsen/logrus v1.4.2
golang.org/x/net v0.0.0-20190607181551-461777fb6f67
golang.org/x/sys v0.0.0-20190422165155-953cdadca894
Expand Down
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tN
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf h1:eg0MeVzsP1G42dRafH3vf+al2vQIJU0YHX+1Tw87oco=
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 h1:DujepqpGd1hyOd7aW59XpK7Qymp8iy83xq74fLr21is=
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
github.com/go-openapi/analysis v0.0.0-20180825180245-b006789cd277/go.mod h1:k70tL6pCuVxPJOHXQ+wIac1FUrvNkHolPie/cLEU6hI=
github.com/go-openapi/analysis v0.17.0/go.mod h1:IowGgpVeD0vNm45So8nr+IcQ3pxVtpRoBWb8PVZO0ik=
github.com/go-openapi/analysis v0.18.0 h1:hRMEymXOgwo7KLPqqFmw6t3jLO2/zxUe/TXjAHPq9Gc=
Expand Down Expand Up @@ -74,6 +79,8 @@ github.com/haproxytech/client-native v1.2.7-0.20191122131150-a6818774610f h1:B3s
github.com/haproxytech/client-native v1.2.7-0.20191122131150-a6818774610f/go.mod h1:LY/19nHPBYa5R28ifLPEJkJltLZtOabbM2Q6WnBysCc=
github.com/haproxytech/client-native v1.2.7-0.20191217143845-4e118a2d28a5 h1:0e/L01qrXu28C7N/oGSCeeW7UxcKNr5Cvl0+4U3+0ns=
github.com/haproxytech/client-native v1.2.7-0.20191217143845-4e118a2d28a5/go.mod h1:BxJRzPKyTJqaVEOs/gU30Fi0NXcxACZoFnwAMdWc6tI=
github.com/haproxytech/client-native v1.2.7 h1:PrTozZq1ecdhi9xsqlbaB0ezzDRF1y1tzMLolITimgQ=
github.com/haproxytech/client-native v1.2.7/go.mod h1:BxJRzPKyTJqaVEOs/gU30Fi0NXcxACZoFnwAMdWc6tI=
github.com/haproxytech/config-parser v1.1.3 h1:8G+XQ7QXGctmeQlgg9xME0WMY0TK7pZenf/DZM/QWfo=
github.com/haproxytech/config-parser v1.1.3/go.mod h1:se7v728KDunj+qz1kXFFFl+nDuoBdUaN5eYSi+gYjNM=
github.com/haproxytech/config-parser v1.1.4 h1:J9ziufMtKSemiHILPu3GgAopuhA8bMxxR1f0kGtgnHk=
Expand Down Expand Up @@ -105,6 +112,7 @@ github.com/haproxytech/models v1.2.5-0.20191122125615-30d0235b81ec h1:t/GUE635MK
github.com/haproxytech/models v1.2.5-0.20191122125615-30d0235b81ec/go.mod h1:UXZVErm/XN6z10sM/enmxrdeEnwo7vz1JI+a8ycEvOQ=
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand All @@ -117,16 +125,20 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/cors v1.6.0 h1:G9tHG9lebljV9mfp9SNPDL36nCDxmo3zTlAf1YgvzmI=
github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/shirou/gopsutil v2.18.12+incompatible h1:1eaJvGomDnH74/5cF4CTmTbLHAriGFsTZppLXDX93OM=
github.com/shirou/gopsutil v2.18.12+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 h1:udFKJ0aHUL60LboW/A+DfgoHVedieIzIXE8uylPue0U=
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190320223903-b7391e95e576/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down

0 comments on commit 284d34b

Please sign in to comment.