Skip to content

Commit

Permalink
Liveness check type on a per-rule basis (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
TrekkieCoder committed Jul 11, 2023
1 parent 8588d63 commit b23b5e7
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 36 deletions.
25 changes: 24 additions & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import (
)

var (
ApiReady bool
ApiReady bool
ApiShutOk chan bool
)

// RegisterAPIHooks - routine to register interface for api
Expand All @@ -51,6 +52,20 @@ func WaitAPIServerReady() {
}
}

func waitApiServerShutOk() {
for {
select {
case <-ApiShutOk:
return
}
}
}

// ApiServerShutOk - Notifier for server to be shutdown on signals
func ApiServerShutOk() {
ApiShutOk <- true
}

// This file was generated by the swagger tool.
// Make sure not to overwrite this file after you generated it because all your edits would be lost!

Expand All @@ -64,6 +79,10 @@ func RunAPIServer() {
}
}()

if ApiShutOk == nil {
ApiShutOk = make(chan bool)
}

swaggerSpec, err := loads.Embedded(restapi.SwaggerJSON, restapi.FlatSwaggerJSON)
if err != nil {
log.Fatalln(err)
Expand Down Expand Up @@ -101,6 +120,10 @@ func RunAPIServer() {
server.TLSCertificate = options.Opts.TLSCertificate
server.Port = options.Opts.Port
server.TLSPort = options.Opts.TLSPort
api.ServerShutdown = func() {
waitApiServerShutOk()
os.Exit(0)
}
ApiReady = true

if err := server.Serve(); err != nil {
Expand Down
6 changes: 6 additions & 0 deletions api/models/loadbalance_entry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions api/restapi/configure_loxilb_rest_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package restapi
import (
"crypto/tls"
"net/http"
"os"

opts "github.com/loxilb-io/loxilb/options"

Expand Down Expand Up @@ -155,9 +154,7 @@ func configureAPI(api *operations.LoxilbRestAPIAPI) http.Handler {

api.PreServerShutdown = func() {}

api.ServerShutdown = func() {
os.Exit(0)
}
api.ServerShutdown = func() {}

return setupGlobalMiddleware(api.Serve(setupMiddlewares))
}
Expand Down
24 changes: 24 additions & 0 deletions api/restapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions api/restapi/handler/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func ConfigPostLoadbalancer(params operations.PostConfigLoadbalancerParams) midd
lbRules.Serv.Managed = params.Attr.ServiceArguments.Managed
lbRules.Serv.ProbeType = params.Attr.ServiceArguments.Probetype
lbRules.Serv.ProbePort = params.Attr.ServiceArguments.Probeport
lbRules.Serv.ProbeReq = params.Attr.ServiceArguments.Probereq
lbRules.Serv.ProbeResp = params.Attr.ServiceArguments.Proberesp

if lbRules.Serv.Proto == "sctp" {
for _, data := range params.Attr.SecondaryIPs {
Expand Down
33 changes: 7 additions & 26 deletions api/restapi/server.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions api/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2173,6 +2173,12 @@ definitions:
type: integer
format: uint16
description: probe port if probetype is tcp/udp/sctp
probereq:
type: string
description: probe request string
proberesp:
type: string
description: probe response string
managed:
type: boolean
description: externally managed rule or not
Expand Down
8 changes: 6 additions & 2 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,14 @@ type LbServiceArg struct {
InactiveTimeout uint32 `json:"inactiveTimeout"`
// Managed - This rule is managed by external entity e.g k8s
Managed bool `json:"managed"`
// ProbeType - Liveness check type for this rule : ping, tcp, udp, sctp, none
// ProbeType - Liveness check type for this rule : ping, tcp, udp, sctp, none, http(s)
ProbeType string `json:"probetype"`
// ProbePort - Liveness check port number. Only valid for tcp, udp, sctp
// ProbePort - Liveness check port number. Only valid for tcp, udp, sctp, http(s)
ProbePort uint16 `json:"probeport"`
// ProbeReq - Request string for liveness check
ProbeReq string `json:"probereq"`
// ProbeResp - Response string for liveness check
ProbeResp string `json:"proberesp"`
}

// LbEndPointArg - Information related to load-balancer end-point
Expand Down
3 changes: 1 addition & 2 deletions loxinet/loxinet.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
apiserver "github.com/loxilb-io/loxilb/api"
nlp "github.com/loxilb-io/loxilb/api/loxinlp"
prometheus "github.com/loxilb-io/loxilb/api/prometheus"
restapi "github.com/loxilb-io/loxilb/api/restapi"
cmn "github.com/loxilb-io/loxilb/common"
opts "github.com/loxilb-io/loxilb/options"
tk "github.com/loxilb-io/loxilib"
Expand Down Expand Up @@ -185,7 +184,7 @@ func loxiNetTicker() {
} else if sig == syscall.SIGINT || sig == syscall.SIGTERM {
tk.LogIt(tk.LogCritical, "Shutdown on sig %v\n", sig)
mh.dpEbpf.DpEbpfUnInit()
restapi.ServerSigShutOk()
apiserver.ApiServerShutOk()
}
case t := <-mh.ticker.C:
tk.LogIt(-1, "Tick at %v\n", t)
Expand Down
13 changes: 12 additions & 1 deletion loxinet/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ type ruleProbe struct {
actChk bool
prbType string
prbPort uint16
prbReq string
prbResp string
}

type ruleEnt struct {
Expand Down Expand Up @@ -730,6 +732,8 @@ func (R *RuleH) GetNatLbRule() ([]cmn.LbRuleMod, error) {
ret.Serv.Managed = data.managed
ret.Serv.ProbeType = data.hChk.prbType
ret.Serv.ProbePort = data.hChk.prbPort
ret.Serv.ProbeReq = data.hChk.prbReq
ret.Serv.ProbeResp = data.hChk.prbResp

for _, sip := range data.secIP {
ret.SecIPs = append(ret.SecIPs, cmn.LbSecIpArg{SecIP: sip.sIP.String()})
Expand Down Expand Up @@ -808,6 +812,8 @@ func (R *RuleH) modNatEpHost(r *ruleEnt, endpoints []ruleNatEp, doAddOp bool, li
// override per end-point liveness settings
hopts.probeType = r.hChk.prbType
hopts.probePort = r.hChk.prbPort
hopts.probeReq = r.hChk.prbReq
hopts.probeResp = r.hChk.prbResp
} else {
hopts.probeType = pType
hopts.probePort = pPort
Expand Down Expand Up @@ -1138,7 +1144,8 @@ func (R *RuleH) AddNatLbRule(serv cmn.LbServiceArg, servSecIPs []cmn.LbSecIpArg,
e.mark = false
}

if eRule.hChk.prbType != serv.ProbeType || eRule.hChk.prbPort != serv.ProbePort {
if eRule.hChk.prbType != serv.ProbeType || eRule.hChk.prbPort != serv.ProbePort ||
eRule.hChk.prbReq != serv.ProbeReq || eRule.hChk.prbResp != serv.ProbeResp {
ruleChg = true
}

Expand All @@ -1149,6 +1156,8 @@ func (R *RuleH) AddNatLbRule(serv cmn.LbServiceArg, servSecIPs []cmn.LbSecIpArg,
// Update the rule
eRule.hChk.prbType = serv.ProbeType
eRule.hChk.prbPort = serv.ProbePort
eRule.hChk.prbReq = serv.ProbeReq
eRule.hChk.prbResp = serv.ProbeResp
eRule.act.action.(*ruleNatActs).sel = natActs.sel
eRule.act.action.(*ruleNatActs).endPoints = eEps
eRule.act.action.(*ruleNatActs).mode = natActs.mode
Expand Down Expand Up @@ -1180,6 +1189,8 @@ func (R *RuleH) AddNatLbRule(serv cmn.LbServiceArg, servSecIPs []cmn.LbSecIpArg,
// lb end-point health monitoring
r.hChk.prbType = serv.ProbeType
r.hChk.prbPort = serv.ProbePort
r.hChk.prbReq = serv.ProbeReq
r.hChk.prbResp = serv.ProbeResp
r.hChk.actChk = serv.Monitor
r.act.action = &natActs
r.ruleNum, err = R.tables[RtLB].Mark.GetCounter()
Expand Down

0 comments on commit b23b5e7

Please sign in to comment.