Skip to content

Commit

Permalink
MINOR: reorg auxiliary config file management
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmatmati authored and oktalz committed Sep 7, 2021
1 parent e625338 commit dc59877
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func (c *HAProxyController) clientAPIClosure(fn func() error) (err error) {
if err = fn(); err != nil {
return err
}

if err = c.Client.APICommitTransaction(); err != nil {
return err
}
Expand All @@ -75,10 +76,12 @@ func (c *HAProxyController) Start() {
if err != nil {
logger.Panic(err)
}

c.Client, err = api.Init(c.Cfg.Env.TransactionDir, c.Cfg.Env.MainCFGFile, c.Cfg.Env.HAProxyBinary, c.Cfg.Env.RuntimeSocket)
if err != nil {
logger.Panic(err)
}

c.initHandlers()
c.haproxyStartup()

Expand Down
10 changes: 10 additions & 0 deletions controller/haproxy/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type HAProxyClient interface {
ServerStateBase(value *types.StringC) error
SetServerAddr(backendName string, serverName string, ip string, port int) error
SetServerState(backendName string, serverName string, state string) error
SetAuxCfgFile(auxCfgFile string)
SyncBackendSrvs(oldEndpoints, newEndpoints *store.PortEndpoints) error
UserListDeleteByGroup(group string) error
UserListCreateByGroup(group string, userPasswordMap map[string][]byte) error
Expand Down Expand Up @@ -90,6 +91,7 @@ func Init(transactionDir, configFile, programPath, runtimeSocket string) (client
Haproxy: programPath,
ValidateConfigurationFile: true,
}

if transactionDir != "" {
confParams.TransactionDir = transactionDir
}
Expand Down Expand Up @@ -137,3 +139,11 @@ func (c *clientNative) APIDisposeTransaction() {
c.activeTransaction = ""
c.activeTransactionHasChanges = false
}

func (c *clientNative) SetAuxCfgFile(auxCfgFile string) {
if auxCfgFile == "" {
c.nativeAPI.Configuration.Transaction.ValidateConfigFilesAfter = nil
return
}
c.nativeAPI.Configuration.Transaction.ValidateConfigFilesAfter = []string{auxCfgFile}
}
2 changes: 2 additions & 0 deletions controller/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func (c *HAProxyController) auxCfgUpdated() bool {
}
logger.Infof("Auxiliary HAProxy config '%s' removed", c.Cfg.Env.AuxCFGFile)
c.AuxCfgModTime = 0
c.Client.SetAuxCfgFile("")
return true
}
// Check modification time
Expand All @@ -190,5 +191,6 @@ func (c *HAProxyController) auxCfgUpdated() bool {
}
logger.Infof("Auxiliary HAProxy config '%s' updated", c.Cfg.Env.AuxCFGFile)
c.AuxCfgModTime = modifTime
c.Client.SetAuxCfgFile(c.Cfg.Env.AuxCFGFile)
return true
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.16

require (
github.com/google/renameio v0.1.1-0.20200217212219-353f81969824
github.com/haproxytech/client-native/v2 v2.2.1-0.20210202111144-7c1e53d92758
github.com/haproxytech/client-native/v2 v2.2.1
github.com/haproxytech/config-parser/v3 v3.0.0-rc1.0.20201218192213-cf1331eaac44
github.com/haproxytech/models/v2 v2.2.0-rc1.0.20210112080933-32de531b38f2
github.com/jessevdk/go-flags v1.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m
github.com/googleapis/gnostic v0.4.1 h1:DLJCy1n/vrD4HPjOvYcT8aYQXpPIzoRZONaYwyycI+I=
github.com/googleapis/gnostic v0.4.1/go.mod h1:LRhVm6pbyptWbWbuZ38d1eyptfvIytN3ir6b65WBswg=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/haproxytech/client-native/v2 v2.2.1-0.20210202111144-7c1e53d92758 h1:0mgmRsHKSiXLmVJ/yMCihoqSvj2EF/Y9DhPnbhwUXFE=
github.com/haproxytech/client-native/v2 v2.2.1-0.20210202111144-7c1e53d92758/go.mod h1:PwZEyFw1UlwUp+OPETx/0hpUhNPYmgdLJ/+ss/FVv2w=
github.com/haproxytech/client-native/v2 v2.2.1 h1:ufbAxRA1s/cU6ByAxHO1A/Bhn0pg64AIVfNQDtKd4bE=
github.com/haproxytech/client-native/v2 v2.2.1/go.mod h1:PwZEyFw1UlwUp+OPETx/0hpUhNPYmgdLJ/+ss/FVv2w=
github.com/haproxytech/config-parser/v3 v3.0.0-rc1.0.20201218192213-cf1331eaac44 h1:lWMn14Si9rseZ3UfTI2w7nqKRjjTIUkyJc7PCHI9928=
github.com/haproxytech/config-parser/v3 v3.0.0-rc1.0.20201218192213-cf1331eaac44/go.mod h1:68k+xwy1wGoufI/VKOOilrx/65M85eeQP6Atg+a29Ds=
github.com/haproxytech/models/v2 v2.2.0-rc1.0.20210112080933-32de531b38f2 h1:cJfX3CNxOcZ7FW3pB88IxJfczdHBEG/dZ25A8JrQr78=
Expand Down

0 comments on commit dc59877

Please sign in to comment.