From bf2f9aaee575df9f16609e3fabd9f3892d13f48f Mon Sep 17 00:00:00 2001 From: l1b0k Date: Mon, 26 Feb 2024 10:32:22 +0800 Subject: [PATCH] fix release ipv6 Signed-off-by: l1b0k --- pkg/eni/local.go | 2 +- pkg/eni/local_test.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pkg/eni/local.go b/pkg/eni/local.go index 9eae21cc..2540efe3 100644 --- a/pkg/eni/local.go +++ b/pkg/eni/local.go @@ -403,7 +403,7 @@ func (l *Local) Release(ctx context.Context, cni *daemon.CNI, request NetworkRes log.Info("release ipv4", "ipv4", res.IP.IPv4) } if res.IP.IPv6.IsValid() { - l.ipv4.Release(cni.PodID, res.IP.IPv6) + l.ipv6.Release(cni.PodID, res.IP.IPv6) log.Info("release ipv6", "ipv6", res.IP.IPv6) } diff --git a/pkg/eni/local_test.go b/pkg/eni/local_test.go index a2fe5a6d..01b81141 100644 --- a/pkg/eni/local_test.go +++ b/pkg/eni/local_test.go @@ -83,3 +83,26 @@ func TestLocal_Release_DifferentENIID(t *testing.T) { assert.False(t, local.Release(context.Background(), cni, request)) } + +func TestLocal_Release_ValidIPv4_ReleaseIPv6(t *testing.T) { + local := NewLocalTest(&daemon.ENI{ID: "eni-1"}, nil, &types.PoolConfig{}) + request := &LocalIPResource{ + ENI: daemon.ENI{ID: "eni-1"}, + IP: types.IPSet2{IPv4: netip.MustParseAddr("192.0.2.1"), IPv6: netip.MustParseAddr("fd00:46dd:e::1")}, + } + cni := &daemon.CNI{PodID: "pod-1"} + + local.ipv4.Add(NewValidIP(netip.MustParseAddr("192.0.2.1"), false)) + local.ipv4[netip.MustParseAddr("192.0.2.1")].Allocate("pod-1") + + local.ipv6.Add(NewValidIP(netip.MustParseAddr("fd00:46dd:e::1"), false)) + local.ipv6[netip.MustParseAddr("fd00:46dd:e::1")].Allocate("pod-1") + + assert.True(t, local.Release(context.Background(), cni, request)) + + assert.Equal(t, ipStatusValid, local.ipv4[netip.MustParseAddr("192.0.2.1")].status) + assert.Equal(t, "", local.ipv4[netip.MustParseAddr("192.0.2.1")].podID) + + assert.Equal(t, ipStatusValid, local.ipv6[netip.MustParseAddr("fd00:46dd:e::1")].status) + assert.Equal(t, "", local.ipv6[netip.MustParseAddr("fd00:46dd:e::1")].podID) +}