Skip to content

Commit

Permalink
ipam: fix ippool with single dual-stack address (#3054)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian authored Jul 19, 2023
1 parent 2ba3b8e commit 42f35a3
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-x86-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ jobs:
- build-kube-ovn
- build-e2e-binaries
runs-on: ubuntu-22.04
timeout-minutes: 35
timeout-minutes: 40
strategy:
fail-fast: false
matrix:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scheduled-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ jobs:
kube-ovn-conformance-e2e:
name: Kube-OVN Conformance E2E
runs-on: ubuntu-22.04
timeout-minutes: 30
timeout-minutes: 40
strategy:
fail-fast: false
matrix:
Expand Down
5 changes: 4 additions & 1 deletion pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -1553,12 +1553,15 @@ func (c *Controller) acquireAddress(pod *v1.Pod, podNet *kubeovnNet) (string, st
ipPool = strings.Split(ippoolStr, ";")
} else {
ipPool = strings.Split(ippoolStr, ",")
if len(ipPool) == 2 && util.CheckProtocol(ipPool[0]) != util.CheckProtocol(ipPool[1]) {
ipPool = []string{ippoolStr}
}
}
for i, ip := range ipPool {
ipPool[i] = strings.TrimSpace(ip)
}

if len(ipPool) == 1 && net.ParseIP(ipPool[0]) == nil {
if len(ipPool) == 1 && (!strings.ContainsRune(ipPool[0], ',') && net.ParseIP(ipPool[0]) == nil) {
var skippedAddrs []string
for {
portName := ovs.PodNameToPortName(podName, pod.Namespace, podNet.ProviderName)
Expand Down
104 changes: 54 additions & 50 deletions test/e2e/kube-ovn/ipam/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,64 +252,68 @@ var _ = framework.Describe("[group:ipam]", func() {
ippoolSep = ","
}

replicas := 3
ippool := framework.RandomIPs(cidr, ippoolSep, replicas)
labels := map[string]string{"app": stsName}
for replicas := 1; replicas <= 3; replicas++ {
ippool := framework.RandomIPs(cidr, ippoolSep, replicas)
labels := map[string]string{"app": stsName}

ginkgo.By("Creating statefulset " + stsName + " with ippool " + ippool)
sts := framework.MakeStatefulSet(stsName, stsName, int32(replicas), labels, framework.PauseImage)
sts.Spec.Template.Annotations = map[string]string{util.IpPoolAnnotation: ippool}
sts = stsClient.CreateSync(sts)
ginkgo.By("Creating statefulset " + stsName + " with ippool " + ippool)
sts := framework.MakeStatefulSet(stsName, stsName, int32(replicas), labels, framework.PauseImage)
sts.Spec.Template.Annotations = map[string]string{util.IpPoolAnnotation: ippool}
sts = stsClient.CreateSync(sts)

ginkgo.By("Getting pods for statefulset " + stsName)
pods := stsClient.GetPods(sts)
framework.ExpectHaveLen(pods.Items, replicas)

ips := make([]string, 0, replicas)
for _, pod := range pods.Items {
framework.ExpectHaveKeyWithValue(pod.Annotations, util.AllocatedAnnotation, "true")
framework.ExpectHaveKeyWithValue(pod.Annotations, util.CidrAnnotation, subnet.Spec.CIDRBlock)
framework.ExpectHaveKeyWithValue(pod.Annotations, util.GatewayAnnotation, subnet.Spec.Gateway)
framework.ExpectHaveKeyWithValue(pod.Annotations, util.IpPoolAnnotation, ippool)
framework.ExpectHaveKeyWithValue(pod.Annotations, util.LogicalSwitchAnnotation, subnet.Name)
framework.ExpectMAC(pod.Annotations[util.MacAddressAnnotation])
framework.ExpectHaveKeyWithValue(pod.Annotations, util.RoutedAnnotation, "true")
ginkgo.By("Getting pods for statefulset " + stsName)
pods := stsClient.GetPods(sts)
framework.ExpectHaveLen(pods.Items, replicas)

podIPs := make([]string, 0, len(pod.Status.PodIPs))
for _, podIP := range pod.Status.PodIPs {
podIPs = append(podIPs, podIP.IP)
ips := make([]string, 0, replicas)
for _, pod := range pods.Items {
framework.ExpectHaveKeyWithValue(pod.Annotations, util.AllocatedAnnotation, "true")
framework.ExpectHaveKeyWithValue(pod.Annotations, util.CidrAnnotation, subnet.Spec.CIDRBlock)
framework.ExpectHaveKeyWithValue(pod.Annotations, util.GatewayAnnotation, subnet.Spec.Gateway)
framework.ExpectHaveKeyWithValue(pod.Annotations, util.IpPoolAnnotation, ippool)
framework.ExpectHaveKeyWithValue(pod.Annotations, util.LogicalSwitchAnnotation, subnet.Name)
framework.ExpectMAC(pod.Annotations[util.MacAddressAnnotation])
framework.ExpectHaveKeyWithValue(pod.Annotations, util.RoutedAnnotation, "true")

podIPs := make([]string, 0, len(pod.Status.PodIPs))
for _, podIP := range pod.Status.PodIPs {
podIPs = append(podIPs, podIP.IP)
}
framework.ExpectConsistOf(podIPs, strings.Split(pod.Annotations[util.IpAddressAnnotation], ","))
ips = append(ips, pod.Annotations[util.IpAddressAnnotation])
}
framework.ExpectConsistOf(podIPs, strings.Split(pod.Annotations[util.IpAddressAnnotation], ","))
ips = append(ips, pod.Annotations[util.IpAddressAnnotation])
}
framework.ExpectConsistOf(ips, strings.Split(ippool, ippoolSep))

ginkgo.By("Deleting pods for statefulset " + stsName)
for _, pod := range pods.Items {
err := podClient.Delete(pod.Name)
framework.ExpectNoError(err, "failed to delete pod "+pod.Name)
}
stsClient.WaitForRunningAndReady(sts)
framework.ExpectConsistOf(ips, strings.Split(ippool, ippoolSep))

ginkgo.By("Getting pods for statefulset " + stsName)
pods = stsClient.GetPods(sts)
framework.ExpectHaveLen(pods.Items, replicas)
ginkgo.By("Deleting pods for statefulset " + stsName)
for _, pod := range pods.Items {
err := podClient.Delete(pod.Name)
framework.ExpectNoError(err, "failed to delete pod "+pod.Name)
}
stsClient.WaitForRunningAndReady(sts)

for i, pod := range pods.Items {
framework.ExpectHaveKeyWithValue(pod.Annotations, util.AllocatedAnnotation, "true")
framework.ExpectHaveKeyWithValue(pod.Annotations, util.CidrAnnotation, subnet.Spec.CIDRBlock)
framework.ExpectHaveKeyWithValue(pod.Annotations, util.GatewayAnnotation, subnet.Spec.Gateway)
framework.ExpectHaveKeyWithValue(pod.Annotations, util.IpPoolAnnotation, ippool)
framework.ExpectHaveKeyWithValue(pod.Annotations, util.IpAddressAnnotation, ips[i])
framework.ExpectHaveKeyWithValue(pod.Annotations, util.LogicalSwitchAnnotation, subnet.Name)
framework.ExpectMAC(pod.Annotations[util.MacAddressAnnotation])
framework.ExpectHaveKeyWithValue(pod.Annotations, util.RoutedAnnotation, "true")
ginkgo.By("Getting pods for statefulset " + stsName)
pods = stsClient.GetPods(sts)
framework.ExpectHaveLen(pods.Items, replicas)

podIPs := make([]string, 0, len(pod.Status.PodIPs))
for _, podIP := range pod.Status.PodIPs {
podIPs = append(podIPs, podIP.IP)
for i, pod := range pods.Items {
framework.ExpectHaveKeyWithValue(pod.Annotations, util.AllocatedAnnotation, "true")
framework.ExpectHaveKeyWithValue(pod.Annotations, util.CidrAnnotation, subnet.Spec.CIDRBlock)
framework.ExpectHaveKeyWithValue(pod.Annotations, util.GatewayAnnotation, subnet.Spec.Gateway)
framework.ExpectHaveKeyWithValue(pod.Annotations, util.IpPoolAnnotation, ippool)
framework.ExpectHaveKeyWithValue(pod.Annotations, util.IpAddressAnnotation, ips[i])
framework.ExpectHaveKeyWithValue(pod.Annotations, util.LogicalSwitchAnnotation, subnet.Name)
framework.ExpectMAC(pod.Annotations[util.MacAddressAnnotation])
framework.ExpectHaveKeyWithValue(pod.Annotations, util.RoutedAnnotation, "true")

podIPs := make([]string, 0, len(pod.Status.PodIPs))
for _, podIP := range pod.Status.PodIPs {
podIPs = append(podIPs, podIP.IP)
}
framework.ExpectConsistOf(podIPs, strings.Split(pod.Annotations[util.IpAddressAnnotation], ","))
}
framework.ExpectConsistOf(podIPs, strings.Split(pod.Annotations[util.IpAddressAnnotation], ","))

ginkgo.By("Deleting statefulset " + stsName)
stsClient.DeleteSync(stsName)
}
})

Expand Down

0 comments on commit 42f35a3

Please sign in to comment.