Skip to content

Commit 0b4cce1

Browse files
committed
enhance: avoid misjudgement on DualStack ip family when parsing network config from existing IPInstances
1 parent e825742 commit 0b4cce1

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

pkg/webhook/utils/utils.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,22 @@ func parseNetworkConfigByExistIPInstances(ctx context.Context, c client.Reader,
263263
ipFamily = ipamtypes.IPv4
264264
}
265265
case 2:
266-
ipFamily = ipamtypes.DualStack
266+
var (
267+
v4Count = 0
268+
v6Count = 0
269+
)
270+
for i := range validIPList {
271+
if networkingv1.IsIPv6IPInstance(&validIPList[i]) {
272+
v6Count += 1
273+
} else {
274+
v4Count += 1
275+
}
276+
}
277+
if v4Count == 1 && v6Count == 1 {
278+
ipFamily = ipamtypes.DualStack
279+
} else {
280+
err = fmt.Errorf("more than two ip instances are of the same family type, ipv4 count %d, ipv6 count %d", v4Count, v6Count)
281+
}
267282
default:
268283
err = fmt.Errorf("more than two reserve ip exist for list options %v", opts)
269284
return

0 commit comments

Comments
 (0)