Skip to content

Commit 3577793

Browse files
committed
MEDIUM: remove restart of HAProxy
1 parent ea3ffa0 commit 3577793

File tree

7 files changed

+9
-85
lines changed

7 files changed

+9
-85
lines changed

pkg/controller/controller.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,7 @@ func (c *HAProxyController) updateHAProxy() {
183183
c.setToReady()
184184
}
185185

186-
switch {
187-
case instance.NeedRestart():
188-
if err = c.haproxy.Service("restart"); err != nil {
189-
logger.Error(err)
190-
} else {
191-
logger.Info("HAProxy restarted")
192-
}
193-
case instance.NeedReload():
186+
if instance.NeedReload() {
194187
if err = c.haproxy.Service("reload"); err != nil {
195188
logger.Error(err)
196189
} else {

pkg/controller/global.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ func (c *HAProxyController) globalCfg() {
9191
diff := newGlobal.Diff(*global)
9292
if len(diff) != 0 {
9393
logger.Error(c.haproxy.GlobalPushConfiguration(*newGlobal))
94-
instance.Restart("Global config updated: %s", strings.Join(updated, "\n"))
94+
instance.Reload("Global config updated: %s", strings.Join(updated, "\n"))
9595
}
9696
diff = newLg.Diff(lg)
9797
// updated = deep.Equal(newLg, lg)
9898
if len(diff) != 0 {
9999
logger.Error(c.haproxy.GlobalPushLogTargets(newLg))
100-
instance.Restart("Global log targets updated: %s", strings.Join(updated, "\n"))
100+
instance.Reload("Global log targets updated: %s", strings.Join(updated, "\n"))
101101
}
102102
c.globalCfgSnipp()
103103
}
@@ -112,7 +112,7 @@ func (c *HAProxyController) globalCfgSnipp() {
112112
}
113113
updatedSnipp, errSnipp := annotations.UpdateGlobalCfgSnippet(c.haproxy)
114114
logger.Error(errSnipp)
115-
instance.RestartIf(len(updatedSnipp) != 0,
115+
instance.ReloadIf(len(updatedSnipp) != 0,
116116
"Global config-snippet updated: %s", strings.Join(updatedSnipp, "\n"))
117117

118118
updatedSnipp, errSnipp = annotations.UpdateFrontendCfgSnippet(c.haproxy, "http", "https", "stats")

pkg/controller/monitor.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (c *HAProxyController) SyncData() {
3434
case k8s.COMMAND:
3535
c.auxCfgManager()
3636
// create a NeedAction function.
37-
if hadChanges || instance.NeedAction() {
37+
if hadChanges || instance.NeedReload() {
3838
c.updateHAProxy()
3939
hadChanges = false
4040
continue
@@ -91,7 +91,6 @@ func (c *HAProxyController) SyncData() {
9191
}
9292
}
9393

94-
// auxCfgManager returns restart or reload requirement based on state and transition of auxiliary configuration file.
9594
func (c *HAProxyController) auxCfgManager() {
9695
info, errStat := os.Stat(c.haproxy.AuxCFGFile)
9796
var (
@@ -109,7 +108,7 @@ func (c *HAProxyController) auxCfgManager() {
109108
c.haproxy.SetAuxCfgFile(auxCfgFile)
110109
c.haproxy.UseAuxFile(useAuxFile)
111110
// The file exists now (modifTime !=0 otherwise nothing changed case).
112-
instance.RestartIf(c.auxCfgModTime == 0, "auxiliary configuration file created")
111+
instance.ReloadIf(c.auxCfgModTime == 0, "auxiliary configuration file created")
113112
instance.ReloadIf(c.auxCfgModTime != 0, "auxiliary configuration file modified")
114113
c.auxCfgModTime = modifTime
115114
if c.auxCfgModTime != 0 {
@@ -125,7 +124,7 @@ func (c *HAProxyController) auxCfgManager() {
125124
// never existed before
126125
return
127126
}
128-
instance.Restart("Auxiliary HAProxy config '%s' removed", c.haproxy.AuxCFGFile)
127+
instance.Reload("Auxiliary HAProxy config '%s' removed", c.haproxy.AuxCFGFile)
129128
return
130129
}
131130
// File exists

pkg/haproxy/instance/configuration.go

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,21 @@ func Reload(reason string, args ...any) {
1313
DefaultConfigurationManager.SetReload(reason, args...)
1414
}
1515

16-
func Restart(reason string, args ...any) {
17-
DefaultConfigurationManager.SetRestart(reason, args...)
18-
}
19-
2016
func ReloadIf(reload bool, reason string, args ...any) {
2117
DefaultConfigurationManager.SetReloadIf(reload, reason, args...)
2218
}
2319

24-
func RestartIf(restart bool, reason string, args ...any) {
25-
DefaultConfigurationManager.SetRestartIf(restart, reason, args...)
26-
}
27-
2820
func NeedReload() bool {
2921
return DefaultConfigurationManager.NeedReload()
3022
}
3123

32-
func NeedRestart() bool {
33-
return DefaultConfigurationManager.NeedRestart()
34-
}
35-
3624
func Reset() {
3725
DefaultConfigurationManager.Reset()
3826
}
3927

40-
func NeedAction() bool {
41-
return DefaultConfigurationManager.NeedAction()
42-
}
43-
4428
type configurationManagerImpl struct {
45-
logger utils.Logger
46-
reload, restart bool
29+
logger utils.Logger
30+
reload bool
4731
}
4832

4933
func NewConfigurationManager() *configurationManagerImpl {
@@ -60,27 +44,14 @@ func (cmi *configurationManagerImpl) SetReload(reason string, args ...any) {
6044
cmi.logger.InfoSkipCallerf("reload required : "+reason, args...)
6145
}
6246

63-
func (cmi *configurationManagerImpl) SetRestart(reason string, args ...any) {
64-
cmi.restart = true
65-
if !cmi.validReason(reason) {
66-
return
67-
}
68-
cmi.logger.InfoSkipCallerf("restart required : "+reason, args...)
69-
}
70-
7147
func (cmi *configurationManagerImpl) Reset() {
7248
cmi.reload = false
73-
cmi.restart = false
7449
}
7550

7651
func (cmi *configurationManagerImpl) NeedReload() bool {
7752
return cmi.reload
7853
}
7954

80-
func (cmi *configurationManagerImpl) NeedRestart() bool {
81-
return cmi.restart
82-
}
83-
8455
func (cmi *configurationManagerImpl) SetReloadIf(reload bool, reason string, args ...any) {
8556
if !reload {
8657
return
@@ -92,21 +63,6 @@ func (cmi *configurationManagerImpl) SetReloadIf(reload bool, reason string, arg
9263
cmi.logger.InfoSkipCallerf("reload required : "+reason, args...)
9364
}
9465

95-
func (cmi *configurationManagerImpl) SetRestartIf(restart bool, reason string, args ...any) {
96-
if !restart {
97-
return
98-
}
99-
cmi.restart = true
100-
if !cmi.validReason(reason) {
101-
return
102-
}
103-
cmi.logger.InfoSkipCallerf("restart required : "+reason, args...)
104-
}
105-
106-
func (cmi *configurationManagerImpl) NeedAction() bool {
107-
return cmi.NeedReload() || cmi.NeedRestart()
108-
}
109-
11066
func (cmi *configurationManagerImpl) validReason(reason string) bool {
11167
if reason == "" {
11268
errMsg := "empty reason for reload"

pkg/haproxy/process/direct-control.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"os"
66
"os/exec"
7-
"strconv"
87
"syscall"
98

109
"github.com/haproxytech/kubernetes-ingress/pkg/haproxy/api"
@@ -61,19 +60,6 @@ func (d *directControl) Service(action string) (err error) {
6160
return d.Service("start")
6261
}
6362
return process.Signal(syscall.SIGUSR2)
64-
case "restart":
65-
if processErr != nil {
66-
logger.Errorf("haproxy is not running, trying to start it")
67-
return d.Service("start")
68-
}
69-
pid := strconv.Itoa(process.Pid)
70-
cmd = exec.Command(d.Env.Binary, "-S", masterSocketArg, "-f", d.Env.MainCFGFile, "-sf", pid)
71-
if d.useAuxFile {
72-
cmd = exec.Command(d.Env.Binary, "-S", masterSocketArg, "-f", d.Env.MainCFGFile, "-f", d.Env.AuxCFGFile, "-sf", pid)
73-
}
74-
cmd.Stdout = os.Stdout
75-
cmd.Stderr = os.Stderr
76-
return cmd.Run()
7763
default:
7864
return fmt.Errorf("unknown command '%s'", action)
7965
}

pkg/haproxy/process/pebble.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ func (d *pebbleControl) Service(action string) error {
6767
cmd.Stdout = os.Stdout
6868
cmd.Stderr = os.Stderr
6969
return cmd.Run()
70-
case "restart":
71-
cmd = exec.Command("pebble", "restart", "haproxy")
72-
cmd.Stdout = os.Stdout
73-
cmd.Stderr = os.Stderr
74-
return cmd.Run()
7570
default:
7671
return fmt.Errorf("unknown command '%s'", action)
7772
}

pkg/haproxy/process/s6-overlay.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ func (d *s6Control) Service(action string) error {
6969
cmd.Stdout = os.Stdout
7070
cmd.Stderr = os.Stderr
7171
return cmd.Run()
72-
case "restart":
73-
cmd = exec.Command("s6-svc", "-t", "/run/service/haproxy")
74-
cmd.Stdout = os.Stdout
75-
cmd.Stderr = os.Stderr
76-
return cmd.Run()
7772
default:
7873
return fmt.Errorf("unknown command '%s'", action)
7974
}

0 commit comments

Comments
 (0)