Skip to content

Commit

Permalink
fix IPAM initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Apr 7, 2022
1 parent b26a06e commit 0ea24dc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func (c *Controller) InitIPAM() error {
if err != nil {
klog.Errorf("failed to init pod %s.%s address %s: %v", podName, pod.Namespace, pod.Annotations[fmt.Sprintf(util.IpAddressAnnotationTemplate, podNet.ProviderName)], err)
} else {
err = c.createOrUpdateCrdIPs(key, ip, mac, subnet, pod.Namespace, pod.Spec.NodeName, podNet.ProviderName)
err = c.createOrUpdateCrdIPs(podName, ip, mac, subnet, pod.Namespace, pod.Spec.NodeName, podNet.ProviderName)
if err != nil {
klog.Errorf("failed to create/update ips CR %s.%s with ip address %s: %v", podName, pod.Namespace, ip, err)
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/controller/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func (c *Controller) handleAddNode(key string) error {
return err
}

if err := c.createOrUpdateCrdIPs(key, ipStr, mac, c.config.NodeSwitch, "", node.Name, ""); err != nil {
if err := c.createOrUpdateCrdIPs("", ipStr, mac, c.config.NodeSwitch, "", node.Name, ""); err != nil {
klog.Errorf("failed to create or update IPs node-%s: %v", key, err)
return err
}
Expand Down Expand Up @@ -600,12 +600,14 @@ func (c *Controller) handleUpdateNode(key string) error {
return nil
}

func (c *Controller) createOrUpdateCrdIPs(key, ip, mac, subnetName, ns, nodeName, providerName string) error {
var ipName string
func (c *Controller) createOrUpdateCrdIPs(podName, ip, mac, subnetName, ns, nodeName, providerName string) error {
var key, ipName string
if subnetName == c.config.NodeSwitch {
ipName = fmt.Sprintf("node-%s", key)
key = nodeName
ipName = fmt.Sprintf("node-%s", nodeName)
} else {
ipName = ovs.PodNameToPortName(key, ns, providerName)
key = podName
ipName = ovs.PodNameToPortName(podName, ns, providerName)
}

v4IP, v6IP := util.SplitStringIP(ip)
Expand Down

0 comments on commit 0ea24dc

Please sign in to comment.