Skip to content

Commit fa65a0a

Browse files
abaysclaudecursoragent
committed
Fix ProvisionServer port exhaustion in envtest functional tests
The functional tests were exhausting the OpenStackProvisionServer port range (6190-6210) when running with parallel Ginkgo processes. envtest does not run the Kubernetes garbage collector, so ProvisionServers created as owned children of BaremetalSets were never cascade-deleted when the parent was removed via DeferCleanup. Additionally, two webhook tests created ProvisionServer resources without any cleanup. These leaked resources accumulated across specs, consuming all 21 available ports and causing later tests to fail. Add a global DeferCleanup in the suite BeforeEach that explicitly deletes all OpenStackProvisionServer resources after each spec, and fix the webhook tests to properly clean up their resources. Closes: OSPRH-30444 Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 84aa9fe commit fa65a0a

2 files changed

Lines changed: 16 additions & 26 deletions

File tree

tests/functional/openstackprovisionserver_webhook_test.go

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,7 @@ var _ = Describe("OpenStackProvisionServer Webhook", func() {
4646
"apacheImageUrl": "registry.redhat.io/ubi9/httpd-24:latest",
4747
"agentImageUrl": "quay.io/openstack-k8s-operators/openstack-baremetal-operator-agent:latest",
4848
}
49-
raw := map[string]interface{}{
50-
"apiVersion": "baremetal.openstack.org/v1beta1",
51-
"kind": "OpenStackProvisionServer",
52-
"metadata": map[string]interface{}{
53-
"name": provisionServerName.Name,
54-
"namespace": provisionServerName.Namespace,
55-
},
56-
"spec": spec,
57-
}
58-
unstructuredObj := &unstructured.Unstructured{Object: raw}
59-
_, err := controllerutil.CreateOrPatch(
60-
th.Ctx, th.K8sClient, unstructuredObj, func() error { return nil })
61-
Expect(err).ShouldNot(HaveOccurred())
49+
DeferCleanup(th.DeleteInstance, CreateProvisionServer(provisionServerName, spec))
6250
})
6351
})
6452

@@ -195,19 +183,7 @@ var _ = Describe("OpenStackProvisionServer Webhook", func() {
195183
"apacheImageUrl": "registry.redhat.io/ubi9/httpd-24:latest",
196184
"agentImageUrl": "quay.io/openstack-k8s-operators/openstack-baremetal-operator-agent:latest",
197185
}
198-
raw := map[string]interface{}{
199-
"apiVersion": "baremetal.openstack.org/v1beta1",
200-
"kind": "OpenStackProvisionServer",
201-
"metadata": map[string]interface{}{
202-
"name": provisionServer2Name.Name,
203-
"namespace": provisionServer2Name.Namespace,
204-
},
205-
"spec": spec,
206-
}
207-
unstructuredObj := &unstructured.Unstructured{Object: raw}
208-
_, err := controllerutil.CreateOrPatch(
209-
th.Ctx, th.K8sClient, unstructuredObj, func() error { return nil })
210-
Expect(err).ShouldNot(HaveOccurred())
186+
DeferCleanup(th.DeleteInstance, CreateProvisionServer(provisionServer2Name, spec))
211187
})
212188
})
213189

tests/functional/suit_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,20 @@ var _ = BeforeEach(func() {
200200
// We still request the delete of the Namespace to properly cleanup if
201201
// we run the test in an existing cluster.
202202
DeferCleanup(th.DeleteNamespace, namespace)
203+
204+
// Explicitly delete all OpenStackProvisionServer resources after each
205+
// spec. envtest does not run the Kubernetes garbage collector, so
206+
// ProvisionServers created as owned children of BaremetalSets are not
207+
// cascade-deleted when the parent is removed. Without this cleanup,
208+
// ports in the 6190-6210 range accumulate across specs until exhausted.
209+
DeferCleanup(func() {
210+
provServerList := &baremetalv1.OpenStackProvisionServerList{}
211+
if err := k8sClient.List(ctx, provServerList); err == nil {
212+
for i := range provServerList.Items {
213+
k8sClient.Delete(ctx, &provServerList.Items[i]) //nolint:errcheck,gosec
214+
}
215+
}
216+
})
203217
})
204218

205219
var _ = AfterSuite(func() {

0 commit comments

Comments
 (0)