Skip to content

Commit 42f35a3

Browse files
authored
ipam: fix ippool with single dual-stack address (#3054)
1 parent 2ba3b8e commit 42f35a3

File tree

4 files changed

+60
-53
lines changed

4 files changed

+60
-53
lines changed

.github/workflows/build-x86-image.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ jobs:
837837
- build-kube-ovn
838838
- build-e2e-binaries
839839
runs-on: ubuntu-22.04
840-
timeout-minutes: 35
840+
timeout-minutes: 40
841841
strategy:
842842
fail-fast: false
843843
matrix:

.github/workflows/scheduled-e2e.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ jobs:
334334
kube-ovn-conformance-e2e:
335335
name: Kube-OVN Conformance E2E
336336
runs-on: ubuntu-22.04
337-
timeout-minutes: 30
337+
timeout-minutes: 40
338338
strategy:
339339
fail-fast: false
340340
matrix:

pkg/controller/pod.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -1553,12 +1553,15 @@ func (c *Controller) acquireAddress(pod *v1.Pod, podNet *kubeovnNet) (string, st
15531553
ipPool = strings.Split(ippoolStr, ";")
15541554
} else {
15551555
ipPool = strings.Split(ippoolStr, ",")
1556+
if len(ipPool) == 2 && util.CheckProtocol(ipPool[0]) != util.CheckProtocol(ipPool[1]) {
1557+
ipPool = []string{ippoolStr}
1558+
}
15561559
}
15571560
for i, ip := range ipPool {
15581561
ipPool[i] = strings.TrimSpace(ip)
15591562
}
15601563

1561-
if len(ipPool) == 1 && net.ParseIP(ipPool[0]) == nil {
1564+
if len(ipPool) == 1 && (!strings.ContainsRune(ipPool[0], ',') && net.ParseIP(ipPool[0]) == nil) {
15621565
var skippedAddrs []string
15631566
for {
15641567
portName := ovs.PodNameToPortName(podName, pod.Namespace, podNet.ProviderName)

test/e2e/kube-ovn/ipam/ipam.go

+54-50
Original file line numberDiff line numberDiff line change
@@ -252,64 +252,68 @@ var _ = framework.Describe("[group:ipam]", func() {
252252
ippoolSep = ","
253253
}
254254

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

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

264-
ginkgo.By("Getting pods for statefulset " + stsName)
265-
pods := stsClient.GetPods(sts)
266-
framework.ExpectHaveLen(pods.Items, replicas)
267-
268-
ips := make([]string, 0, replicas)
269-
for _, pod := range pods.Items {
270-
framework.ExpectHaveKeyWithValue(pod.Annotations, util.AllocatedAnnotation, "true")
271-
framework.ExpectHaveKeyWithValue(pod.Annotations, util.CidrAnnotation, subnet.Spec.CIDRBlock)
272-
framework.ExpectHaveKeyWithValue(pod.Annotations, util.GatewayAnnotation, subnet.Spec.Gateway)
273-
framework.ExpectHaveKeyWithValue(pod.Annotations, util.IpPoolAnnotation, ippool)
274-
framework.ExpectHaveKeyWithValue(pod.Annotations, util.LogicalSwitchAnnotation, subnet.Name)
275-
framework.ExpectMAC(pod.Annotations[util.MacAddressAnnotation])
276-
framework.ExpectHaveKeyWithValue(pod.Annotations, util.RoutedAnnotation, "true")
264+
ginkgo.By("Getting pods for statefulset " + stsName)
265+
pods := stsClient.GetPods(sts)
266+
framework.ExpectHaveLen(pods.Items, replicas)
277267

278-
podIPs := make([]string, 0, len(pod.Status.PodIPs))
279-
for _, podIP := range pod.Status.PodIPs {
280-
podIPs = append(podIPs, podIP.IP)
268+
ips := make([]string, 0, replicas)
269+
for _, pod := range pods.Items {
270+
framework.ExpectHaveKeyWithValue(pod.Annotations, util.AllocatedAnnotation, "true")
271+
framework.ExpectHaveKeyWithValue(pod.Annotations, util.CidrAnnotation, subnet.Spec.CIDRBlock)
272+
framework.ExpectHaveKeyWithValue(pod.Annotations, util.GatewayAnnotation, subnet.Spec.Gateway)
273+
framework.ExpectHaveKeyWithValue(pod.Annotations, util.IpPoolAnnotation, ippool)
274+
framework.ExpectHaveKeyWithValue(pod.Annotations, util.LogicalSwitchAnnotation, subnet.Name)
275+
framework.ExpectMAC(pod.Annotations[util.MacAddressAnnotation])
276+
framework.ExpectHaveKeyWithValue(pod.Annotations, util.RoutedAnnotation, "true")
277+
278+
podIPs := make([]string, 0, len(pod.Status.PodIPs))
279+
for _, podIP := range pod.Status.PodIPs {
280+
podIPs = append(podIPs, podIP.IP)
281+
}
282+
framework.ExpectConsistOf(podIPs, strings.Split(pod.Annotations[util.IpAddressAnnotation], ","))
283+
ips = append(ips, pod.Annotations[util.IpAddressAnnotation])
281284
}
282-
framework.ExpectConsistOf(podIPs, strings.Split(pod.Annotations[util.IpAddressAnnotation], ","))
283-
ips = append(ips, pod.Annotations[util.IpAddressAnnotation])
284-
}
285-
framework.ExpectConsistOf(ips, strings.Split(ippool, ippoolSep))
286-
287-
ginkgo.By("Deleting pods for statefulset " + stsName)
288-
for _, pod := range pods.Items {
289-
err := podClient.Delete(pod.Name)
290-
framework.ExpectNoError(err, "failed to delete pod "+pod.Name)
291-
}
292-
stsClient.WaitForRunningAndReady(sts)
285+
framework.ExpectConsistOf(ips, strings.Split(ippool, ippoolSep))
293286

294-
ginkgo.By("Getting pods for statefulset " + stsName)
295-
pods = stsClient.GetPods(sts)
296-
framework.ExpectHaveLen(pods.Items, replicas)
287+
ginkgo.By("Deleting pods for statefulset " + stsName)
288+
for _, pod := range pods.Items {
289+
err := podClient.Delete(pod.Name)
290+
framework.ExpectNoError(err, "failed to delete pod "+pod.Name)
291+
}
292+
stsClient.WaitForRunningAndReady(sts)
297293

298-
for i, pod := range pods.Items {
299-
framework.ExpectHaveKeyWithValue(pod.Annotations, util.AllocatedAnnotation, "true")
300-
framework.ExpectHaveKeyWithValue(pod.Annotations, util.CidrAnnotation, subnet.Spec.CIDRBlock)
301-
framework.ExpectHaveKeyWithValue(pod.Annotations, util.GatewayAnnotation, subnet.Spec.Gateway)
302-
framework.ExpectHaveKeyWithValue(pod.Annotations, util.IpPoolAnnotation, ippool)
303-
framework.ExpectHaveKeyWithValue(pod.Annotations, util.IpAddressAnnotation, ips[i])
304-
framework.ExpectHaveKeyWithValue(pod.Annotations, util.LogicalSwitchAnnotation, subnet.Name)
305-
framework.ExpectMAC(pod.Annotations[util.MacAddressAnnotation])
306-
framework.ExpectHaveKeyWithValue(pod.Annotations, util.RoutedAnnotation, "true")
294+
ginkgo.By("Getting pods for statefulset " + stsName)
295+
pods = stsClient.GetPods(sts)
296+
framework.ExpectHaveLen(pods.Items, replicas)
307297

308-
podIPs := make([]string, 0, len(pod.Status.PodIPs))
309-
for _, podIP := range pod.Status.PodIPs {
310-
podIPs = append(podIPs, podIP.IP)
298+
for i, pod := range pods.Items {
299+
framework.ExpectHaveKeyWithValue(pod.Annotations, util.AllocatedAnnotation, "true")
300+
framework.ExpectHaveKeyWithValue(pod.Annotations, util.CidrAnnotation, subnet.Spec.CIDRBlock)
301+
framework.ExpectHaveKeyWithValue(pod.Annotations, util.GatewayAnnotation, subnet.Spec.Gateway)
302+
framework.ExpectHaveKeyWithValue(pod.Annotations, util.IpPoolAnnotation, ippool)
303+
framework.ExpectHaveKeyWithValue(pod.Annotations, util.IpAddressAnnotation, ips[i])
304+
framework.ExpectHaveKeyWithValue(pod.Annotations, util.LogicalSwitchAnnotation, subnet.Name)
305+
framework.ExpectMAC(pod.Annotations[util.MacAddressAnnotation])
306+
framework.ExpectHaveKeyWithValue(pod.Annotations, util.RoutedAnnotation, "true")
307+
308+
podIPs := make([]string, 0, len(pod.Status.PodIPs))
309+
for _, podIP := range pod.Status.PodIPs {
310+
podIPs = append(podIPs, podIP.IP)
311+
}
312+
framework.ExpectConsistOf(podIPs, strings.Split(pod.Annotations[util.IpAddressAnnotation], ","))
311313
}
312-
framework.ExpectConsistOf(podIPs, strings.Split(pod.Annotations[util.IpAddressAnnotation], ","))
314+
315+
ginkgo.By("Deleting statefulset " + stsName)
316+
stsClient.DeleteSync(stsName)
313317
}
314318
})
315319

0 commit comments

Comments
 (0)