@@ -15,6 +15,7 @@ import (
1515 "sigs.k8s.io/controller-runtime/pkg/client"
1616 "sigs.k8s.io/controller-runtime/pkg/manager"
1717
18+ "github.com/ydb-platform/ydb-kubernetes-operator/api/v1alpha1"
1819 api "github.com/ydb-platform/ydb-kubernetes-operator/api/v1alpha1"
1920 . "github.com/ydb-platform/ydb-kubernetes-operator/internal/controllers/constants" //nolint:revive,stylecheck
2021 "github.com/ydb-platform/ydb-kubernetes-operator/internal/controllers/monitoring"
@@ -107,6 +108,8 @@ func createMockSvc(name string, parentKind string, parent client.Object) {
107108func createMockDBAndSvc () {
108109 GinkgoHelper ()
109110
111+ createMockStorageAndSvc ()
112+
110113 db := testobjects .DefaultDatabase ()
111114 Expect (k8sClient .Create (ctx , db )).Should (Succeed ())
112115
@@ -128,6 +131,40 @@ func createMockStorageAndSvc() {
128131 createMockSvc ("storage-svc-status" , "Storage" , stor )
129132}
130133
134+ func cleanupMockStorageAndSvc () {
135+ storage := v1alpha1.Storage {}
136+ Expect (k8sClient .Get (ctx , types.NamespacedName {
137+ Name : testobjects .StorageName ,
138+ Namespace : testobjects .YdbNamespace ,
139+ }, & storage ))
140+ Expect (k8sClient .Delete (ctx , & storage )).Should (Succeed ())
141+
142+ svc := corev1.Service {}
143+ Expect (k8sClient .Get (ctx , types.NamespacedName {
144+ Name : "storage-svc-status" ,
145+ Namespace : testobjects .YdbNamespace ,
146+ }, & svc ))
147+ Expect (k8sClient .Delete (ctx , & svc )).Should (Succeed ())
148+ }
149+
150+ func cleanupMockDatabaseAndSvc () {
151+ cleanupMockStorageAndSvc ()
152+
153+ database := v1alpha1.Database {}
154+ Expect (k8sClient .Get (ctx , types.NamespacedName {
155+ Name : testobjects .DatabaseName ,
156+ Namespace : testobjects .YdbNamespace ,
157+ }, & database ))
158+ Expect (k8sClient .Delete (ctx , & database )).Should (Succeed ())
159+
160+ svc := corev1.Service {}
161+ Expect (k8sClient .Get (ctx , types.NamespacedName {
162+ Name : "database-svc-status" ,
163+ Namespace : testobjects .YdbNamespace ,
164+ }, & svc ))
165+ Expect (k8sClient .Delete (ctx , & svc )).Should (Succeed ())
166+ }
167+
131168var _ = Describe ("Create DatabaseMonitoring" , func () {
132169 When ("Database is already ready" , func () {
133170 It ("We must create ServiceMonitor" , func () {
@@ -162,12 +199,14 @@ var _ = Describe("Create DatabaseMonitoring", func() {
162199 }
163200 return false
164201 }, test .Timeout , test .Interval ).Should (BeTrue ())
202+
203+ cleanupMockDatabaseAndSvc ()
165204 })
166205 })
167206})
168207
169208var _ = Describe ("StorageMonitoring tests" , func () {
170- When ("Database is already ready" , func () {
209+ When ("Storage is already ready" , func () {
171210 It ("We must create ServiceMonitor" , func () {
172211 createMockStorageAndSvc ()
173212
@@ -200,6 +239,8 @@ var _ = Describe("StorageMonitoring tests", func() {
200239 }
201240 return false
202241 }, test .Timeout , test .Interval ).Should (BeTrue ())
242+
243+ cleanupMockStorageAndSvc ()
203244 })
204245 })
205246})
0 commit comments