Skip to content

Commit

Permalink
[flexible-ipam] Optimization on NodeIPAM code path (#3326)
Browse files Browse the repository at this point in the history
Avoid running unnecessary code in getIPPoolsByPod function when
no IPAM annotation is present.
Signed-off-by: Anna Khmelnitsky <akhmelnitsky@vmware.com>
  • Loading branch information
annakhm committed Feb 23, 2022
1 parent 3f30d84 commit 2cdc5ab
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions pkg/agent/cniserver/ipam/antrea_ipam_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,20 @@ func (c *AntreaIPAMController) getIPPoolsByPod(namespace, name string) ([]string
}
return nil, nil, nil, err
}

annotations, exists := pod.Annotations[AntreaIPAMAnnotationKey]
if !exists {
// Find IPPool by Namespace
ns, err := c.namespaceLister.Get(namespace)
if err != nil {
return nil, nil, nil, nil
}
annotations, exists = ns.Annotations[AntreaIPAMAnnotationKey]
if !exists {
return nil, nil, nil, nil
}
}

// Collect specified IPs if exist
ipStrings, _ := pod.Annotations[AntreaIPAMPodIPAnnotationKey]
ipStrings = strings.ReplaceAll(ipStrings, " ", "")
Expand Down Expand Up @@ -187,20 +201,6 @@ ownerReferenceLoop:
}
}

annotations, exists := pod.Annotations[AntreaIPAMAnnotationKey]
if exists {
return strings.Split(annotations, AntreaIPAMAnnotationDelimiter), ips, reservedOwner, ipErr
}

// Find IPPool by Namespace
ns, err := c.namespaceLister.Get(namespace)
if err != nil {
return nil, nil, nil, nil
}
annotations, exists = ns.Annotations[AntreaIPAMAnnotationKey]
if !exists {
return nil, nil, nil, nil
}
return strings.Split(annotations, AntreaIPAMAnnotationDelimiter), ips, reservedOwner, ipErr
}

Expand Down

0 comments on commit 2cdc5ab

Please sign in to comment.