@@ -35,20 +35,21 @@ import (
3535var _ = Describe ("Instautoctrl-expiration" , func () {
3636 // Define utility constants for object names and testing timeouts/durations and intervals.
3737 const (
38- PersistentInstanceName = "test-expiration-instance-persistent"
39- NonPersistentInstanceName = "test-expiration-instance-non-persistent"
40- WorkingNamespace = "test-expiration-working-namespace"
41- persistentTemplateName = "test-expiration-template-persistent"
42- nonPersistentTemplateName = "test-expiration-template-non-persistent"
43- TenantName = "test-expiration-tenant"
44- CustomDeleteAfter = instautoctrl .NeverTimeoutValue
45- CustomInactivityTimeout = instautoctrl .NeverTimeoutValue
46- CustomDeleteAfter2 = "0m"
47- CustomInactivityTimeout2 = "2m"
48-
49- timeout = time .Second * 65
50- timeoutSmall = time .Second * 30
51- interval = time .Millisecond * 1000
38+ PersistentInstanceName = "test-expiration-instance-persistent"
39+ NonPersistentInstanceName = "test-expiration-instance-non-persistent"
40+ NonPersistentInstanceName2 = "test-expiration-instance-non-persistent-2"
41+ WorkingNamespace = "test-expiration-working-namespace"
42+ persistentTemplateName = "test-expiration-template-persistent"
43+ nonPersistentTemplateName = "test-expiration-template-non-persistent"
44+ TenantName = "test-expiration-tenant"
45+ CustomDeleteAfter = instautoctrl .NeverTimeoutValue
46+ CustomInactivityTimeout = instautoctrl .NeverTimeoutValue
47+ CustomDeleteAfter2 = "10s"
48+ CustomInactivityTimeout2 = "1m"
49+
50+ timeout = time .Second * 30
51+
52+ interval = time .Millisecond * 1000
5253 )
5354
5455 var (
@@ -162,6 +163,25 @@ var _ = Describe("Instautoctrl-expiration", func() {
162163 Status : crownlabsv1alpha2.InstanceStatus {},
163164 }
164165
166+ nonPersistentInstance2 = crownlabsv1alpha2.Instance {
167+ TypeMeta : metav1.TypeMeta {},
168+ ObjectMeta : metav1.ObjectMeta {
169+ Name : NonPersistentInstanceName2 ,
170+ Namespace : WorkingNamespace ,
171+ },
172+ Spec : crownlabsv1alpha2.InstanceSpec {
173+ Running : false ,
174+ Template : crownlabsv1alpha2.GenericRef {
175+ Name : nonPersistentTemplateName ,
176+ Namespace : WorkingNamespace ,
177+ },
178+ Tenant : crownlabsv1alpha2.GenericRef {
179+ Name : TenantName ,
180+ },
181+ },
182+ Status : crownlabsv1alpha2.InstanceStatus {},
183+ }
184+
165185 tenant = crownlabsv1alpha2.Tenant {
166186 TypeMeta : metav1.TypeMeta {},
167187 ObjectMeta : metav1.ObjectMeta {
@@ -209,8 +229,7 @@ var _ = Describe("Instautoctrl-expiration", func() {
209229 newNs := workingNs .DeepCopy ()
210230 newPersistentTemplate := persistentTemplate .DeepCopy ()
211231 newNonPersistentTemplate := nonPersistentTemplate .DeepCopy ()
212- newPersistentInstance := persistentInstance .DeepCopy ()
213- newNonPersistentInstance := nonPersistentInstance .DeepCopy ()
232+
214233 newTenant := tenant .DeepCopy ()
215234 By ("Creating the namespace where to create instance and template" )
216235 err := k8sClientExpiration .Create (ctx , newNs )
@@ -222,7 +241,7 @@ var _ = Describe("Instautoctrl-expiration", func() {
222241 By ("Deleting instances" )
223242 Expect (client .IgnoreNotFound (k8sClientExpiration .Delete (ctx , & persistentInstance ))).To (Succeed ())
224243 Expect (client .IgnoreNotFound (k8sClientExpiration .Delete (ctx , & nonPersistentInstance ))).To (Succeed ())
225-
244+ Expect ( client . IgnoreNotFound ( k8sClientExpiration . Delete ( ctx , & nonPersistentInstance2 ))). To ( Succeed ())
226245 By ("Deleting tenant" )
227246 Expect (k8sClientExpiration .Delete (ctx , & tenant )).Should (Succeed ())
228247
@@ -257,63 +276,24 @@ var _ = Describe("Instautoctrl-expiration", func() {
257276 createdTenant := & crownlabsv1alpha2.Tenant {}
258277 doesEventuallyExists (ctx , tenantLookupKey , createdTenant , BeTrue (), timeout , interval , k8sClientExpiration )
259278
260- By ("Creating the instances" )
261- Expect (k8sClientExpiration .Create (ctx , newPersistentInstance )).Should (Succeed ())
262- Expect (k8sClientExpiration .Create (ctx , newNonPersistentInstance )).Should (Succeed ())
263-
264- By ("Checking that the instances has been created" )
265- persistanteInstanceLookupKey := types.NamespacedName {Name : PersistentInstanceName , Namespace : WorkingNamespace }
266- nonPersistentInstanceLookupKey := types.NamespacedName {Name : NonPersistentInstanceName , Namespace : WorkingNamespace }
267- createdPersistentInstance := & crownlabsv1alpha2.Instance {}
268- createdNonPersistentInstance := & crownlabsv1alpha2.Instance {}
269-
270- doesEventuallyExists (ctx , persistanteInstanceLookupKey , createdPersistentInstance , BeTrue (), timeout , interval , k8sClientExpiration )
271- doesEventuallyExists (ctx , nonPersistentInstanceLookupKey , createdNonPersistentInstance , BeTrue (), timeout , interval , k8sClientExpiration )
272-
273- })
274-
275- Context ("Testing maximum deletion time" , func () {
276- It ("Should succeed: the persistent VM reached the maximum lifespan and it is deleted" , func () {
277- By ("Getting current instance" )
278- currentInstance := & crownlabsv1alpha2.Instance {}
279- instanceLookupKey := types.NamespacedName {Name : NonPersistentInstanceName , Namespace : WorkingNamespace }
280- Expect (k8sClientExpiration .Get (ctx , instanceLookupKey , currentInstance )).Should (Succeed ())
281-
282- By ("waiting for the persistent VM to reach the maximum deletion time" )
283- doesEventuallyExists (ctx , instanceLookupKey , currentInstance , BeFalse (), timeout , interval , k8sClientExpiration )
284-
285- })
286-
287279 })
288280
289281 Context ("Testing never deletion" , func () {
290- // It("Should succeed: the persistent VM is not deleted because it has a never deletion time", func() {
291- // By("Getting current instance")
292- // currentInstance := &crownlabsv1alpha2.Instance{}
293- // instanceLookupKey := types.NamespacedName{Name: PersistentInstanceName, Namespace: WorkingNamespace}
294- // Expect(k8sClientExpiration.Get(ctx, instanceLookupKey, currentInstance)).Should(Succeed())
295-
296- // By("Checking that the persistent template has a never deletion time")
297- // currentTemplate := &crownlabsv1alpha2.Template{}
298- // templateLookupKey := types.NamespacedName{Name: persistentTemplateName, Namespace: WorkingNamespace}
299- // Expect(k8sClientExpiration.Get(ctx, templateLookupKey, currentTemplate)).Should(Succeed())
300- // Expect(currentTemplate.Spec.DeleteAfter).To(Equal(instautoctrl.NeverTimeoutValue))
301-
302- // By("waiting for the persistent VM to not reach the maximum deletion time")
303- // doesEventuallyExists(ctx, instanceLookupKey, currentInstance, BeTrue(), timeout, interval, k8sClientExpiration)
304-
305- // })
306-
307- It (("Should succeed: the non-persistent VM is not deleted because it has not reached yet the deletion time" ), func () {
308- By ("Getting current instance" )
309- currentInstance := & crownlabsv1alpha2.Instance {}
310- instanceLookupKey := types.NamespacedName {Name : NonPersistentInstanceName , Namespace : WorkingNamespace }
311- Expect (k8sClientExpiration .Get (ctx , instanceLookupKey , currentInstance )).Should (Succeed ())
312-
313- By ("waiting for the non-persistent VM to not reach the maximum deletion time" )
314- doesEventuallyExists (ctx , instanceLookupKey , currentInstance , BeTrue (), timeoutSmall , interval , k8sClientExpiration )
282+ It ("Should succeed: the persistent VM is not deleted because it has a never deletion time" , func () {
283+ By ("Checking that the persistent template has a never deletion time" )
284+ currentTemplate := & crownlabsv1alpha2.Template {}
285+ templateLookupKey := types.NamespacedName {Name : persistentTemplateName , Namespace : WorkingNamespace }
286+ Expect (k8sClientExpiration .Get (ctx , templateLookupKey , currentTemplate )).Should (Succeed ())
287+ Expect (currentTemplate .Spec .DeleteAfter ).To (Equal (instautoctrl .NeverTimeoutValue ))
288+ })
289+ It ("Should succeed: the persistent VM has a valid deletion time and should be deleted" , func () {
290+ currentTemplate := & crownlabsv1alpha2.Template {}
291+ templateLookupKey := types.NamespacedName {Name : nonPersistentTemplateName , Namespace : WorkingNamespace }
292+ Expect (k8sClientExpiration .Get (ctx , templateLookupKey , currentTemplate )).Should (Succeed ())
293+ Expect (currentTemplate .Spec .DeleteAfter ).ToNot (Equal (CustomDeleteAfter ))
315294
316295 })
296+
317297 })
318298
319299})
0 commit comments