Skip to content

Commit 1022b4a

Browse files
committed
BUG/MEDIUM: reload: wait until reload is done
to avoid potential issues with reading files on fs, wait until reload is done
1 parent 15aa01e commit 1022b4a

File tree

4 files changed

+78
-14
lines changed

4 files changed

+78
-14
lines changed

fs/etc/s6-overlay/s6-rc.d/haproxy/run

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ fi
2323

2424
echo "Memory limit for HAProxy: ${MEMLIMIT}MiB"
2525

26+
# if master socket is changed, that needs to be aligned in pkg/haproxy/process/interface.go
2627
exec /usr/local/sbin/haproxy -W -db -m "${MEMLIMIT}" -S /var/run/haproxy-master.sock,level,admin -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/haproxy-aux.cfg

pkg/haproxy/process/interface.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import (
1313

1414
var logger = utils.GetLogger()
1515

16+
// MUST be the same as in fs/etc/s6-overlay/s6-rc.d/haproxy/run
17+
const MASTER_SOCKET_PATH = "/var/run/haproxy-master.sock" //nolint:stylecheck
18+
1619
type Process interface {
1720
Service(action string) (err error)
1821
UseAuxFile(useAuxFile bool)
@@ -22,16 +25,9 @@ type Process interface {
2225
func New(env env.Env, osArgs utils.OSArgs, auxCfgFile string, api api.HAProxyClient) (p Process) { //nolint:ireturn
2326
switch {
2427
case osArgs.UseWiths6Overlay:
25-
p = &s6Control{
26-
Env: env,
27-
OSArgs: osArgs,
28-
API: api,
29-
}
28+
p = newS6Control(api, env, osArgs)
3029
case osArgs.UseWithPebble:
31-
p = &pebbleControl{
32-
Env: env,
33-
OSArgs: osArgs,
34-
}
30+
p = newPebbleControl(env, osArgs)
3531
default:
3632
p = &directControl{
3733
Env: env,

pkg/haproxy/process/pebble.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,42 @@
11
package process
22

33
import (
4+
"context"
45
"fmt"
56
"os"
67
"os/exec"
78

9+
"github.com/haproxytech/client-native/v5/runtime"
10+
"github.com/haproxytech/client-native/v5/runtime/options"
811
"github.com/haproxytech/kubernetes-ingress/pkg/haproxy/api"
912
"github.com/haproxytech/kubernetes-ingress/pkg/haproxy/env"
1013
"github.com/haproxytech/kubernetes-ingress/pkg/utils"
1114
)
1215

1316
type pebbleControl struct {
14-
Env env.Env
15-
OSArgs utils.OSArgs
17+
Env env.Env
18+
OSArgs utils.OSArgs
19+
masterSocket runtime.Runtime
20+
masterSocketValid bool
21+
logger utils.Logger
22+
}
23+
24+
func newPebbleControl(env env.Env, osArgs utils.OSArgs) *pebbleControl {
25+
pb := pebbleControl{
26+
Env: env,
27+
OSArgs: osArgs,
28+
logger: utils.GetLogger(),
29+
}
30+
31+
masterSocket, err := runtime.New(context.Background(), options.MasterSocket(MASTER_SOCKET_PATH, 1))
32+
if err != nil {
33+
pb.logger.Error(err)
34+
return &pb
35+
}
36+
pb.masterSocketValid = true
37+
pb.masterSocket = masterSocket
38+
39+
return &pb
1640
}
1741

1842
func (d *pebbleControl) Service(action string) error {
@@ -30,6 +54,15 @@ func (d *pebbleControl) Service(action string) error {
3054
// no need to stop it (pebble)
3155
return nil
3256
case "reload":
57+
if d.masterSocketValid {
58+
msg, err := d.masterSocket.Reload()
59+
if err != nil {
60+
d.logger.Error(err)
61+
}
62+
d.logger.Debug("Reload done")
63+
d.logger.Debug(msg)
64+
return err
65+
}
3366
cmd = exec.Command("pebble", "signal", "SIGUSR2", "haproxy")
3467
cmd.Stdout = os.Stdout
3568
cmd.Stderr = os.Stderr

pkg/haproxy/process/s6-overlay.go

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,44 @@
11
package process
22

33
import (
4+
"context"
45
"fmt"
56
"os"
67
"os/exec"
78

9+
"github.com/haproxytech/client-native/v5/runtime"
10+
"github.com/haproxytech/client-native/v5/runtime/options"
811
"github.com/haproxytech/kubernetes-ingress/pkg/haproxy/api"
912
"github.com/haproxytech/kubernetes-ingress/pkg/haproxy/env"
1013
"github.com/haproxytech/kubernetes-ingress/pkg/utils"
1114
)
1215

1316
type s6Control struct {
14-
API api.HAProxyClient
15-
Env env.Env
16-
OSArgs utils.OSArgs
17+
API api.HAProxyClient
18+
Env env.Env
19+
OSArgs utils.OSArgs
20+
masterSocket runtime.Runtime
21+
masterSocketValid bool
22+
logger utils.Logger
23+
}
24+
25+
func newS6Control(api api.HAProxyClient, env env.Env, osArgs utils.OSArgs) *s6Control {
26+
sc := s6Control{
27+
API: api,
28+
Env: env,
29+
OSArgs: osArgs,
30+
logger: utils.GetLogger(),
31+
}
32+
33+
masterSocket, err := runtime.New(context.Background(), options.MasterSocket(MASTER_SOCKET_PATH, 1))
34+
if err != nil {
35+
sc.logger.Error(err)
36+
return &sc
37+
}
38+
sc.masterSocketValid = true
39+
sc.masterSocket = masterSocket
40+
41+
return &sc
1742
}
1843

1944
func (d *s6Control) Service(action string) error {
@@ -31,6 +56,15 @@ func (d *s6Control) Service(action string) error {
3156
// no need to stop it (s6)
3257
return nil
3358
case "reload":
59+
if d.masterSocketValid {
60+
msg, err := d.masterSocket.Reload()
61+
if err != nil {
62+
d.logger.Error(err)
63+
}
64+
d.logger.Debug(msg)
65+
return err
66+
}
67+
3468
cmd = exec.Command("s6-svc", "-2", "/run/service/haproxy")
3569
cmd.Stdout = os.Stdout
3670
cmd.Stderr = os.Stderr

0 commit comments

Comments
 (0)