Skip to content

Commit b6fa16c

Browse files
committed
Support for LB end-point selection persistence with timeout - patch3
1 parent e3c3ff0 commit b6fa16c

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

api/loxinlp/ipvs.go

+23-21
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ type ipvsEndPoint struct {
4545
}
4646

4747
type ipVSEntry struct {
48-
Key ipVSKey
48+
key ipVSKey
4949
sel cmn.EpSelect
5050
mode cmn.LBMode
5151
pType string
52-
InValid bool
53-
EndPoints []ipvsEndPoint
52+
timeout uint32
53+
inValid bool
54+
endPoints []ipvsEndPoint
5455
}
5556

5657
type IPVSH struct {
@@ -85,6 +86,7 @@ func (ctx *IPVSH) buildIPVSDB() []*ipVSEntry {
8586

8687
newEntry.sel = cmn.LbSelRr
8788
newEntry.pType = ""
89+
newEntry.timeout = svc.Timeout
8890
if svc.Flags&0x1 == 0x1 {
8991
newEntry.sel = cmn.LbSelRrPersist
9092
}
@@ -110,18 +112,18 @@ func (ctx *IPVSH) buildIPVSDB() []*ipVSEntry {
110112

111113
key := ipVSKey{Address: svc.Address.String(), Protocol: proto, Port: svc.Port}
112114
for _, endPoint := range endPoints {
113-
newEntry.EndPoints = append(newEntry.EndPoints, ipvsEndPoint{EpIP: endPoint.Address.String(), EpPort: endPoint.Port, Weight: uint8(endPoint.Weight)})
115+
newEntry.endPoints = append(newEntry.endPoints, ipvsEndPoint{EpIP: endPoint.Address.String(), EpPort: endPoint.Port, Weight: uint8(endPoint.Weight)})
114116
}
115117

116-
if len(newEntry.EndPoints) != 0 {
118+
if len(newEntry.endPoints) != 0 {
117119
if eEnt := ctx.RMap[key]; eEnt != nil {
118-
if reflect.DeepEqual(eEnt.EndPoints, newEntry.EndPoints) {
119-
eEnt.InValid = false
120+
if reflect.DeepEqual(eEnt.endPoints, newEntry.endPoints) {
121+
eEnt.inValid = false
120122
continue
121123
}
122124
}
123125

124-
newEntry.Key = key
126+
newEntry.key = key
125127
ipVSList = append(ipVSList, &newEntry)
126128
}
127129
}
@@ -136,38 +138,38 @@ func IPVSSync() {
136138
case <-ipVSCtx.ticker.C:
137139

138140
for _, ent := range ipVSCtx.RMap {
139-
ent.InValid = true
141+
ent.inValid = true
140142
}
141143

142144
ipVSList := ipVSCtx.buildIPVSDB()
143145

144146
for _, ent := range ipVSCtx.RMap {
145-
if ent.InValid {
146-
name := fmt.Sprintf("ipvs_%s:%d-%s", ent.Key.Address, ent.Key.Port, ent.Key.Protocol)
147-
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, ProbeType: ent.pType}}
147+
if ent.inValid {
148+
name := fmt.Sprintf("ipvs_%s:%d-%s", ent.key.Address, ent.key.Port, ent.key.Protocol)
149+
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, ProbeType: ent.pType}}
148150
_, err := hooks.NetLbRuleDel(&lbrule)
149151
if err != nil {
150-
tk.LogIt(tk.LogError, "IPVS LB %v delete failed\n", ent.Key)
152+
tk.LogIt(tk.LogError, "IPVS LB %v delete failed\n", ent.key)
151153
}
152-
tk.LogIt(tk.LogInfo, "IPVS ent %v deleted\n", ent.Key)
153-
delete(ipVSCtx.RMap, ent.Key)
154+
tk.LogIt(tk.LogInfo, "IPVS ent %v deleted\n", ent.key)
155+
delete(ipVSCtx.RMap, ent.key)
154156
}
155157
}
156158

157159
for _, newEnt := range ipVSList {
158-
name := fmt.Sprintf("ipvs_%s:%d-%s", newEnt.Key.Address, newEnt.Key.Port, newEnt.Key.Protocol)
159-
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, ProbeType: newEnt.pType}}
160-
for _, ep := range newEnt.EndPoints {
160+
name := fmt.Sprintf("ipvs_%s:%d-%s", newEnt.key.Address, newEnt.key.Port, newEnt.key.Protocol)
161+
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, ProbeType: newEnt.pType, PersistTimeout: newEnt.timeout}}
162+
for _, ep := range newEnt.endPoints {
161163
lbrule.Eps = append(lbrule.Eps, cmn.LbEndPointArg{EpIP: ep.EpIP, EpPort: ep.EpPort, Weight: 1})
162164
}
163165

164166
_, err := hooks.NetLbRuleAdd(&lbrule)
165167
if err != nil {
166-
tk.LogIt(tk.LogError, "IPVS LB %v add failed\n", newEnt.Key)
168+
tk.LogIt(tk.LogError, "IPVS LB %v add failed\n", newEnt.key)
167169
continue
168170
}
169-
ipVSCtx.RMap[newEnt.Key] = newEnt
170-
tk.LogIt(tk.LogError, "IPVS ent %v added\n", newEnt.Key)
171+
ipVSCtx.RMap[newEnt.key] = newEnt
172+
tk.LogIt(tk.LogError, "IPVS ent %v added\n", newEnt.key)
171173
}
172174
}
173175
}

0 commit comments

Comments
 (0)