44package v1alpha1
55
66import (
7+ "github.com/ironcore-dev/metal-operator/internal/controller"
78 . "github.com/onsi/ginkgo/v2"
89 . "github.com/onsi/gomega"
910 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -29,6 +30,14 @@ var _ = Describe("Endpoint Webhook", func() {
2930 Expect (obj ).NotTo (BeNil (), "Expected obj to be initialized" )
3031 })
3132
33+ AfterEach (func () {
34+ By ("Deleting the Endpoint" )
35+ Expect (k8sClient .DeleteAllOf (ctx , & metalv1alpha1.Endpoint {})).To (Succeed ())
36+
37+ By ("Ensuring clean state" )
38+ controller .EnsureCleanState ()
39+ })
40+
3241 Context ("When creating or updating an Endpoint under Validating Webhook" , func () {
3342 It ("Should deny creation if an Endpoint has a duplicate MAC address" , func (ctx SpecContext ) {
3443 By ("Creating an Endpoint" )
@@ -42,7 +51,6 @@ var _ = Describe("Endpoint Webhook", func() {
4251 },
4352 }
4453 Expect (k8sClient .Create (ctx , endpoint )).To (Succeed ())
45- DeferCleanup (k8sClient .Delete , endpoint )
4654
4755 By ("Creating an Endpoint with existing MAC address" )
4856 existingEndpoint := & metalv1alpha1.Endpoint {
@@ -69,7 +77,6 @@ var _ = Describe("Endpoint Webhook", func() {
6977 },
7078 }
7179 Expect (k8sClient .Create (ctx , endpoint )).ToNot (HaveOccurred ())
72- DeferCleanup (k8sClient .Delete , endpoint )
7380
7481 By ("Creating an Endpoint with non-existing MAC address" )
7582 existingEndpoint := & metalv1alpha1.Endpoint {
@@ -96,7 +103,6 @@ var _ = Describe("Endpoint Webhook", func() {
96103 },
97104 }
98105 Expect (k8sClient .Create (ctx , endpoint )).To (Succeed ())
99- DeferCleanup (k8sClient .Delete , endpoint )
100106
101107 By ("Creating an Endpoint with different MAC address" )
102108 existingEndpoint := & metalv1alpha1.Endpoint {
@@ -109,7 +115,6 @@ var _ = Describe("Endpoint Webhook", func() {
109115 },
110116 }
111117 Expect (k8sClient .Create (ctx , existingEndpoint )).To (Succeed ())
112- DeferCleanup (k8sClient .Delete , existingEndpoint )
113118
114119 By ("Updating an Endpoint to conflicting MAC address" )
115120 updatedEndpoint := endpoint .DeepCopy ()
@@ -129,7 +134,6 @@ var _ = Describe("Endpoint Webhook", func() {
129134 },
130135 }
131136 Expect (k8sClient .Create (ctx , existingEndpoint )).To (Succeed ())
132- DeferCleanup (k8sClient .Delete , existingEndpoint )
133137
134138 By ("Updating an Endpoint IP address" )
135139 updatedEndpoint := existingEndpoint .DeepCopy ()
0 commit comments