Skip to content

Commit

Permalink
refactor function name isIPAssignedToPod to isIPAssignedToOtherPod (#…
Browse files Browse the repository at this point in the history
…2096)

* refacor funcname isIPAssignedToPod to isIPAssignedToOtherPod

* report assigned pod to log

* turn the order of return value

* refactor
  • Loading branch information
changluyi committed Dec 2, 2022
1 parent c52f384 commit c42dae3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pkg/controller/pod.go
Expand Up @@ -1297,8 +1297,8 @@ func (c *Controller) acquireAddress(pod *v1.Pod, podNet *kubeovnNet) (string, st
for _, net := range nsNets {
for _, staticIPs := range ipPool {
for _, staticIP := range strings.Split(staticIPs, ",") {
if c.ipam.IsIPAssignedToPod(staticIP, net.Subnet.Name, key) {
klog.Errorf("static address %s for %s has been assigned", staticIP, key)
if assignedPod, ok := c.ipam.IsIPAssignedToOtherPod(staticIP, net.Subnet.Name, key); ok {
klog.Errorf("static address %s for %s has been assigned to %", staticIP, key, assignedPod)
continue
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/ipam/ipam.go
Expand Up @@ -242,14 +242,14 @@ func (ipam *IPAM) ContainAddress(address string) bool {
return false
}

func (ipam *IPAM) IsIPAssignedToPod(ip, subnetName, podName string) bool {
func (ipam *IPAM) IsIPAssignedToOtherPod(ip, subnetName, podName string) (string, bool) {
ipam.mutex.RLock()
defer ipam.mutex.RUnlock()

if subnet, ok := ipam.Subnets[subnetName]; !ok {
return false
return "", false
} else {
return subnet.isIPAssignedToPod(ip, podName)
return subnet.isIPAssignedToOtherPod(ip, podName)
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/ipam/subnet.go
Expand Up @@ -551,20 +551,20 @@ func (subnet *Subnet) GetPodAddress(podName, nicName string) (IP, IP, string, st
}
}

func (subnet *Subnet) isIPAssignedToPod(ip, podName string) bool {
func (subnet *Subnet) isIPAssignedToOtherPod(ip, podName string) (string, bool) {
if existPod, ok := subnet.V4IPToPod[IP(ip)]; ok {
klog.V(4).Infof("v4 check ip assigned, existPod %s, podName %s", existPod, podName)
pods := strings.Split(existPod, ",")
if !util.ContainsString(pods, podName) {
return true
return existPod, true
}
}
if existPod, ok := subnet.V6IPToPod[IP(ip)]; ok {
klog.V(4).Infof("v6 check ip assigned, existPod %s, podName %s", existPod, podName)
pods := strings.Split(existPod, ",")
if !util.ContainsString(pods, podName) {
return true
return existPod, true
}
}
return false
return "", false
}

0 comments on commit c42dae3

Please sign in to comment.