From 4944db750ec6981406a34485254a66e63d03adde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=A5=96=E5=BB=BA?= Date: Tue, 16 Aug 2022 11:16:47 +0800 Subject: [PATCH] initialize IPAM from IP CR with empty PodType for sts Pods (#1812) --- pkg/controller/init.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pkg/controller/init.go b/pkg/controller/init.go index d45ddf8db47..11453477c12 100644 --- a/pkg/controller/init.go +++ b/pkg/controller/init.go @@ -344,7 +344,13 @@ func (c *Controller) InitIPAM() error { } for _, pod := range pods { - if pod.Spec.HostNetwork || !isPodAlive(pod) { + if pod.Spec.HostNetwork { + continue + } + + isAlive := isPodAlive(pod) + isStsPod, _ := isStatefulSetPod(pod) + if !isAlive && !isStsPod { continue } @@ -363,6 +369,14 @@ func (c *Controller) InitIPAM() error { } if pod.Annotations[fmt.Sprintf(util.AllocatedAnnotationTemplate, podNet.ProviderName)] == "true" { portName := ovs.PodNameToPortName(podName, pod.Namespace, podNet.ProviderName) + if !isAlive && isStsPod { + if ipCR := ipsMap[portName]; ipCR != nil && ipCR.Spec.PodType == "" { + if _, _, _, err = c.ipam.GetStaticAddress(key, ipCR.Name, ipCR.Spec.IPAddress, ipCR.Spec.MacAddress, ipCR.Spec.Subnet, true); err != nil { + klog.Errorf("failed to init IPAM from IP CR %s: %v", ipCR.Name, err) + } + } + continue + } ip := pod.Annotations[fmt.Sprintf(util.IpAddressAnnotationTemplate, podNet.ProviderName)] mac := pod.Annotations[fmt.Sprintf(util.MacAddressAnnotationTemplate, podNet.ProviderName)] subnet := pod.Annotations[fmt.Sprintf(util.LogicalSwitchAnnotationTemplate, podNet.ProviderName)]