Skip to content

Commit 20b3f38

Browse files
ivanmatmatiMo3m3n
authored andcommitted
MINOR: add HAProxyClient to controller builder
1 parent d17a5c8 commit 20b3f38

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

pkg/controller/builder.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/prometheus/client_golang/prometheus/promhttp"
1010

1111
"github.com/haproxytech/kubernetes-ingress/pkg/haproxy"
12+
"github.com/haproxytech/kubernetes-ingress/pkg/haproxy/api"
1213
"github.com/haproxytech/kubernetes-ingress/pkg/haproxy/config"
1314
"github.com/haproxytech/kubernetes-ingress/pkg/haproxy/process"
1415
"github.com/haproxytech/kubernetes-ingress/pkg/ingress"
@@ -19,6 +20,7 @@ import (
1920

2021
type Builder struct {
2122
osArgs utils.OSArgs
23+
haproxyClient api.HAProxyClient
2224
haproxyEnv config.Env
2325
haproxyProcess process.Process
2426
haproxyCfgFile []byte
@@ -51,6 +53,11 @@ func (builder *Builder) WithHAProxyProcess(process process.Process) *Builder {
5153
return builder
5254
}
5355

56+
func (builder *Builder) WithHaproxyClient(haproxyClient api.HAProxyClient) *Builder {
57+
builder.haproxyClient = haproxyClient
58+
return builder
59+
}
60+
5461
func (builder *Builder) WithEventChan(eventChan chan k8s.SyncDataEvent) *Builder {
5562
builder.eventChan = eventChan
5663
return builder
@@ -104,7 +111,7 @@ func (builder *Builder) Build() *HAProxyController {
104111
}()
105112
}
106113

107-
haproxy, err := haproxy.New(builder.osArgs, builder.haproxyEnv, builder.haproxyCfgFile, builder.haproxyProcess)
114+
haproxy, err := haproxy.New(builder.osArgs, builder.haproxyEnv, builder.haproxyCfgFile, builder.haproxyProcess, builder.haproxyClient)
108115
logger.Panic(err)
109116

110117
prefix, errPrefix := utils.GetPodPrefix(os.Getenv("POD_NAME"))

pkg/haproxy/main.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type HAProxy struct {
2424
*config.Config
2525
}
2626

27-
func New(osArgs utils.OSArgs, env config.Env, cfgFile []byte, p process.Process) (h HAProxy, err error) {
27+
func New(osArgs utils.OSArgs, env config.Env, cfgFile []byte, p process.Process, client api.HAProxyClient) (h HAProxy, err error) {
2828
err = (&env).Init(osArgs)
2929
if err != nil {
3030
err = fmt.Errorf("failed to initialize haproxy environment: %w", err)
@@ -43,11 +43,12 @@ func New(osArgs utils.OSArgs, env config.Env, cfgFile []byte, p process.Process)
4343
err = fmt.Errorf("failed to initialize haproxy config state: %w", err)
4444
return
4545
}
46-
47-
h.HAProxyClient, err = api.New(h.CfgDir, h.MainCFGFile, h.Binary, h.RuntimeSocket)
48-
if err != nil {
49-
err = fmt.Errorf("failed to initialize haproxy API client: %w", err)
50-
return
46+
if client == nil {
47+
h.HAProxyClient, err = api.New(h.CfgDir, h.MainCFGFile, h.Binary, h.RuntimeSocket)
48+
if err != nil {
49+
err = fmt.Errorf("failed to initialize haproxy API client: %w", err)
50+
return
51+
}
5152
}
5253
if p == nil {
5354
h.Process = process.New(h.Env, osArgs, h.AuxCFGFile, h.HAProxyClient)

0 commit comments

Comments
 (0)