Skip to content

Commit

Permalink
fix static ip error in dual stack (#1598)
Browse files Browse the repository at this point in the history
* fix static ip error in dual stack

* fix static ip error in dual stack
  • Loading branch information
wangyd1988 committed Jun 13, 2022
1 parent 7fdb4bc commit bc86ec8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
14 changes: 8 additions & 6 deletions pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -1258,20 +1258,22 @@ func (c *Controller) acquireAddress(pod *v1.Pod, podNet *kubeovnNet) (string, st
}

// IPPool allocate
ipPool := strings.Split(pod.Annotations[fmt.Sprintf(util.IpPoolAnnotationTemplate, podNet.ProviderName)], ",")
ipPool := strings.Split(pod.Annotations[fmt.Sprintf(util.IpPoolAnnotationTemplate, podNet.ProviderName)], ";")
for i, ip := range ipPool {
ipPool[i] = strings.TrimSpace(ip)
}

if ok, _ := isStatefulSetPod(pod); !ok {
for _, net := range nsNets {
for _, staticIP := range ipPool {
if c.ipam.IsIPAssignedToPod(staticIP, net.Subnet.Name, key) {
klog.Errorf("static address %s for %s has been assigned", staticIP, key)
continue
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)
break
}
}

v4IP, v6IP, mac, err = c.acquireStaticAddress(key, nicName, staticIP, macStr, net.Subnet.Name, net.AllowLiveMigration)
v4IP, v6IP, mac, err = c.acquireStaticAddress(key, nicName, staticIPs, macStr, net.Subnet.Name, net.AllowLiveMigration)
if err == nil {
return v4IP, v6IP, mac, net.Subnet, nil
}
Expand Down
8 changes: 5 additions & 3 deletions pkg/util/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,11 @@ func ValidatePodNetwork(annotations map[string]string) error {

ipPool := annotations[IpPoolAnnotation]
if ipPool != "" {
for _, ip := range strings.Split(ipPool, ",") {
if net.ParseIP(strings.TrimSpace(ip)) == nil {
errors = append(errors, fmt.Errorf("%s in %s is not a valid address", ip, IpPoolAnnotation))
for _, ips := range strings.Split(ipPool, ";") {
for _, ip := range strings.Split(ips, ",") {
if net.ParseIP(strings.TrimSpace(ip)) == nil {
errors = append(errors, fmt.Errorf("%s in %s is not a valid address", ip, IpPoolAnnotation))
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/ip/static_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ var _ = Describe("[IP Allocation]", func() {
"e2e": "true",
},
Annotations: map[string]string{
util.IpPoolAnnotation: strings.Join(ips, ","),
util.IpPoolAnnotation: strings.Join(ips, ";"),
},
},
Spec: corev1.PodSpec{
Expand Down Expand Up @@ -175,7 +175,7 @@ var _ = Describe("[IP Allocation]", func() {
"e2e": "true",
},
Annotations: map[string]string{
util.IpPoolAnnotation: strings.Join(ips, ","),
util.IpPoolAnnotation: strings.Join(ips, ";"),
},
},
Spec: corev1.PodSpec{
Expand Down

0 comments on commit bc86ec8

Please sign in to comment.