mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-14 06:15:45 +00:00
Merge pull request #116879 from lzhecheng/fix-generateAPIPodStatus-dualstack
[Dual-stack] Fix generateAPIPodStatus() of kubelet handling Secondary IP
This commit is contained in:
commit
1e0b4c84cf
@ -1738,6 +1738,13 @@ func (kl *Kubelet) generateAPIPodStatus(pod *v1.Pod, podStatus *kubecontainer.Po
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
klog.V(4).InfoS("Cannot get host IPs", "err", err)
|
klog.V(4).InfoS("Cannot get host IPs", "err", err)
|
||||||
} else {
|
} 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()
|
s.HostIP = hostIPs[0].String()
|
||||||
// HostNetwork Pods inherit the node IPs as PodIPs. They are immutable once set,
|
// 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.
|
// other than that if the node becomes dual-stack, we add the secondary IP.
|
||||||
@ -1749,11 +1756,13 @@ func (kl *Kubelet) generateAPIPodStatus(pod *v1.Pod, podStatus *kubecontainer.Po
|
|||||||
}
|
}
|
||||||
// Secondary IP is not set #105320
|
// Secondary IP is not set #105320
|
||||||
if len(hostIPs) == 2 && len(s.PodIPs) == 1 {
|
if len(hostIPs) == 2 && len(s.PodIPs) == 1 {
|
||||||
|
if utilnet.IPFamilyOfString(s.PodIPs[0].IP) != utilnet.IPFamilyOf(hostIPs[1]) {
|
||||||
s.PodIPs = append(s.PodIPs, v1.PodIP{IP: hostIPs[1].String()})
|
s.PodIPs = append(s.PodIPs, v1.PodIP{IP: hostIPs[1].String()})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return *s
|
return *s
|
||||||
}
|
}
|
||||||
|
@ -4087,6 +4087,17 @@ func TestNodeAddressUpdatesGenerateAPIPodStatusHostNetworkPodIPs(t *testing.T) {
|
|||||||
{IP: "2001:db8::2"},
|
{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 {
|
for _, tc := range testcases {
|
||||||
|
Loading…
Reference in New Issue
Block a user