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 b669c67 commit 7103aae
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pkg/controller/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,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 @@ -345,6 +351,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.Spec.IPAddress, ipCR.Spec.MacAddress, ipCR.Spec.Subnet); 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 7103aae

Please sign in to comment.