Skip to content

Commit ebf1bbd

Browse files
ivanmatmatioktalz
authored andcommitted
MINOR: provide initial local peer
1 parent b23396d commit ebf1bbd

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

fs/usr/local/etc/haproxy/haproxy.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
global
1010
daemon
11+
localpeer local
1112
master-worker
1213
pidfile /var/run/haproxy.pid
1314
stats socket /var/run/haproxy-runtime-api.sock level admin expose-fd listeners
@@ -23,7 +24,7 @@ defaults haproxytech
2324
timeout http-keep-alive 60000
2425

2526
peers localinstance
26-
27+
peer local 127.0.0.1:10000
2728

2829
frontend https
2930
mode http

pkg/controller/controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ func (c *HAProxyController) clientAPIClosure(fn func() error) (err error) {
8484
// Start initializes and runs HAProxyController
8585
func (c *HAProxyController) Start() {
8686
logger.Panic(c.clientAPIClosure(func() error {
87+
err := c.haproxy.PeerEntryDelete("localinstance", "local")
88+
if err != nil {
89+
return err
90+
}
8791
return c.haproxy.PeerEntryCreateOrEdit("localinstance",
8892
models.PeerEntry{
8993
Name: c.Hostname,

pkg/haproxy/api/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ type HAProxyClient interface { //nolint:interfacebloat
8080
HTTPRequestRule
8181
LogTarget
8282
TCPRequestRule
83+
PeerEntryDelete(peerSection string, name string) error
8384
PeerEntryEdit(peerSection string, peer models.PeerEntry) error
8485
PeerEntryCreateOrEdit(peerSection string, peer models.PeerEntry) error
8586
SetMapContent(mapFile string, payload []string) error

pkg/haproxy/api/frontend.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,11 @@ func (c *clientNative) PeerEntryCreateOrEdit(peerSection string, peerEntry model
243243
}
244244
return err
245245
}
246+
247+
func (c *clientNative) PeerEntryDelete(peerSection, entry string) error {
248+
cfg, err := c.nativeAPI.Configuration()
249+
if err != nil {
250+
return err
251+
}
252+
return cfg.DeletePeerEntry(entry, peerSection, c.activeTransaction, 0)
253+
}

0 commit comments

Comments
 (0)