Skip to content

Commit 965d5f6

Browse files
committed
Fix flaky NodePort e2e tests #152
1 parent 29fc830 commit 965d5f6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

controllers/tests/kafkacluster_controller_externalnodeport_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package tests
1818
import (
1919
"fmt"
2020
"sync/atomic"
21+
"time"
2122

2223
. "github.com/onsi/ginkgo/v2"
2324
. "github.com/onsi/gomega"
@@ -98,6 +99,23 @@ var _ = Describe("KafkaClusterNodeportExternalAccess", Ordered, func() {
9899
Expect(err).NotTo(HaveOccurred())
99100
// deletes all nodeports in the test namespace, to ensure a clean sheet, as garbage collection does not work in envtest
100101
Expect(deleteNodePorts(ctx, kafkaCluster)).Should(Succeed())
102+
103+
// Wait for services to be fully deleted to prevent port conflicts
104+
Eventually(func() int {
105+
var serviceList corev1.ServiceList
106+
err := k8sClient.List(ctx, &serviceList, client.InNamespace(namespace))
107+
if err != nil {
108+
return -1
109+
}
110+
nodePortCount := 0
111+
for _, service := range serviceList.Items {
112+
if service.Spec.Type == corev1.ServiceTypeNodePort {
113+
nodePortCount++
114+
}
115+
}
116+
return nodePortCount
117+
}, 30*time.Second, 100*time.Millisecond).Should(Equal(0), "NodePort services should be fully deleted")
118+
101119
kafkaCluster = nil
102120
})
103121

controllers/tests/suite_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ func GetNodePort(portAmount int32) int32 {
303303
continue
304304
}
305305

306+
// Ensure the port range doesn't cross into the high conflict zone
307+
if port+portAmount >= 32025 && port <= 32035 {
308+
continue
309+
}
310+
306311
allAvailable := true
307312
for i := int32(0); i <= portAmount; i++ {
308313
if nodePorts[port+i] {

0 commit comments

Comments
 (0)