@@ -45,12 +45,13 @@ type ipvsEndPoint struct {
45
45
}
46
46
47
47
type ipVSEntry struct {
48
- Key ipVSKey
48
+ key ipVSKey
49
49
sel cmn.EpSelect
50
50
mode cmn.LBMode
51
51
pType string
52
- InValid bool
53
- EndPoints []ipvsEndPoint
52
+ timeout uint32
53
+ inValid bool
54
+ endPoints []ipvsEndPoint
54
55
}
55
56
56
57
type IPVSH struct {
@@ -85,6 +86,7 @@ func (ctx *IPVSH) buildIPVSDB() []*ipVSEntry {
85
86
86
87
newEntry .sel = cmn .LbSelRr
87
88
newEntry .pType = ""
89
+ newEntry .timeout = svc .Timeout
88
90
if svc .Flags & 0x1 == 0x1 {
89
91
newEntry .sel = cmn .LbSelRrPersist
90
92
}
@@ -110,18 +112,18 @@ func (ctx *IPVSH) buildIPVSDB() []*ipVSEntry {
110
112
111
113
key := ipVSKey {Address : svc .Address .String (), Protocol : proto , Port : svc .Port }
112
114
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 )})
114
116
}
115
117
116
- if len (newEntry .EndPoints ) != 0 {
118
+ if len (newEntry .endPoints ) != 0 {
117
119
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
120
122
continue
121
123
}
122
124
}
123
125
124
- newEntry .Key = key
126
+ newEntry .key = key
125
127
ipVSList = append (ipVSList , & newEntry )
126
128
}
127
129
}
@@ -136,38 +138,38 @@ func IPVSSync() {
136
138
case <- ipVSCtx .ticker .C :
137
139
138
140
for _ , ent := range ipVSCtx .RMap {
139
- ent .InValid = true
141
+ ent .inValid = true
140
142
}
141
143
142
144
ipVSList := ipVSCtx .buildIPVSDB ()
143
145
144
146
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 }}
148
150
_ , err := hooks .NetLbRuleDel (& lbrule )
149
151
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 )
151
153
}
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 )
154
156
}
155
157
}
156
158
157
159
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 {
161
163
lbrule .Eps = append (lbrule .Eps , cmn.LbEndPointArg {EpIP : ep .EpIP , EpPort : ep .EpPort , Weight : 1 })
162
164
}
163
165
164
166
_ , err := hooks .NetLbRuleAdd (& lbrule )
165
167
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 )
167
169
continue
168
170
}
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 )
171
173
}
172
174
}
173
175
}
0 commit comments