Skip to content

Commit fe28b69

Browse files
fabianonunesoktalz
authored andcommitted
MINOR: allow custom ports for local peer, stats and healthz
1 parent 0e4f460 commit fe28b69

File tree

5 files changed

+40
-3
lines changed

5 files changed

+40
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ frontend healthz
3636

3737
frontend stats
3838
mode http
39-
bind *:1024
39+
bind *:1024 name stats
4040
http-request set-var(txn.base) base
4141
http-request use-service prometheus-exporter if { path /metrics }
4242
stats enable

pkg/controller/controller.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,14 @@ func (c *HAProxyController) updateHAProxy() {
174174

175175
// setToRready exposes readiness endpoint
176176
func (c *HAProxyController) setToReady() {
177+
healthzPort := c.osArgs.HealthzBindPort
177178
logger.Panic(c.clientAPIClosure(func() error {
178179
return c.haproxy.FrontendBindEdit("healthz",
179180
models.Bind{
180181
BindParams: models.BindParams{
181182
Name: "v4",
182183
},
183-
Address: "0.0.0.0:1042",
184+
Address: fmt.Sprintf("0.0.0.0:%d", healthzPort),
184185
})
185186
}))
186187
if !c.osArgs.DisableIPV6 {
@@ -191,10 +192,33 @@ func (c *HAProxyController) setToReady() {
191192
Name: "v6",
192193
V4v6: true,
193194
},
194-
Address: ":::1042",
195+
Address: fmt.Sprintf(":::%d", healthzPort),
195196
})
196197
}))
197198
}
199+
200+
logger.Panic(c.clientAPIClosure(func() error {
201+
ip := "127.0.0.1"
202+
return c.haproxy.PeerEntryEdit("localinstance",
203+
models.PeerEntry{
204+
Name: "local",
205+
Address: &ip,
206+
Port: &c.osArgs.LocalPeerPort,
207+
},
208+
)
209+
}))
210+
211+
logger.Panic(c.clientAPIClosure(func() error {
212+
return c.haproxy.FrontendBindEdit("stats",
213+
models.Bind{
214+
BindParams: models.BindParams{
215+
Name: "stats",
216+
},
217+
Address: fmt.Sprintf("*:%d", c.osArgs.StatsBindPort),
218+
},
219+
)
220+
}))
221+
198222
logger.Debugf("healthz frontend exposed for readiness probe")
199223
cm := c.store.ConfigMaps.Main
200224
if cm.Name != "" && !cm.Loaded {

pkg/haproxy/api/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type HAProxyClient interface {
5959
GlobalPushConfiguration(models.Global) error
6060
GlobalCfgSnippet(snippet []string) error
6161
GetMap(mapFile string) (*models.Map, error)
62+
PeerEntryEdit(peerSection string, peer models.PeerEntry) error
6263
RefreshBackends() (deleted []string, err error)
6364
SetMapContent(mapFile string, payload []string) error
6465
SetServerAddr(backendName string, serverName string, ip string, port int) error

pkg/haproxy/api/frontend.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,12 @@ func (c *clientNative) FrontendRuleDeleteAll(frontend string) {
224224
}
225225
// No usage of TCPResponseRules yet.
226226
}
227+
228+
func (c *clientNative) PeerEntryEdit(peerSection string, peerEntry models.PeerEntry) error {
229+
configuration, err := c.nativeAPI.Configuration()
230+
if err != nil {
231+
return err
232+
}
233+
c.activeTransactionHasChanges = true
234+
return configuration.EditPeerEntry(peerEntry.Name, peerSection, &peerEntry, c.activeTransaction, 0)
235+
}

pkg/utils/flags.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ type OSArgs struct { //nolint:maligned
9494
HTTPSBindPort int64 `long:"https-bind-port" default:"443" description:"port to listen on for HTTPS traffic"`
9595
IPV4BindAddr string `long:"ipv4-bind-address" default:"0.0.0.0" description:"IPv4 address the Ingress Controller listens on (if enabled)"`
9696
IPV6BindAddr string `long:"ipv6-bind-address" default:"::" description:"IPv6 address the Ingress Controller listens on (if enabled)"`
97+
HealthzBindPort int64 `long:"healthz-bind-port" default:"1042" description:"port to listen on for probes"`
98+
StatsBindPort int64 `long:"stats-bind-port" default:"1024" description:"port to listen on for stats page"`
99+
LocalPeerPort int64 `long:"localpeer-port" default:"10000" description:"port to listen on for local peer"`
97100
Program string `long:"program" description:"path to HAProxy program. NOTE: works only with External mode"`
98101
CfgDir string `long:"config-dir" description:"path to HAProxy configuration directory. NOTE: works only in External mode"`
99102
RuntimeDir string `long:"runtime-dir" description:"path to HAProxy runtime directory. NOTE: works only in External mode"`

0 commit comments

Comments
 (0)