Change:
}) } } <ins> func TestSortPodIPs(t *testing.T) { testcases := []struct { name        string nodeIP      string podIPs      []string expectedIPs []string }{ { name:        "Simple", nodeIP:      "", podIPs:      []string{"10.0.0.1"}, expectedIPs: []string{"10.0.0.1"}, }, { name:        "Dual-stack", nodeIP:      "", podIPs:      []string{"10.0.0.1", "fd01::1234"}, expectedIPs: []string{"10.0.0.1", "fd01::1234"}, }, { name:        "Dual-stack with explicit node IP", nodeIP:      "192.168.1.1", podIPs:      []string{"10.0.0.1", "fd01::1234"}, expectedIPs: []string{"10.0.0.1", "fd01::1234"}, }, { name:        "Dual-stack with CRI returning wrong family first", nodeIP:      "", podIPs:      []string{"fd01::1234", "10.0.0.1"}, expectedIPs: []string{"10.0.0.1", "fd01::1234"}, }, { name:        "Dual-stack with explicit node IP with CRI returning wrong family first", nodeIP:      "192.168.1.1", podIPs:      []string{"fd01::1234", "10.0.0.1"}, expectedIPs: []string{"10.0.0.1", "fd01::1234"}, }, { name:        "Dual-stack with IPv6 node IP", nodeIP:      "fd00::5678", podIPs:      []string{"10.0.0.1", "fd01::1234"}, expectedIPs: []string{"fd01::1234", "10.0.0.1"}, }, { name:        "Dual-stack with IPv6 node IP, other CRI order", nodeIP:      "fd00::5678", podIPs:      []string{"fd01::1234", "10.0.0.1"}, expectedIPs: []string{"fd01::1234", "10.0.0.1"}, }, { name:        "No Pod IP matching Node IP", nodeIP:      "fd00::5678", podIPs:      []string{"10.0.0.1"}, expectedIPs: []string{"10.0.0.1"}, }, { name:        "No Pod IP matching (unspecified) Node IP", nodeIP:      "", podIPs:      []string{"fd01::1234"}, expectedIPs: []string{"fd01::1234"}, }, { name:        "Multiple IPv4 IPs", nodeIP:      "", podIPs:      []string{"10.0.0.1", "10.0.0.2", "10.0.0.3"}, expectedIPs: []string{"10.0.0.1"}, }, { name:        "Multiple Dual-Stack IPs", nodeIP:      "", podIPs:      []string{"10.0.0.1", "10.0.0.2", "fd01::1234", "10.0.0.3", "fd01::5678"}, expectedIPs: []string{"10.0.0.1", "fd01::1234"}, }, } for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */) defer testKubelet.Cleanup() kl := testKubelet.kubelet if tc.nodeIP != "" { kl.nodeIPs = []net.IP{net.ParseIP(tc.nodeIP)} } podIPs := kl.sortPodIPs(tc.podIPs) if !reflect.DeepEqual(podIPs, tc.expectedIPs) { t.Fatalf("Expected PodIPs %#v, got %#v", tc.expectedIPs, podIPs) } }) } } </ins>

Discussion:
<!-- Please use this template while reporting a bug and provide as much info as possible. Not doing so may result in your bug not being addressed in a timely manner. Thanks! If the matter is security related, please disclose it privately via --In a dual-stack cluster with IPv4 as default family (first kubelet IP), a container is created with a env var set to . When the container is running, properly contains the IPv4 But at runtime, this env var (used in container args) is expanded to the pod IPv6 instead of the IPv4. When using , it should always return the value actually exposed as and not something else. Kubernetes version:Cloud provider or hardware configuration: Bare metal cluster OS (e.g: ): Ubuntu 20.04 Kernel (e.g. ): Linux 5.8.0-59-generic 66~20.04.1-Ubuntu SMP Thu Jun 17 11:14:10 UTC 2021 x8664 x8664 x86_64 GNU/Linux Network plugin and version (if this is a network-related bug): cilium 1.10 Others: CRI-O 1.21 + crun.
Note: I have a configuration that matches the ones that had IP ordering issue before was fixed. So it may be related.
/sig network
Just a guess, but I wonder if it may be caused by
That's it. The fix from properly sort IP when computing the Pod status, but the sorted IPs are then replaced by computed IPs as this log shows.
/triage accepted Thanks for the detailed report
/assign