@@ -159,6 +159,10 @@ func createSSHFunctionAndExpectReady(
159159 err = k8sClient .Create (ctx , function )
160160 Expect (err ).NotTo (HaveOccurred ())
161161
162+ utils .DeferCleanupOnSuccess (func () {
163+ _ , _ = utils .RunCmd ("kubectl" , "delete" , "function" , function .Name , "--namespace" , function .Namespace )
164+ })
165+
162166 Eventually (functionBecomesReady (function .Name , functionNamespace )).Should (Succeed ())
163167 return function .Name
164168}
@@ -216,13 +220,6 @@ var _ = Describe("Operator", func() {
216220
217221 AfterEach (func () {
218222 logFailedTestDetails (functionName , functionNamespace )
219-
220- // Cleanup function resource
221- if functionName != "" {
222- cmd := exec .Command ("kubectl" , "delete" , "function" , functionName , "-n" , functionNamespace , "--ignore-not-found" )
223- _ , err := utils .Run (cmd )
224- Expect (err ).NotTo (HaveOccurred ())
225- }
226223 })
227224
228225 It ("should mark the function as ready" , func () {
@@ -242,6 +239,10 @@ var _ = Describe("Operator", func() {
242239 err := k8sClient .Create (ctx , function )
243240 Expect (err ).NotTo (HaveOccurred ())
244241
242+ utils .DeferCleanupOnSuccess (func () {
243+ _ , _ = utils .RunCmd ("kubectl" , "delete" , "function" , function .Name , "--namespace" , function .Namespace )
244+ })
245+
245246 functionName = function .Name
246247
247248 Eventually (functionBecomesReady (functionName , functionNamespace )).Should (Succeed ())
@@ -296,13 +297,6 @@ var _ = Describe("Operator", func() {
296297
297298 AfterEach (func () {
298299 logFailedTestDetails (functionName , functionNamespace )
299-
300- // Cleanup function resource
301- if functionName != "" {
302- cmd := exec .Command ("kubectl" , "delete" , "function" , functionName , "-n" , functionNamespace , "--ignore-not-found" )
303- _ , err := utils .Run (cmd )
304- Expect (err ).NotTo (HaveOccurred ())
305- }
306300 })
307301
308302 It ("should mark the function as ready" , func () {
@@ -323,6 +317,10 @@ var _ = Describe("Operator", func() {
323317 err := k8sClient .Create (ctx , function )
324318 Expect (err ).NotTo (HaveOccurred ())
325319
320+ utils .DeferCleanupOnSuccess (func () {
321+ _ , _ = utils .RunCmd ("kubectl" , "delete" , "function" , function .Name , "--namespace" , function .Namespace )
322+ })
323+
326324 functionName = function .Name
327325
328326 Eventually (functionBecomesReady (functionName , functionNamespace )).Should (Succeed ())
@@ -356,12 +354,7 @@ var _ = Describe("Operator", func() {
356354 })
357355
358356 AfterEach (func () {
359- // Cleanup function resource
360- if functionName != "" {
361- cmd := exec .Command ("kubectl" , "delete" , "function" , functionName , "-n" , functionNamespace , "--ignore-not-found" )
362- _ , err := utils .Run (cmd )
363- Expect (err ).NotTo (HaveOccurred ())
364- }
357+ logFailedTestDetails (functionName , functionNamespace )
365358 })
366359
367360 It ("should mark the function as not ready" , func () {
@@ -381,6 +374,10 @@ var _ = Describe("Operator", func() {
381374 err := k8sClient .Create (ctx , function )
382375 Expect (err ).NotTo (HaveOccurred ())
383376
377+ utils .DeferCleanupOnSuccess (func () {
378+ _ , _ = utils .RunCmd ("kubectl" , "delete" , "function" , function .Name , "--namespace" , function .Namespace )
379+ })
380+
384381 functionName = function .Name
385382
386383 Eventually (functionNotDeployed (functionName , functionNamespace ), 2 * time .Minute ).Should (Succeed ())
@@ -435,13 +432,6 @@ var _ = Describe("Operator", func() {
435432
436433 AfterEach (func () {
437434 logFailedTestDetails (functionName , functionNamespace )
438-
439- // Cleanup function resource
440- if functionName != "" {
441- cmd := exec .Command ("kubectl" , "delete" , "function" , functionName , "-n" , functionNamespace , "--ignore-not-found" )
442- _ , err := utils .Run (cmd )
443- Expect (err ).NotTo (HaveOccurred ())
444- }
445435 })
446436
447437 Context ("using token authentication" , func () {
@@ -481,6 +471,10 @@ var _ = Describe("Operator", func() {
481471 err = k8sClient .Create (ctx , function )
482472 Expect (err ).NotTo (HaveOccurred ())
483473
474+ utils .DeferCleanupOnSuccess (func () {
475+ _ , _ = utils .RunCmd ("kubectl" , "delete" , "function" , function .Name , "--namespace" , function .Namespace )
476+ })
477+
484478 functionName = function .Name
485479
486480 Eventually (functionBecomesReady (functionName , functionNamespace )).Should (Succeed ())
@@ -504,6 +498,10 @@ var _ = Describe("Operator", func() {
504498 err := k8sClient .Create (ctx , function )
505499 Expect (err ).NotTo (HaveOccurred ())
506500
501+ utils .DeferCleanupOnSuccess (func () {
502+ _ , _ = utils .RunCmd ("kubectl" , "delete" , "function" , function .Name , "--namespace" , function .Namespace )
503+ })
504+
507505 functionName = function .Name
508506
509507 Eventually (functionNotReadyWithAuthError (functionName , functionNamespace ), 2 * time .Minute ).Should (Succeed ())
@@ -548,6 +546,10 @@ var _ = Describe("Operator", func() {
548546 err = k8sClient .Create (ctx , function )
549547 Expect (err ).NotTo (HaveOccurred ())
550548
549+ utils .DeferCleanupOnSuccess (func () {
550+ _ , _ = utils .RunCmd ("kubectl" , "delete" , "function" , function .Name , "--namespace" , function .Namespace )
551+ })
552+
551553 functionName = function .Name
552554
553555 Eventually (functionBecomesReady (functionName , functionNamespace )).Should (Succeed ())
@@ -571,6 +573,10 @@ var _ = Describe("Operator", func() {
571573 err := k8sClient .Create (ctx , function )
572574 Expect (err ).NotTo (HaveOccurred ())
573575
576+ utils .DeferCleanupOnSuccess (func () {
577+ _ , _ = utils .RunCmd ("kubectl" , "delete" , "function" , function .Name , "--namespace" , function .Namespace )
578+ })
579+
574580 functionName = function .Name
575581
576582 Eventually (functionNotReadyWithAuthError (functionName , functionNamespace ), 2 * time .Minute ).Should (Succeed ())
@@ -636,12 +642,6 @@ var _ = Describe("Operator", func() {
636642
637643 AfterEach (func () {
638644 logFailedTestDetails (functionName , functionNamespace )
639-
640- if functionName != "" {
641- cmd := exec .Command ("kubectl" , "delete" , "function" , functionName , "-n" , functionNamespace , "--ignore-not-found" )
642- _ , err := utils .Run (cmd )
643- Expect (err ).NotTo (HaveOccurred ())
644- }
645645 })
646646
647647 It ("should mark the function as ready with SSH key auth" , func () {
@@ -714,12 +714,6 @@ var _ = Describe("Operator", func() {
714714
715715 AfterEach (func () {
716716 logFailedTestDetails (functionName , functionNamespace )
717-
718- if functionName != "" {
719- cmd := exec .Command ("kubectl" , "delete" , "function" , functionName , "-n" , functionNamespace , "--ignore-not-found" )
720- _ , err := utils .Run (cmd )
721- Expect (err ).NotTo (HaveOccurred ())
722- }
723717 })
724718
725719 It ("should mark the function as ready when SSH key authSecretRef is provided" , func () {
@@ -743,6 +737,10 @@ var _ = Describe("Operator", func() {
743737 err := k8sClient .Create (ctx , function )
744738 Expect (err ).NotTo (HaveOccurred ())
745739
740+ utils .DeferCleanupOnSuccess (func () {
741+ _ , _ = utils .RunCmd ("kubectl" , "delete" , "function" , function .Name , "--namespace" , function .Namespace )
742+ })
743+
746744 functionName = function .Name
747745
748746 Eventually (functionNotReadyWithAuthError (functionName , functionNamespace ), 2 * time .Minute ).Should (Succeed ())
0 commit comments