From 85445b3d8494930c8e6e53d1ade6950cd061ccd7 Mon Sep 17 00:00:00 2001 From: Fabiano Parente Date: Tue, 5 Sep 2023 13:13:57 -0300 Subject: [PATCH] BUG/MINOR: prevents port conflicts on startup when using hostNetwork Creates new binds (instead of editing them) of the healthz and stats frontends to avoid port conflicts at the first start of the HAProxy when using hostNetwork: true. Since these bind directives are not required, the first start of HAProxy is not affected. --- deploy/tests/integration/base-suite.go | 5 ----- deploy/tests/tnr/routeacl/suite_test.go | 5 ----- fs/usr/local/etc/haproxy/haproxy.cfg | 4 ---- pkg/controller/controller.go | 4 ++-- 4 files changed, 2 insertions(+), 16 deletions(-) diff --git a/deploy/tests/integration/base-suite.go b/deploy/tests/integration/base-suite.go index 3daa4479..07175762 100644 --- a/deploy/tests/integration/base-suite.go +++ b/deploy/tests/integration/base-suite.go @@ -30,7 +30,6 @@ import ( "k8s.io/apimachinery/pkg/watch" ) -//nolint:dupword var haproxyConfig = `global daemon master-worker @@ -43,25 +42,21 @@ peers localinstance 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 diff --git a/deploy/tests/tnr/routeacl/suite_test.go b/deploy/tests/tnr/routeacl/suite_test.go index cd8231a6..3d0ab7cf 100644 --- a/deploy/tests/tnr/routeacl/suite_test.go +++ b/deploy/tests/tnr/routeacl/suite_test.go @@ -62,7 +62,6 @@ func (suite *UseBackendSuite) BeforeTest(suiteName, testName string) { suite.T().Logf("temporary configuration dir %s", suite.test.TempDir) } -//nolint:dupword var haproxyConfig = `global daemon master-worker @@ -75,25 +74,21 @@ peers localinstance 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 diff --git a/fs/usr/local/etc/haproxy/haproxy.cfg b/fs/usr/local/etc/haproxy/haproxy.cfg index c2fd2ff4..0af2c93a 100644 --- a/fs/usr/local/etc/haproxy/haproxy.cfg +++ b/fs/usr/local/etc/haproxy/haproxy.cfg @@ -27,25 +27,21 @@ peers localinstance 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 diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 3b7edb5d..65baa9b4 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -204,7 +204,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", @@ -237,7 +237,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",