Repository: spidernet-io/spiderpool
Pull request #1341 (2023-02-20 07:21:04)

Add flag to IPsDiffSet, IPsDiffSet and IPsIntersectionSet to determine whether the IP addresses result set needs to be sorted
Signed-off-by: iiiceoo <ziqian.xue@daocloud.io>

sonarcloud[bot]: SonarCloud Quality Gate failed.&nbsp; &nbsp; [![Quality Gate failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/failed-16px.png 'Quality Gate failed')](https://sonarcloud.io/dashboard?id=spidernet-io_spiderpool&pullRequest=1341)

[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=spidernet-io_spiderpool&pullRequest=1341&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=spidernet-io_spiderpool&pullRequest=1341&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=spidernet-io_spiderpool&pullRequest=1341&resolved=false&types=BUG)  
[![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=spidernet-io_spiderpool&pullRequest=1341&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=spidernet-io_spiderpool&pullRequest=1341&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=spidernet-io_spiderpool&pullRequest=1341&resolved=false&types=VULNERABILITY)  
[![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=spidernet-io_spiderpool&pullRequest=1341&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=spidernet-io_spiderpool&pullRequest=1341&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=spidernet-io_spiderpool&pullRequest=1341&resolved=false&types=SECURITY_HOTSPOT)  
[![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=spidernet-io_spiderpool&pullRequest=1341&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=spidernet-io_spiderpool&pullRequest=1341&resolved=false&types=CODE_SMELL) [0 Code Smells](https://sonarcloud.io/project/issues?id=spidernet-io_spiderpool&pullRequest=1341&resolved=false&types=CODE_SMELL)

[![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=spidernet-io_spiderpool&pullRequest=1341) No Coverage information  
[![12.6%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/20-16px.png '12.6%')](https://sonarcloud.io/component_measures?id=spidernet-io_spiderpool&pullRequest=1341&metric=new_duplicated_lines_density&view=list) [12.6% Duplication](https://sonarcloud.io/component_measures?id=spidernet-io_spiderpool&pullRequest=1341&metric=new_duplicated_lines_density&view=list)


codecov[bot]: # [Codecov](https://codecov.io/gh/spidernet-io/spiderpool/pull/1341?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spidernet-io) Report
> Merging [#1341](https://codecov.io/gh/spidernet-io/spiderpool/pull/1341?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spidernet-io) (b459a64) into [main](https://codecov.io/gh/spidernet-io/spiderpool/commit/6b3c4734fedbad5e0861d316d615bbb4ae0a148c?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spidernet-io) (6b3c473) will **decrease** coverage by `0.04%`.
> The diff coverage is `51.85%`.

[![Impacted file tree graph](https://codecov.io/gh/spidernet-io/spiderpool/pull/1341/graphs/tree.svg?width=650&height=150&src=pr&token=YKXY2E4Q8G&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spidernet-io)](https://codecov.io/gh/spidernet-io/spiderpool/pull/1341?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spidernet-io)

```diff
@@            Coverage Diff             @@
##             main    #1341      +/-   ##
==========================================
- Coverage   52.56%   52.52%   -0.04%     
==========================================
  Files          44       44              
  Lines        4465     4468       +3     
==========================================
  Hits         2347     2347              
- Misses       2092     2094       +2     
- Partials       26       27       +1     
```

| Flag | Coverage Δ | |
|---|---|---|
| unittests | `52.52% <51.85%> (-0.04%)` | :arrow_down: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spidernet-io#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/spidernet-io/spiderpool/pull/1341?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spidernet-io) | Coverage Δ | |
|---|---|---|
| [pkg/ippoolmanager/ippool\_informer.go](https://codecov.io/gh/spidernet-io/spiderpool/pull/1341?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spidernet-io#diff-cGtnL2lwcG9vbG1hbmFnZXIvaXBwb29sX2luZm9ybWVyLmdv) | `0.00% <0.00%> (ø)` | |
| [pkg/ippoolmanager/ippool\_manager.go](https://codecov.io/gh/spidernet-io/spiderpool/pull/1341?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spidernet-io#diff-cGtnL2lwcG9vbG1hbmFnZXIvaXBwb29sX21hbmFnZXIuZ28=) | `0.00% <0.00%> (ø)` | |
| [pkg/subnetmanager/subnet\_informer.go](https://codecov.io/gh/spidernet-io/spiderpool/pull/1341?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spidernet-io#diff-cGtnL3N1Ym5ldG1hbmFnZXIvc3VibmV0X2luZm9ybWVyLmdv) | `0.00% <0.00%> (ø)` | |
| [pkg/ip/ip.go](https://codecov.io/gh/spidernet-io/spiderpool/pull/1341?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spidernet-io#diff-cGtnL2lwL2lwLmdv) | `94.59% <60.00%> (-2.63%)` | :arrow_down: |
| [pkg/ip/iprange.go](https://codecov.io/gh/spidernet-io/spiderpool/pull/1341?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spidernet-io#diff-cGtnL2lwL2lwcmFuZ2UuZ28=) | `100.00% <100.00%> (ø)` | |
| [pkg/ip/utils.go](https://codecov.io/gh/spidernet-io/spiderpool/pull/1341?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spidernet-io#diff-cGtnL2lwL3V0aWxzLmdv) | `100.00% <100.00%> (ø)` | |
| [pkg/ippoolmanager/ippool\_subnet\_validate.go](https://codecov.io/gh/spidernet-io/spiderpool/pull/1341?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spidernet-io#diff-cGtnL2lwcG9vbG1hbmFnZXIvaXBwb29sX3N1Ym5ldF92YWxpZGF0ZS5nbw==) | `90.47% <100.00%> (ø)` | |
| [pkg/ippoolmanager/ippool\_validate.go](https://codecov.io/gh/spidernet-io/spiderpool/pull/1341?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spidernet-io#diff-cGtnL2lwcG9vbG1hbmFnZXIvaXBwb29sX3ZhbGlkYXRlLmdv) | `94.97% <100.00%> (ø)` | |
| [pkg/subnetmanager/subnet\_validate.go](https://codecov.io/gh/spidernet-io/spiderpool/pull/1341?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spidernet-io#diff-cGtnL3N1Ym5ldG1hbmFnZXIvc3VibmV0X3ZhbGlkYXRlLmdv) | `100.00% <100.00%> (ø)` | |


Patch:
diff --git a/pkg/ip/ip.go b/pkg/ip/ip.go
index 1d576c227..7278be1ef 100644
--- a/pkg/ip/ip.go
+++ b/pkg/ip/ip.go
@@ -80,7 +80,9 @@ func IsIP(version types.IPVersion, s string) error {
 // IPsDiffSet calculates the difference set of two IP address slices.
 // For example, the difference set between [172.18.40.1 172.18.40.2] and
 // [172.18.40.2 172.18.40.3] is [172.18.40.1].
-func IPsDiffSet(ips1, ips2 []net.IP) []net.IP {
+//
+// If sorted is true, the result set of IP addresses will be sorted.
+func IPsDiffSet(ips1, ips2 []net.IP, sorted bool) []net.IP {
 	var ips []net.IP
 	marks := make(map[string]bool)
 	for _, ip := range ips1 {
@@ -99,9 +101,11 @@ func IPsDiffSet(ips1, ips2 []net.IP) []net.IP {
 		ips = append(ips, net.ParseIP(k))
 	}
 
-	sort.Slice(ips, func(i, j int) bool {
-		return bytes.Compare(ips[i].To16(), ips[j].To16()) < 0
-	})
+	if sorted {
+		sort.Slice(ips, func(i, j int) bool {
+			return bytes.Compare(ips[i].To16(), ips[j].To16()) < 0
+		})
+	}
 
 	return ips
 }
@@ -109,7 +113,9 @@ func IPsDiffSet(ips1, ips2 []net.IP) []net.IP {
 // IPsUnionSet calculates the union set of two IP address slices.
 // For example, the union set between [172.18.40.1 172.18.40.2] and
 // [172.18.40.2 172.18.40.3] is [172.18.40.1 172.18.40.2 172.18.40.3].
-func IPsUnionSet(ips1, ips2 []net.IP) []net.IP {
+//
+// If sorted is true, the result set of IP addresses will be sorted.
+func IPsUnionSet(ips1, ips2 []net.IP, sorted bool) []net.IP {
 	var ips []net.IP
 	marks := make(map[string]bool)
 	ips1 = append(ips1, ips2...)
@@ -123,9 +129,11 @@ func IPsUnionSet(ips1, ips2 []net.IP) []net.IP {
 		ips = append(ips, net.ParseIP(k))
 	}
 
-	sort.Slice(ips, func(i, j int) bool {
-		return bytes.Compare(ips[i].To16(), ips[j].To16()) < 0
-	})
+	if sorted {
+		sort.Slice(ips, func(i, j int) bool {
+			return bytes.Compare(ips[i].To16(), ips[j].To16()) < 0
+		})
+	}
 
 	return ips
 }
@@ -133,7 +141,9 @@ func IPsUnionSet(ips1, ips2 []net.IP) []net.IP {
 // IPsIntersectionSet calculates the intersection set of two IP address
 // slices. For example, the intersection set between [172.18.40.1 172.18.40.2]
 // and [172.18.40.2 172.18.40.3] is [172.18.40.2].
-func IPsIntersectionSet(ips1, ips2 []net.IP) []net.IP {
+//
+// If sorted is true, the result set of IP addresses will be sorted.
+func IPsIntersectionSet(ips1, ips2 []net.IP, sorted bool) []net.IP {
 	var ips []net.IP
 	set := make(map[string]bool)
 	for _, ip := range ips1 {
@@ -153,9 +163,11 @@ func IPsIntersectionSet(ips1, ips2 []net.IP) []net.IP {
 		ips = append(ips, net.ParseIP(k))
 	}
 
-	sort.Slice(ips, func(i, j int) bool {
-		return bytes.Compare(ips[i].To16(), ips[j].To16()) < 0
-	})
+	if sorted {
+		sort.Slice(ips, func(i, j int) bool {
+			return bytes.Compare(ips[i].To16(), ips[j].To16()) < 0
+		})
+	}
 
 	return ips
 }
diff --git a/pkg/ip/iprange.go b/pkg/ip/iprange.go
index 905717889..2f0d5aed8 100644
--- a/pkg/ip/iprange.go
+++ b/pkg/ip/iprange.go
@@ -158,7 +158,7 @@ func IsIPRangeOverlap(version types.IPVersion, ipRange1, ipRange2 string) (bool,
 	// verified in IsIPRange above.
 	ips1, _ := ParseIPRange(version, ipRange1)
 	ips2, _ := ParseIPRange(version, ipRange2)
-	if len(ips1) > len(IPsDiffSet(ips1, ips2)) {
+	if len(ips1) > len(IPsDiffSet(ips1, ips2, false)) {
 		return true, nil
 	}
 
diff --git a/pkg/ip/utils.go b/pkg/ip/utils.go
index 773d1a30a..7178bfc87 100644
--- a/pkg/ip/utils.go
+++ b/pkg/ip/utils.go
@@ -19,7 +19,7 @@ func AssembleTotalIPs(ipVersion types.IPVersion, ipRanges, excludedIPRanges []st
 	if nil != err {
 		return nil, err
 	}
-	totalIPs := IPsDiffSet(ips, excludeIPs)
+	totalIPs := IPsDiffSet(ips, excludeIPs, false)
 
 	return totalIPs, nil
 }
diff --git a/pkg/ippoolmanager/ippool_informer.go b/pkg/ippoolmanager/ippool_informer.go
index 7c4e4f001..97f6cdb22 100644
--- a/pkg/ippoolmanager/ippool_informer.go
+++ b/pkg/ippoolmanager/ippool_informer.go
@@ -497,7 +497,7 @@ func (ic *IPPoolController) scaleIPPoolIfNeeded(ctx context.Context, pool *spide
 			if nil != err {
 				return fmt.Errorf("%w: failed to parse IP ranges '%v', error: %v", constant.ErrWrongInput, allocatedIPRanges, err)
 			}
-			freeIPs := spiderpoolip.IPsDiffSet(totalIPs, allocatedIPs)
+			freeIPs := spiderpoolip.IPsDiffSet(totalIPs, allocatedIPs, true)
 			discardedIPs := freeIPs[:totalIPCount-desiredIPNum]
 			discardedIPRanges, err := spiderpoolip.ConvertIPsToIPRanges(*pool.Spec.IPVersion, discardedIPs)
 			if nil != err {
@@ -756,7 +756,7 @@ func (ic *IPPoolController) scaleIPPoolWithIPs(ctx context.Context, pool *spider
 			return fmt.Errorf("failed to parse IP ranges '%v', error: %v", pool.Spec.IPs, err)
 		}
 
-		sortedIPRanges, err := spiderpoolip.ConvertIPsToIPRanges(*pool.Spec.IPVersion, spiderpoolip.IPsDiffSet(totalIPs, discardedIPs))
+		sortedIPRanges, err := spiderpoolip.ConvertIPsToIPRanges(*pool.Spec.IPVersion, spiderpoolip.IPsDiffSet(totalIPs, discardedIPs, false))
 		if nil != err {
 			return fmt.Errorf("failed to convert IPs '%v' to IP ranges, error: %v", ipRanges, err)
 		}
@@ -822,7 +822,7 @@ func (ic *IPPoolController) generateIPsFromSubnetWhenScaleUpIP(ctx context.Conte
 		// the subnetPoolAllocatedIPs is greater than pool total IP counts indicates that
 		// the SpiderSubnet updated successfully but the IPPool failed to update in the last procession
 		if len(subnetPoolAllocatedIPs) > len(poolTotalIPs) {
-			lastAllocatedIPs := spiderpoolip.IPsDiffSet(subnetPoolAllocatedIPs, poolTotalIPs)
+			lastAllocatedIPs := spiderpoolip.IPsDiffSet(subnetPoolAllocatedIPs, poolTotalIPs, false)
 			log.Sugar().Warnf("SpiderSubnet '%s' Status ControlledIPPool '%s' has the allocated IPs '%v', try to re-use it!", subnetName, pool.Name, lastAllocatedIPs)
 			if len(lastAllocatedIPs) == desiredIPNum-len(poolTotalIPs) {
 				// last allocated IPs is same with the current allocation request
@@ -853,7 +853,7 @@ func (ic *IPPoolController) generateIPsFromSubnetWhenScaleUpIP(ctx context.Conte
 	}
 
 	if len(reservedIPs) != 0 {
-		freeIPs = spiderpoolip.IPsDiffSet(freeIPs, reservedIPs)
+		freeIPs = spiderpoolip.IPsDiffSet(freeIPs, reservedIPs, true)
 	}
 
 	if len(pool.Spec.ExcludeIPs) != 0 {
@@ -861,7 +861,7 @@ func (ic *IPPoolController) generateIPsFromSubnetWhenScaleUpIP(ctx context.Conte
 		if nil != err {
 			return nil, fmt.Errorf("failed to parse exclude IP ranges '%v', error: %v", pool.Spec.ExcludeIPs, err)
 		}
-		freeIPs = spiderpoolip.IPsDiffSet(freeIPs, excludeIPs)
+		freeIPs = spiderpoolip.IPsDiffSet(freeIPs, excludeIPs, true)
 	}
 
 	// check the filtered subnet free IP number is enough or not
diff --git a/pkg/ippoolmanager/ippool_manager.go b/pkg/ippoolmanager/ippool_manager.go
index 04d778f02..3c515ab4e 100644
--- a/pkg/ippoolmanager/ippool_manager.go
+++ b/pkg/ippoolmanager/ippool_manager.go
@@ -163,7 +163,7 @@ func (im *ipPoolManager) genRandomIP(ctx context.Context, ipPool *spiderpoolv1.S
 		return nil, err
 	}
 
-	availableIPs := spiderpoolip.IPsDiffSet(totalIPs, append(reservedIPs, usedIPs...))
+	availableIPs := spiderpoolip.IPsDiffSet(totalIPs, append(reservedIPs, usedIPs...), false)
 	if len(availableIPs) == 0 {
 		return nil, constant.ErrIPUsedOut
 	}
diff --git a/pkg/ippoolmanager/ippool_subnet_validate.go b/pkg/ippoolmanager/ippool_subnet_validate.go
index 5c661d0e4..4d08921ac 100644
--- a/pkg/ippoolmanager/ippool_subnet_validate.go
+++ b/pkg/ippoolmanager/ippool_subnet_validate.go
@@ -86,7 +86,7 @@ func validateSubnetTotalIPsContainsIPPoolTotalIPs(subnet *spiderpoolv1.SpiderSub
 		return field.InternalError(ipsField, fmt.Errorf("failed to assemble the total IP addresses of the Subnet %s: %v", subnet.Name, err))
 	}
 
-	outIPs := spiderpoolip.IPsDiffSet(poolTotalIPs, subnetTotalIPs)
+	outIPs := spiderpoolip.IPsDiffSet(poolTotalIPs, subnetTotalIPs, false)
 	if len(outIPs) > 0 {
 		ranges, _ := spiderpoolip.ConvertIPsToIPRanges(*ipPool.Spec.IPVersion, outIPs)
 		return field.Forbidden(
diff --git a/pkg/ippoolmanager/ippool_validate.go b/pkg/ippoolmanager/ippool_validate.go
index 084322efa..f8adac9d3 100644
--- a/pkg/ippoolmanager/ippool_validate.go
+++ b/pkg/ippoolmanager/ippool_validate.go
@@ -243,7 +243,7 @@ func (iw *IPPoolWebhook) validateIPPoolAvailableIPs(ctx context.Context, ipPool
 				return field.InternalError(ipsField, fmt.Errorf("failed to assemble the total IP addresses of the existing IPPool %s: %v", pool.Name, err))
 			}
 
-			overlapIPs := spiderpoolip.IPsIntersectionSet(newIPs, existIPs)
+			overlapIPs := spiderpoolip.IPsIntersectionSet(newIPs, existIPs, false)
 			if len(overlapIPs) > 0 {
 				overlapRanges, _ := spiderpoolip.ConvertIPsToIPRanges(*pool.Spec.IPVersion, overlapIPs)
 				return field.Forbidden(
diff --git a/pkg/subnetmanager/controllers/utils.go b/pkg/subnetmanager/controllers/utils.go
index 048f8b1af..07716f53e 100644
--- a/pkg/subnetmanager/controllers/utils.go
+++ b/pkg/subnetmanager/controllers/utils.go
@@ -80,7 +80,7 @@ func GenSubnetFreeIPs(subnet *spiderpoolv1.SpiderSubnet) ([]net.IP, error) {
 	if err != nil {
 		return nil, err
 	}
-	freeIPs := spiderpoolip.IPsDiffSet(totalIPs, usedIPs)
+	freeIPs := spiderpoolip.IPsDiffSet(totalIPs, usedIPs, true)
 
 	return freeIPs, nil
 }
diff --git a/pkg/subnetmanager/subnet_informer.go b/pkg/subnetmanager/subnet_informer.go
index a1e64b548..9e147e9a7 100644
--- a/pkg/subnetmanager/subnet_informer.go
+++ b/pkg/subnetmanager/subnet_informer.go
@@ -338,7 +338,7 @@ func (sc *SubnetController) syncControlledIPPoolIPs(ctx context.Context, subnet
 			return err
 		}
 
-		validIPs := spiderpoolip.IPsIntersectionSet(subnetTotalIPs, poolTotalIPs)
+		validIPs := spiderpoolip.IPsIntersectionSet(subnetTotalIPs, poolTotalIPs, false)
 		tmpCount += len(validIPs)
 
 		ranges, err := spiderpoolip.ConvertIPsToIPRanges(*pool.Spec.IPVersion, validIPs)
diff --git a/pkg/subnetmanager/subnet_validate.go b/pkg/subnetmanager/subnet_validate.go
index be4894ab3..f41534adc 100644
--- a/pkg/subnetmanager/subnet_validate.go
+++ b/pkg/subnetmanager/subnet_validate.go
@@ -117,7 +117,7 @@ func validateSubnetIPInUse(subnet *spiderpoolv1.SpiderSubnet) *field.Error {
 		if err != nil {
 			return field.InternalError(controlledIPPoolsField, fmt.Errorf("failed to parse the pre-allocation of the IPPool %s: %v", poolName, err))
 		}
-		invalidIPs := spiderpoolip.IPsDiffSet(poolTotalIPs, totalIPs)
+		invalidIPs := spiderpoolip.IPsDiffSet(poolTotalIPs, totalIPs, false)
 		if len(invalidIPs) > 0 {
 			ranges, _ := spiderpoolip.ConvertIPsToIPRanges(*subnet.Spec.IPVersion, invalidIPs)
 			return field.Forbidden(


Test patch:
diff --git a/pkg/ip/ip_test.go b/pkg/ip/ip_test.go
index 49d13a408..b8e735885 100644
--- a/pkg/ip/ip_test.go
+++ b/pkg/ip/ip_test.go
@@ -190,6 +190,7 @@ var _ = Describe("IP", Label("ip_test"), func() {
 					net.IPv4(172, 18, 40, 2),
 					net.IPv4(172, 18, 40, 3),
 				},
+				true,
 			)
 			Expect(ips).To(Equal([]net.IP{net.IPv4(172, 18, 40, 1)}))
 		})
@@ -204,6 +205,7 @@ var _ = Describe("IP", Label("ip_test"), func() {
 					net.ParseIP("abcd:1234::2"),
 					net.ParseIP("abcd:1234::3"),
 				},
+				true,
 			)
 			Expect(ips).To(Equal([]net.IP{net.ParseIP("abcd:1234::1")}))
 		})
@@ -220,6 +222,7 @@ var _ = Describe("IP", Label("ip_test"), func() {
 					net.IPv4(172, 18, 40, 2),
 					net.IPv4(172, 18, 40, 3),
 				},
+				true,
 			)
 			Expect(ips).To(Equal(
 				[]net.IP{
@@ -240,6 +243,7 @@ var _ = Describe("IP", Label("ip_test"), func() {
 					net.ParseIP("abcd:1234::2"),
 					net.ParseIP("abcd:1234::3"),
 				},
+				true,
 			)
 			Expect(ips).To(Equal(
 				[]net.IP{
@@ -262,6 +266,7 @@ var _ = Describe("IP", Label("ip_test"), func() {
 					net.IPv4(172, 18, 40, 2),
 					net.IPv4(172, 18, 40, 3),
 				},
+				true,
 			)
 			Expect(ips).To(Equal([]net.IP{net.IPv4(172, 18, 40, 2)}))
 		})
@@ -276,6 +281,7 @@ var _ = Describe("IP", Label("ip_test"), func() {
 					net.ParseIP("abcd:1234::2"),
 					net.ParseIP("abcd:1234::3"),
 				},
+				true,
 			)
 			Expect(ips).To(Equal([]net.IP{net.ParseIP("abcd:1234::2")}))
 		})
diff --git a/test/e2e/common/spidersubnet.go b/test/e2e/common/spidersubnet.go
index d97e716cd..24a9b6708 100644
--- a/test/e2e/common/spidersubnet.go
+++ b/test/e2e/common/spidersubnet.go
@@ -310,7 +310,7 @@ func GetAvailableIpsInSubnet(f *frame.Framework, subnetName string) ([]net.IP, e
 		return nil, err
 	}
 
-	ips := ip.IPsDiffSet(ips1, ips2)
+	ips := ip.IPsDiffSet(ips1, ips2, false)
 	return ips, nil
 }
 
@@ -358,7 +358,7 @@ LOOP:
 							return err
 						}
 
-						diffIps := ip.IPsDiffSet(ips1, ips2)
+						diffIps := ip.IPsDiffSet(ips1, ips2, false)
 						if diffIps != nil {
 							GinkgoWriter.Printf("inconsistent ip records in subnet %v/%v and pool %v/%v \n", subnetName, ips2, pool.Name, ips1)
 							continue LOOP