Merge pull request #9076 from CFSworks/fix-ipv6-pref

Fix `ip_pref` configuration option
This commit is contained in:
Samuel Karp 2023-10-06 23:31:45 -07:00 committed by GitHub
commit 841c693710
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 4 additions and 4 deletions

View File

@ -612,7 +612,7 @@ func selectPodIPs(ctx context.Context, configs []*cni.IPConfig, preference strin
} }
case "ipv6": case "ipv6":
for i, ip := range configs { for i, ip := range configs {
if ip.IP.To16() != nil { if ip.IP.To4() == nil {
return ipString(ip), append(extra, toStrings(configs[i+1:])...) return ipString(ip), append(extra, toStrings(configs[i+1:])...)
} }
extra = append(extra, ipString(ip)) extra = append(extra, ipString(ip))

View File

@ -145,7 +145,7 @@ func TestSelectPodIP(t *testing.T) {
}, },
{ {
desc: "ipv6 should be picked even if ipv4 comes first", desc: "ipv6 should be picked even if ipv4 comes first",
ips: []string{"2001:db8:85a3::8a2e:370:7334", "192.168.17.43"}, ips: []string{"192.168.17.43", "2001:db8:85a3::8a2e:370:7334"},
expectedIP: "2001:db8:85a3::8a2e:370:7334", expectedIP: "2001:db8:85a3::8a2e:370:7334",
expectedAdditionalIPs: []string{"192.168.17.43"}, expectedAdditionalIPs: []string{"192.168.17.43"},
pref: "ipv6", pref: "ipv6",

View File

@ -692,7 +692,7 @@ func selectPodIPs(ctx context.Context, configs []*cni.IPConfig, preference strin
} }
case "ipv6": case "ipv6":
for i, ip := range configs { for i, ip := range configs {
if ip.IP.To16() != nil { if ip.IP.To4() == nil {
return ipString(ip), append(extra, toStrings(configs[i+1:])...) return ipString(ip), append(extra, toStrings(configs[i+1:])...)
} }
extra = append(extra, ipString(ip)) extra = append(extra, ipString(ip))

View File

@ -293,7 +293,7 @@ func TestSelectPodIP(t *testing.T) {
}, },
{ {
desc: "ipv6 should be picked even if ipv4 comes first", desc: "ipv6 should be picked even if ipv4 comes first",
ips: []string{"2001:db8:85a3::8a2e:370:7334", "192.168.17.43"}, ips: []string{"192.168.17.43", "2001:db8:85a3::8a2e:370:7334"},
expectedIP: "2001:db8:85a3::8a2e:370:7334", expectedIP: "2001:db8:85a3::8a2e:370:7334",
expectedAdditionalIPs: []string{"192.168.17.43"}, expectedAdditionalIPs: []string{"192.168.17.43"},
pref: "ipv6", pref: "ipv6",