Skip to content

Commit

Permalink
BUG/MINOR: prevents port conflicts on startup when using hostNetwork
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianonunes committed Sep 2, 2023
1 parent 6d18884 commit a51e3c7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
5 changes: 0 additions & 5 deletions deploy/tests/tnr/routeacl/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,24 @@ stats socket /var/run/haproxy-runtime-api.sock level admin expose-fd listeners
default-path config
peers localinstance
peer local 127.0.0.1:10000
frontend https
mode http
bind 127.0.0.1:8080 name v4
http-request set-var(txn.base) base
use_backend %[var(txn.path_match),field(1,.)]
frontend http
mode http
bind 127.0.0.1:4443 name v4
http-request set-var(txn.base) base
use_backend %[var(txn.path_match),field(1,.)]
frontend healthz
bind 127.0.0.1:1042 name v4
mode http
monitor-uri /healthz
option dontlog-normal
frontend stats
mode http
bind *:1024 name stats
stats enable
stats uri /
stats refresh 10s
Expand Down
5 changes: 0 additions & 5 deletions fs/usr/local/etc/haproxy/haproxy.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,24 @@ defaults
timeout http-keep-alive 60000

peers localinstance
peer local 127.0.0.1:10000

frontend https
mode http
bind 127.0.0.1:8080 name v4
http-request set-var(txn.base) base
use_backend %[var(txn.path_match),field(1,.)]

frontend http
mode http
bind 127.0.0.1:4443 name v4
http-request set-var(txn.base) base
use_backend %[var(txn.path_match),field(1,.)]

frontend healthz
bind 127.0.0.1:1042 name v4
mode http
monitor-uri /healthz
option dontlog-normal

frontend stats
mode http
bind *:1024 name stats
http-request set-var(txn.base) base
http-request use-service prometheus-exporter if { path /metrics }
stats enable
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (c *HAProxyController) updateHAProxy() {
func (c *HAProxyController) setToReady() {
healthzPort := c.osArgs.HealthzBindPort
logger.Panic(c.clientAPIClosure(func() error {
return c.haproxy.FrontendBindEdit("healthz",
return c.haproxy.FrontendBindCreate("healthz",
models.Bind{
BindParams: models.BindParams{
Name: "v4",
Expand All @@ -218,7 +218,7 @@ func (c *HAProxyController) setToReady() {

logger.Panic(c.clientAPIClosure(func() error {
ip := "127.0.0.1"
return c.haproxy.PeerEntryEdit("localinstance",
return c.haproxy.PeerEntryCreate("localinstance",
models.PeerEntry{
Name: "local",
Address: &ip,
Expand All @@ -228,7 +228,7 @@ func (c *HAProxyController) setToReady() {
}))

logger.Panic(c.clientAPIClosure(func() error {
return c.haproxy.FrontendBindEdit("stats",
return c.haproxy.FrontendBindCreate("stats",
models.Bind{
BindParams: models.BindParams{
Name: "stats",
Expand Down
1 change: 1 addition & 0 deletions pkg/haproxy/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type HAProxyClient interface { //nolint:interfacebloat
GlobalPushConfiguration(models.Global) error
GlobalCfgSnippet(snippet []string) error
GetMap(mapFile string) (*models.Map, error)
PeerEntryCreate(peerSection string, peer models.PeerEntry) error
PeerEntryEdit(peerSection string, peer models.PeerEntry) error
RefreshBackends() (deleted []string, err error)
SetMapContent(mapFile string, payload []string) error
Expand Down
9 changes: 9 additions & 0 deletions pkg/haproxy/api/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,12 @@ func (c *clientNative) PeerEntryEdit(peerSection string, peerEntry models.PeerEn
c.activeTransactionHasChanges = true
return configuration.EditPeerEntry(peerEntry.Name, peerSection, &peerEntry, c.activeTransaction, 0)
}

func (c *clientNative) PeerEntryCreate(peerSection string, peerEntry models.PeerEntry) error {
configuration, err := c.nativeAPI.Configuration()
if err != nil {
return err
}
c.activeTransactionHasChanges = true
return configuration.CreatePeerEntry(peerSection, &peerEntry, c.activeTransaction, 0)
}

0 comments on commit a51e3c7

Please sign in to comment.