Skip to content

Commit

Permalink
Merge pull request #511 from TrekkieCoder/main
Browse files Browse the repository at this point in the history
PR: gh-483 For node-port services, use one-arm mode as default
  • Loading branch information
UltraInstinct14 authored Jan 29, 2024
2 parents bb6b2f8 + de3a315 commit f819638
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions api/loxinlp/ipvs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ import (
tk "github.com/loxilb-io/loxilib"
)

const (
K8sNodePortMin = 30000
K8sNodePortMax = 32768
)

type ipVSKey struct {
Address string
Protocol string
Expand All @@ -41,7 +46,8 @@ type ipvsEndPoint struct {

type ipVSEntry struct {
Key ipVSKey
Type string
sel cmn.EpSelect
mode cmn.LBMode
InValid bool
EndPoints []ipvsEndPoint
}
Expand Down Expand Up @@ -72,13 +78,13 @@ func (ctx *IpVSH) BuildIpVSDB() []*ipVSEntry {
continue
}

newEntry.Type = svc.SchedName
if svc.SchedName != "rr" {
continue
}

newEntry.sel = cmn.LbSelRr
if svc.Flags&0x1 == 0x1 {
newEntry.Type = "rrp"
newEntry.sel = cmn.LbSelRrPersist
}

proto := ""
Expand All @@ -94,6 +100,11 @@ func (ctx *IpVSH) BuildIpVSDB() []*ipVSEntry {
continue
}

newEntry.mode = cmn.LBModeDefault
if svc.Port >= K8sNodePortMin && svc.Port <= K8sNodePortMax {
newEntry.mode = cmn.LBModeOneArm
}

key := ipVSKey{Address: svc.Address.String(), Protocol: proto, Port: svc.Port}
for _, endPoint := range endPoints {
newEntry.EndPoints = append(newEntry.EndPoints, ipvsEndPoint{EpIP: endPoint.Address.String(), EpPort: endPoint.Port, Weight: uint8(endPoint.Weight)})
Expand Down Expand Up @@ -130,7 +141,7 @@ func IpVSSync() {
for _, ent := range ipVSCtx.RMap {
if ent.InValid {
name := fmt.Sprintf("ipvs_%s:%d-%s", ent.Key.Address, ent.Key.Port, ent.Key.Protocol)
lbrule := cmn.LbRuleMod{Serv: cmn.LbServiceArg{ServIP: ent.Key.Address, ServPort: ent.Key.Port, Proto: ent.Key.Protocol, Sel: cmn.LbSelRr, Name: name}}
lbrule := cmn.LbRuleMod{Serv: cmn.LbServiceArg{ServIP: ent.Key.Address, ServPort: ent.Key.Port, Proto: ent.Key.Protocol, Sel: ent.sel, Mode: ent.mode, Name: name}}
_, err := hooks.NetLbRuleDel(&lbrule)
if err != nil {
tk.LogIt(tk.LogError, "IPVS LB %v delete failed\n", ent.Key)
Expand All @@ -141,14 +152,8 @@ func IpVSSync() {
}

for _, newEnt := range ipVSList {

sel := cmn.LbSelRr
if newEnt.Type == "rrp" {
sel = cmn.LbSelRrPersist
}
fmt.Printf("Selection %s\n", newEnt.Type)
name := fmt.Sprintf("ipvs_%s:%d-%s", newEnt.Key.Address, newEnt.Key.Port, newEnt.Key.Protocol)
lbrule := cmn.LbRuleMod{Serv: cmn.LbServiceArg{ServIP: newEnt.Key.Address, ServPort: newEnt.Key.Port, Proto: newEnt.Key.Protocol, Sel: sel, Name: name}}
lbrule := cmn.LbRuleMod{Serv: cmn.LbServiceArg{ServIP: newEnt.Key.Address, ServPort: newEnt.Key.Port, Proto: newEnt.Key.Protocol, Sel: newEnt.sel, Mode: newEnt.mode, Name: name}}
for _, ep := range newEnt.EndPoints {
lbrule.Eps = append(lbrule.Eps, cmn.LbEndPointArg{EpIP: ep.EpIP, EpPort: ep.EpPort, Weight: 1})
}
Expand Down

0 comments on commit f819638

Please sign in to comment.