@@ -25,6 +25,9 @@ import (
25
25
"github.com/onsi/gomega"
26
26
corev1 "k8s.io/api/core/v1"
27
27
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28
+ "sigs.k8s.io/controller-runtime/pkg/client"
29
+
30
+ "github.com/deckhouse/virtualization/tests/e2e/config"
28
31
)
29
32
30
33
const (
@@ -40,6 +43,7 @@ type Framework struct {
40
43
41
44
namespace * corev1.Namespace
42
45
namespacesToDelete []string
46
+ resourcesToDelete []client.Object
43
47
}
44
48
45
49
func NewFramework (namespacePrefix string ) * Framework {
@@ -73,12 +77,22 @@ func (f *Framework) Before() {
73
77
gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
74
78
ginkgo .By (fmt .Sprintf ("Created namespace %s" , ns .Name ))
75
79
f .namespace = ns
76
- f .AddNamespaceToDelete (ns .Name )
77
80
}
78
81
}
79
82
80
83
func (f * Framework ) After () {
81
84
ginkgo .GinkgoHelper ()
85
+
86
+ if ! config .IsCleanUpNeeded () {
87
+ return
88
+ }
89
+
90
+ for _ , resource := range f .resourcesToDelete {
91
+ ginkgo .By (fmt .Sprintf ("Delete resource %s" , resource .GetName ()))
92
+ err := f .client .Delete (context .Background (), resource )
93
+ gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
94
+ }
95
+
82
96
for _ , ns := range f .namespacesToDelete {
83
97
ginkgo .By (fmt .Sprintf ("Delete namespace %s" , ns ))
84
98
err := f .KubeClient ().CoreV1 ().Namespaces ().Delete (context .Background (), ns , metav1.DeleteOptions {})
@@ -118,3 +132,7 @@ func (f *Framework) Namespace() *corev1.Namespace {
118
132
func (f * Framework ) AddNamespaceToDelete (name string ) {
119
133
f .namespacesToDelete = append (f .namespacesToDelete , name )
120
134
}
135
+
136
+ func (f * Framework ) AddResourceToDelete (obj client.Object ) {
137
+ f .resourcesToDelete = append (f .resourcesToDelete , obj )
138
+ }
0 commit comments