Skip to content

Commit

Permalink
fix init ipam
Browse files Browse the repository at this point in the history
  • Loading branch information
fanriming committed Sep 16, 2021
1 parent f250602 commit 97a5b2a
Showing 1 changed file with 8 additions and 31 deletions.
39 changes: 8 additions & 31 deletions pkg/controller/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,43 +286,20 @@ func (c *Controller) InitIPAM() error {
}
for _, pod := range pods {
if isPodAlive(pod) && pod.Annotations[util.AllocatedAnnotation] == "true" {
if pod.Annotations[util.LogicalSwitchAnnotation] != "" {
podNets, err := c.getPodKubeovnNets(pod)
if err != nil {
klog.Errorf("failed to get pod kubeovn nets %s.%s address %s: %v", pod.Name, pod.Namespace, pod.Annotations[util.IpAddressAnnotation], err)
}
for _, podNet := range podNets {
_, _, _, err := c.ipam.GetStaticAddress(
fmt.Sprintf("%s/%s", pod.Namespace, pod.Name),
pod.Annotations[util.IpAddressAnnotation],
pod.Annotations[util.MacAddressAnnotation],
pod.Annotations[util.LogicalSwitchAnnotation], false)
pod.Annotations[fmt.Sprintf(util.IpAddressAnnotationTemplate, podNet.ProviderName)],
pod.Annotations[fmt.Sprintf(util.MacAddressAnnotationTemplate, podNet.ProviderName)],
pod.Annotations[fmt.Sprintf(util.LogicalSwitchAnnotationTemplate, podNet.ProviderName)], false)
if err != nil {
klog.Errorf("failed to init pod %s.%s address %s: %v", pod.Name, pod.Namespace, pod.Annotations[util.IpAddressAnnotation], err)
}
}
attachNetworks := pod.Annotations[util.AttachmentNetworkAnnotation]
if attachNetworks != "" {
attachments, err := util.ParsePodNetworkAnnotation(attachNetworks, pod.Namespace)
if err != nil {
klog.Errorf("failed to parse attach net for pod '%s', %v", pod.Name, err)
continue
}
for _, attach := range attachments {
var builder strings.Builder
builder.WriteString(attach.Name)
builder.WriteString(".")
if attach.Namespace == "" {
builder.WriteString("default")
} else {
builder.WriteString(attach.Namespace)
}

_, _, _, err := c.ipam.GetStaticAddress(
fmt.Sprintf("%s/%s", pod.Namespace, pod.Name),
pod.Annotations[fmt.Sprintf(util.IpAddressAnnotationTemplate, builder.String())],
pod.Annotations[fmt.Sprintf(util.MacAddressAnnotationTemplate, builder.String())],
pod.Annotations[fmt.Sprintf(util.LogicalSwitchAnnotationTemplate, builder.String())], false)
if err != nil {
klog.Errorf("failed to init pod %s.%s address %s: %v", pod.Name, pod.Namespace, pod.Annotations[util.IpAddressAnnotation], err)
}
}
}
}
}

Expand Down

0 comments on commit 97a5b2a

Please sign in to comment.