diff --git a/pkg/cri/sbserver/sandbox_run.go b/pkg/cri/sbserver/sandbox_run.go index 0997aa5fd..f44a25f10 100644 --- a/pkg/cri/sbserver/sandbox_run.go +++ b/pkg/cri/sbserver/sandbox_run.go @@ -612,7 +612,7 @@ func selectPodIPs(ctx context.Context, configs []*cni.IPConfig, preference strin } case "ipv6": for i, ip := range configs { - if ip.IP.To16() != nil { + if ip.IP.To4() == nil { return ipString(ip), append(extra, toStrings(configs[i+1:])...) } extra = append(extra, ipString(ip)) diff --git a/pkg/cri/sbserver/sandbox_run_test.go b/pkg/cri/sbserver/sandbox_run_test.go index a51810925..238ef031f 100644 --- a/pkg/cri/sbserver/sandbox_run_test.go +++ b/pkg/cri/sbserver/sandbox_run_test.go @@ -145,7 +145,7 @@ func TestSelectPodIP(t *testing.T) { }, { 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", expectedAdditionalIPs: []string{"192.168.17.43"}, pref: "ipv6", diff --git a/pkg/cri/server/sandbox_run.go b/pkg/cri/server/sandbox_run.go index 6268de828..a9540a1a5 100644 --- a/pkg/cri/server/sandbox_run.go +++ b/pkg/cri/server/sandbox_run.go @@ -692,7 +692,7 @@ func selectPodIPs(ctx context.Context, configs []*cni.IPConfig, preference strin } case "ipv6": for i, ip := range configs { - if ip.IP.To16() != nil { + if ip.IP.To4() == nil { return ipString(ip), append(extra, toStrings(configs[i+1:])...) } extra = append(extra, ipString(ip)) diff --git a/pkg/cri/server/sandbox_run_test.go b/pkg/cri/server/sandbox_run_test.go index d8f494625..b1bc1ec13 100644 --- a/pkg/cri/server/sandbox_run_test.go +++ b/pkg/cri/server/sandbox_run_test.go @@ -293,7 +293,7 @@ func TestSelectPodIP(t *testing.T) { }, { 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", expectedAdditionalIPs: []string{"192.168.17.43"}, pref: "ipv6",