Merge pull request #116879 from lzhecheng/fix-generateAPIPodStatus-dualstack

[Dual-stack] Fix generateAPIPodStatus() of kubelet handling Secondary IP
This commit is contained in:
Kubernetes Prow Robot 2023-07-07 20:37:04 -07:00 committed by GitHub
commit 1e0b4c84cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -1738,6 +1738,13 @@ func (kl *Kubelet) generateAPIPodStatus(pod *v1.Pod, podStatus *kubecontainer.Po
if err != nil {
klog.V(4).InfoS("Cannot get host IPs", "err", err)
} else {
if s.HostIP != "" {
if utilnet.IPFamilyOfString(s.HostIP) != utilnet.IPFamilyOf(hostIPs[0]) {
kl.recorder.Eventf(pod, v1.EventTypeWarning, "HostIPsIPFamilyMismatch",
"Kubelet detected an IPv%s node IP (%s), but the cloud provider selected an IPv%s node IP (%s); pass an explicit `--node-ip` to kubelet to fix this.",
utilnet.IPFamilyOfString(s.HostIP), s.HostIP, utilnet.IPFamilyOf(hostIPs[0]), hostIPs[0].String())
}
}
s.HostIP = hostIPs[0].String()
// HostNetwork Pods inherit the node IPs as PodIPs. They are immutable once set,
// other than that if the node becomes dual-stack, we add the secondary IP.
@ -1749,7 +1756,9 @@ func (kl *Kubelet) generateAPIPodStatus(pod *v1.Pod, podStatus *kubecontainer.Po
}
// Secondary IP is not set #105320
if len(hostIPs) == 2 && len(s.PodIPs) == 1 {
s.PodIPs = append(s.PodIPs, v1.PodIP{IP: hostIPs[1].String()})
if utilnet.IPFamilyOfString(s.PodIPs[0].IP) != utilnet.IPFamilyOf(hostIPs[1]) {
s.PodIPs = append(s.PodIPs, v1.PodIP{IP: hostIPs[1].String()})
}
}
}
}

View File

@ -4087,6 +4087,17 @@ func TestNodeAddressUpdatesGenerateAPIPodStatusHostNetworkPodIPs(t *testing.T) {
{IP: "2001:db8::2"},
},
},
{
name: "Update secondary after new secondary address dual-stack - reverse order",
nodeIPs: []string{"2001:db8::2"},
nodeAddresses: []v1.NodeAddress{
{Type: v1.NodeInternalIP, Address: "10.0.0.1"},
{Type: v1.NodeInternalIP, Address: "2001:db8::2"},
},
expectedPodIPs: []v1.PodIP{
{IP: "2001:db8::2"},
},
},
}
for _, tc := range testcases {