Skip to content

Commit

Permalink
initialize IPAM from IP CR with empty PodType for sts Pods (#1812)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Aug 16, 2022
1 parent 3eb1d1a commit d44de3e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pkg/controller/init.go
Expand Up @@ -340,7 +340,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
}

Expand All @@ -359,6 +365,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)]
Expand Down

0 comments on commit d44de3e

Please sign in to comment.