Skip to content

Commit dc59877

Browse files
ivanmatmatioktalz
authored andcommitted
MINOR: reorg auxiliary config file management
1 parent e625338 commit dc59877

File tree

5 files changed

+18
-3
lines changed

5 files changed

+18
-3
lines changed

controller/controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func (c *HAProxyController) clientAPIClosure(fn func() error) (err error) {
5959
if err = fn(); err != nil {
6060
return err
6161
}
62+
6263
if err = c.Client.APICommitTransaction(); err != nil {
6364
return err
6465
}
@@ -75,10 +76,12 @@ func (c *HAProxyController) Start() {
7576
if err != nil {
7677
logger.Panic(err)
7778
}
79+
7880
c.Client, err = api.Init(c.Cfg.Env.TransactionDir, c.Cfg.Env.MainCFGFile, c.Cfg.Env.HAProxyBinary, c.Cfg.Env.RuntimeSocket)
7981
if err != nil {
8082
logger.Panic(err)
8183
}
84+
8285
c.initHandlers()
8386
c.haproxyStartup()
8487

controller/haproxy/api/api.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type HAProxyClient interface {
6363
ServerStateBase(value *types.StringC) error
6464
SetServerAddr(backendName string, serverName string, ip string, port int) error
6565
SetServerState(backendName string, serverName string, state string) error
66+
SetAuxCfgFile(auxCfgFile string)
6667
SyncBackendSrvs(oldEndpoints, newEndpoints *store.PortEndpoints) error
6768
UserListDeleteByGroup(group string) error
6869
UserListCreateByGroup(group string, userPasswordMap map[string][]byte) error
@@ -90,6 +91,7 @@ func Init(transactionDir, configFile, programPath, runtimeSocket string) (client
9091
Haproxy: programPath,
9192
ValidateConfigurationFile: true,
9293
}
94+
9395
if transactionDir != "" {
9496
confParams.TransactionDir = transactionDir
9597
}
@@ -137,3 +139,11 @@ func (c *clientNative) APIDisposeTransaction() {
137139
c.activeTransaction = ""
138140
c.activeTransactionHasChanges = false
139141
}
142+
143+
func (c *clientNative) SetAuxCfgFile(auxCfgFile string) {
144+
if auxCfgFile == "" {
145+
c.nativeAPI.Configuration.Transaction.ValidateConfigFilesAfter = nil
146+
return
147+
}
148+
c.nativeAPI.Configuration.Transaction.ValidateConfigFilesAfter = []string{auxCfgFile}
149+
}

controller/monitor.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ func (c *HAProxyController) auxCfgUpdated() bool {
181181
}
182182
logger.Infof("Auxiliary HAProxy config '%s' removed", c.Cfg.Env.AuxCFGFile)
183183
c.AuxCfgModTime = 0
184+
c.Client.SetAuxCfgFile("")
184185
return true
185186
}
186187
// Check modification time
@@ -190,5 +191,6 @@ func (c *HAProxyController) auxCfgUpdated() bool {
190191
}
191192
logger.Infof("Auxiliary HAProxy config '%s' updated", c.Cfg.Env.AuxCFGFile)
192193
c.AuxCfgModTime = modifTime
194+
c.Client.SetAuxCfgFile(c.Cfg.Env.AuxCFGFile)
193195
return true
194196
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.16
44

55
require (
66
github.com/google/renameio v0.1.1-0.20200217212219-353f81969824
7-
github.com/haproxytech/client-native/v2 v2.2.1-0.20210202111144-7c1e53d92758
7+
github.com/haproxytech/client-native/v2 v2.2.1
88
github.com/haproxytech/config-parser/v3 v3.0.0-rc1.0.20201218192213-cf1331eaac44
99
github.com/haproxytech/models/v2 v2.2.0-rc1.0.20210112080933-32de531b38f2
1010
github.com/jessevdk/go-flags v1.4.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m
207207
github.com/googleapis/gnostic v0.4.1 h1:DLJCy1n/vrD4HPjOvYcT8aYQXpPIzoRZONaYwyycI+I=
208208
github.com/googleapis/gnostic v0.4.1/go.mod h1:LRhVm6pbyptWbWbuZ38d1eyptfvIytN3ir6b65WBswg=
209209
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
210-
github.com/haproxytech/client-native/v2 v2.2.1-0.20210202111144-7c1e53d92758 h1:0mgmRsHKSiXLmVJ/yMCihoqSvj2EF/Y9DhPnbhwUXFE=
211-
github.com/haproxytech/client-native/v2 v2.2.1-0.20210202111144-7c1e53d92758/go.mod h1:PwZEyFw1UlwUp+OPETx/0hpUhNPYmgdLJ/+ss/FVv2w=
210+
github.com/haproxytech/client-native/v2 v2.2.1 h1:ufbAxRA1s/cU6ByAxHO1A/Bhn0pg64AIVfNQDtKd4bE=
211+
github.com/haproxytech/client-native/v2 v2.2.1/go.mod h1:PwZEyFw1UlwUp+OPETx/0hpUhNPYmgdLJ/+ss/FVv2w=
212212
github.com/haproxytech/config-parser/v3 v3.0.0-rc1.0.20201218192213-cf1331eaac44 h1:lWMn14Si9rseZ3UfTI2w7nqKRjjTIUkyJc7PCHI9928=
213213
github.com/haproxytech/config-parser/v3 v3.0.0-rc1.0.20201218192213-cf1331eaac44/go.mod h1:68k+xwy1wGoufI/VKOOilrx/65M85eeQP6Atg+a29Ds=
214214
github.com/haproxytech/models/v2 v2.2.0-rc1.0.20210112080933-32de531b38f2 h1:cJfX3CNxOcZ7FW3pB88IxJfczdHBEG/dZ25A8JrQr78=

0 commit comments

Comments
 (0)