Skip to content

Commit

Permalink
Merge pull request #351 from TrekkieCoder/main
Browse files Browse the repository at this point in the history
PR - Liveness check type on a per-rule basis (#350)
  • Loading branch information
UltraInstinct14 authored Jul 11, 2023
2 parents dad68cb + b23b5e7 commit ad867e7
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 48 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
12 changes: 12 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
51 changes: 51 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.

6 changes: 6 additions & 0 deletions api/restapi/handler/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func ConfigPostLoadbalancer(params operations.PostConfigLoadbalancerParams) midd
lbRules.Serv.Mode = cmn.LBMode(params.Attr.ServiceArguments.Mode)
lbRules.Serv.InactiveTimeout = uint32(params.Attr.ServiceArguments.InactiveTimeOut)
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 Expand Up @@ -119,6 +123,8 @@ func ConfigGetLoadbalancer(params operations.GetConfigLoadbalancerAllParams) mid
tmpSvc.InactiveTimeOut = int32(lb.Serv.InactiveTimeout)
tmpSvc.Monitor = lb.Serv.Monitor
tmpSvc.Managed = lb.Serv.Managed
tmpSvc.Probetype = lb.Serv.ProbeType
tmpSvc.Probeport = lb.Serv.ProbePort

tmpLB.ServiceArguments = &tmpSvc

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.

13 changes: 13 additions & 0 deletions api/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2166,6 +2166,19 @@ definitions:
monitor:
type: boolean
description: value for monitoring enabled or not
probetype:
type: string
description: probe type for any end-point of this entry
probeport:
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: 8 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +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, http(s)
ProbeType string `json:"probetype"`
// 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
Loading

0 comments on commit ad867e7

Please sign in to comment.