Skip to content

Commit 3cb5ea2

Browse files
authored
Merge pull request #942 from l1b0k/feat/enahnce
feat(eni): add IPStatusInvalid and update status handling for invalid…
2 parents fe8cdd8 + 5465d9e commit 3cb5ea2

File tree

6 files changed

+90
-4
lines changed

6 files changed

+90
-4
lines changed

pkg/apis/crds/network.alibabacloud.com_nodes.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ spec:
227227
address.
228228
enum:
229229
- Valid
230+
- Invalid
230231
- Deleting
231232
type: string
232233
required:
@@ -257,6 +258,7 @@ spec:
257258
address.
258259
enum:
259260
- Valid
261+
- Invalid
260262
- Deleting
261263
type: string
262264
required:

pkg/apis/crds/register.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func getCRD(name string) apiextensionsv1.CustomResourceDefinition {
5858
version = "v0.1.0"
5959
case CRDNode:
6060
crdBytes = crdsNode
61-
version = "v0.6.0"
61+
version = "v0.6.1"
6262
case CRDNodeRuntime:
6363
crdBytes = crdsNodeRuntime
6464
version = "v0.1.0"

pkg/apis/network.alibabacloud.com/v1beta1/node_types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ const (
3030
)
3131

3232
// IPStatus representing the status of an IP address.
33-
// +kubebuilder:validation:Enum=Valid;Deleting
33+
// +kubebuilder:validation:Enum=Valid;Invalid;Deleting
3434
type IPStatus string
3535

3636
const (
3737
IPStatusValid IPStatus = "Valid"
38+
IPStatusInvalid IPStatus = "Invalid"
3839
IPStatusDeleting IPStatus = "Deleting"
3940
)
4041

pkg/controller/multi-ip/node/eni.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,19 @@ func mergeIPMap(log logr.Logger, remote, current map[string]*networkv1beta1.IP)
168168
for k := range current {
169169
_, ok := remote[k]
170170
if !ok {
171-
log.Info("sync eni with remote, delete ip from local", "ip", k)
172-
delete(current, k)
171+
ip := current[k]
172+
if ip.Primary {
173+
log.Error(nil, "primary ip not in remote, but can not delete it", "ip", k)
174+
continue
175+
}
176+
177+
if ip.PodID != "" {
178+
ip.Status = networkv1beta1.IPStatusInvalid
179+
log.Info("ip not in remote,but in use mark as invalid", "ip", k)
180+
} else {
181+
log.Info("sync eni with remote, delete ip from local", "ip", k)
182+
delete(current, k)
183+
}
173184
}
174185
}
175186

pkg/controller/multi-ip/node/eni_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,75 @@ func Test_mergeIPMap(t *testing.T) {
227227
},
228228
},
229229
},
230+
{
231+
name: "eflo ip not found in temote but in use",
232+
args: args{
233+
log: logr.Discard(),
234+
remote: map[string]*networkv1beta1.IP{
235+
"ipName": {
236+
IP: "",
237+
IPName: "ipName",
238+
Status: networkv1beta1.IPStatusDeleting,
239+
},
240+
"ipName2": {
241+
IP: "127.0.0.1",
242+
IPName: "ipName2",
243+
Status: networkv1beta1.IPStatusValid,
244+
},
245+
},
246+
current: map[string]*networkv1beta1.IP{
247+
"1": {
248+
IP: "1",
249+
PodID: "foo",
250+
PodUID: "bar",
251+
Status: networkv1beta1.IPStatusValid,
252+
},
253+
},
254+
},
255+
expect: map[string]*networkv1beta1.IP{
256+
"ipName": {
257+
IP: "",
258+
IPName: "ipName",
259+
Status: networkv1beta1.IPStatusDeleting,
260+
},
261+
"ipName2": {
262+
IP: "127.0.0.1",
263+
IPName: "ipName2",
264+
Status: networkv1beta1.IPStatusValid,
265+
},
266+
"1": {
267+
IP: "1",
268+
PodID: "foo",
269+
PodUID: "bar",
270+
Status: networkv1beta1.IPStatusInvalid,
271+
},
272+
},
273+
},
274+
{
275+
name: "primary case",
276+
args: args{
277+
log: logr.Discard(),
278+
remote: map[string]*networkv1beta1.IP{
279+
// somehow primary ip is not in remote
280+
},
281+
current: map[string]*networkv1beta1.IP{
282+
"ipName": {
283+
IP: "",
284+
IPName: "ipName",
285+
Primary: true,
286+
Status: networkv1beta1.IPStatusValid,
287+
},
288+
},
289+
},
290+
expect: map[string]*networkv1beta1.IP{
291+
"ipName": {
292+
IP: "",
293+
IPName: "ipName",
294+
Primary: true,
295+
Status: networkv1beta1.IPStatusValid,
296+
},
297+
},
298+
},
230299
}
231300
for _, tt := range tests {
232301
t.Run(tt.name, func(t *testing.T) {

pkg/controller/multi-ip/node/pool.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,9 @@ func releasePodNotFound(ctx context.Context, c client.Client, nodeName string, p
646646
l.Info("pod released", "pod", v.IP.PodID, "ip", v.IP.IP)
647647
v.IP.PodID = ""
648648
v.IP.PodUID = ""
649+
if v.IP.Status == networkv1beta1.IPStatusInvalid && !v.IP.Primary {
650+
v.IP.Status = networkv1beta1.IPStatusDeleting
651+
}
649652
}
650653
}
651654
}

0 commit comments

Comments
 (0)