Skip to content

Commit

Permalink
MINOR: support thread pin on frontend/status
Browse files Browse the repository at this point in the history
  • Loading branch information
cxfcxf authored and oktalz committed Jul 30, 2024
1 parent 5fbf0b2 commit 5f1b949
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 24 deletions.
8 changes: 5 additions & 3 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ func (c *HAProxyController) setToReady() {
return c.haproxy.FrontendBindCreate("healthz",
models.Bind{
BindParams: models.BindParams{
Name: "v4",
Name: "v4",
Thread: c.osArgs.HealthzBindThread,
},
Address: fmt.Sprintf("0.0.0.0:%d", healthzPort),
})
Expand All @@ -235,8 +236,9 @@ func (c *HAProxyController) setToReady() {
return c.haproxy.FrontendBindCreate("healthz",
models.Bind{
BindParams: models.BindParams{
Name: "v6",
V4v6: true,
Name: "v6",
V4v6: true,
Thread: c.osArgs.HealthzBindThread,
},
Address: fmt.Sprintf(":::%d", healthzPort),
})
Expand Down
18 changes: 10 additions & 8 deletions pkg/controller/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,16 @@ func (c *HAProxyController) startupHandlers() error {
handlers := []UpdateHandler{
handler.GlobalCfg{},
handler.HTTPBind{
HTTP: !c.osArgs.DisableHTTP,
HTTPS: !c.osArgs.DisableHTTPS,
IPv4: !c.osArgs.DisableIPV4,
IPv6: !c.osArgs.DisableIPV6,
HTTPPort: c.osArgs.HTTPBindPort,
HTTPSPort: c.osArgs.HTTPSBindPort,
IPv4Addr: c.osArgs.IPV4BindAddr,
IPv6Addr: c.osArgs.IPV6BindAddr,
HTTP: !c.osArgs.DisableHTTP,
HTTPS: !c.osArgs.DisableHTTPS,
IPv4: !c.osArgs.DisableIPV4,
IPv6: !c.osArgs.DisableIPV6,
HTTPPort: c.osArgs.HTTPBindPort,
HTTPSPort: c.osArgs.HTTPSBindPort,
IPv4Addr: c.osArgs.IPV4BindAddr,
IPv6Addr: c.osArgs.IPV6BindAddr,
HTTPBindThread: c.osArgs.HTTPBindThread,
HTTPSBindThread: c.osArgs.HTTPSBindThread,
},
}

Expand Down
42 changes: 29 additions & 13 deletions pkg/handler/http-bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,38 @@ import (
)

type HTTPBind struct {
IPv4Addr string
IPv6Addr string
HTTPPort int64
HTTPSPort int64
HTTP bool
HTTPS bool
IPv4 bool
IPv6 bool
IPv4Addr string
IPv6Addr string
HTTPPort int64
HTTPSPort int64
HTTP bool
HTTPS bool
IPv4 bool
IPv6 bool
HTTPBindThread string
HTTPSBindThread string
}

type PortAndThread struct {
Port int64
Thread string
}

func (handler HTTPBind) Update(k store.K8s, h haproxy.HAProxy, a annotations.Annotations) (err error) {
var errors utils.Errors
frontends := make(map[string]int64, 2)
frontends := make(map[string]PortAndThread, 2)
protos := make(map[string]string, 2)
if handler.HTTP {
frontends[h.FrontHTTP] = handler.HTTPPort
frontends[h.FrontHTTP] = PortAndThread{
Port: handler.HTTPPort,
Thread: handler.HTTPBindThread,
}
}
if handler.HTTPS {
frontends[h.FrontHTTPS] = handler.HTTPSPort
frontends[h.FrontHTTPS] = PortAndThread{
Port: handler.HTTPSPort,
Thread: handler.HTTPSBindThread,
}
}
if handler.IPv4 {
protos["v4"] = handler.IPv4Addr
Expand All @@ -61,11 +74,14 @@ func (handler HTTPBind) Update(k store.K8s, h haproxy.HAProxy, a annotations.Ann
Address: ":::1024",
}))
}
for ftName, ftPort := range frontends {
for ftName, ftPortAndThread := range frontends {
ftPort := ftPortAndThread.Port
thread := ftPortAndThread.Thread
for proto, addr := range protos {
bind := models.Bind{
BindParams: models.BindParams{
Name: proto,
Name: proto,
Thread: thread,
},
Address: addr,
Port: utils.PtrInt64(ftPort),
Expand Down
3 changes: 3 additions & 0 deletions pkg/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,12 @@ type OSArgs struct {
ControllerPort int `long:"controller-port" description:"port to listen on for controller data: prometheus, pprof" default:"6060"`
HTTPBindPort int64 `long:"http-bind-port" default:"8080" description:"port to listen on for HTTP traffic"`
HTTPSBindPort int64 `long:"https-bind-port" default:"8443" description:"port to listen on for HTTPS traffic"`
HTTPBindThread string `long:"http-bind-thread" description:"default http service bind thread params eg: 1-1" default:""`
HTTPSBindThread string `long:"https-bind-thread" description:"default https service bind thread params eg: 1-1" default:""`
SyncPeriod time.Duration `long:"sync-period" default:"5s" description:"Sets the period at which the controller syncs HAProxy configuration file"`
CacheResyncPeriod time.Duration `long:"cache-resync-period" default:"10m" description:"Sets the underlying Shared Informer resync period: resyncing controller with informers cache"`
HealthzBindPort int64 `long:"healthz-bind-port" default:"1042" description:"port to listen on for probes"`
HealthzBindThread string `long:"healthz-bind-thread" description:"default healthz service bind thread params eg: 1-1" default:""`
LogLevel LogLevelValue `long:"log" default:"info" description:"level of log messages you can see"`
DisableIPV4 bool `long:"disable-ipv4" description:"toggle to disable the IPv4 protocol from all frontends"`
External bool `short:"e" long:"external" description:"use as external Ingress Controller (out of k8s cluster)"`
Expand Down

0 comments on commit 5f1b949

Please sign in to comment.