Skip to content

Commit 0ad19c5

Browse files
committed
fix tests
1 parent 1ed463e commit 0ad19c5

File tree

7 files changed

+62
-80
lines changed

7 files changed

+62
-80
lines changed

operators/api/v1alpha2/template_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type TemplateSpec struct {
6363
// The list of environments (i.e. VMs or containers) that compose the Template.
6464
EnvironmentList []Environment `json:"environmentList"`
6565

66-
// +kubebuilder:validation:Pattern="^(never|[0-9]+[mhd])$"
66+
// +kubebuilder:validation:Pattern="^(never|[0-9]+[smhd])$"
6767
// +kubebuilder:default="never"
6868

6969
// The maximum lifetime of an Instance referencing the current Template.
@@ -76,7 +76,7 @@ type TemplateSpec struct {
7676
// Whether the Template has the authorization to be Public Exposed or not, using a LoadBalancer service.
7777
AllowPublicExposure bool `json:"allowPublicExposure,omitempty"`
7878

79-
// +kubebuilder:validation:Pattern="^(never|[0-9]+[mhd])$"
79+
// +kubebuilder:validation:Pattern="^(never|[0-9]+[smhd])$"
8080
// +kubebuilder:default="never"
8181
// The maximum period of inactivity after which an Instance referencing
8282
// the current Template will be automatically stopped or deleted to

operators/cmd/instance-automation/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func main() {
9595
instanceInactiveTerminationNotificationInterval := flag.Duration("instance-inactive-termination-notification-interval", 24*time.Hour, "It represent how long before the instance is deleted the notification email should be sent to the user.")
9696
expirationNotificationInterval := flag.Duration("expiration-notification-interval", 24*time.Hour, "It represent how long before the instance is deleted the notification email should be sent to the user.")
9797

98-
marginTime := flag.Duration("margin-time", 1*time.Minute, "The margin time to add to operations involving time comparisons to avoid edge cases due to delays")
98+
marginTime := flag.Duration("margin-time", 20*time.Second, "The margin time to add to operations involving time comparisons to avoid edge cases due to delays")
9999

100100
flag.StringVar(&containerEnvOpts.ImagesTag, "container-env-sidecars-tag", "latest", "The tag for service containers (such as gui sidecar containers)")
101101
flag.StringVar(&containerEnvOpts.ContentUploaderImg, "container-env-content-uploader-img", "latest", "The image name for the job to compress and upload instance content from a persistent instance.")

operators/deploy/crds/crownlabs.polito.it_templates.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ spec:
8181
Once this period is expired, the Instance may be automatically deleted
8282
or stopped to save resources. If set to "never", the instance will not be
8383
automatically terminated.
84-
pattern: ^(never|[0-9]+[mhd])$
84+
pattern: ^(never|[0-9]+[smhd])$
8585
type: string
8686
description:
8787
description: A textual description of the Template.
@@ -279,7 +279,7 @@ spec:
279279
The maximum period of inactivity after which an Instance referencing
280280
the current Template will be automatically stopped or deleted to
281281
save resources.
282-
pattern: ^(never|[0-9]+[mhd])$
282+
pattern: ^(never|[0-9]+[smhd])$
283283
type: string
284284
prettyName:
285285
description: The human-readable name of the Template.

operators/pkg/instautoctrl/test_e2e/instautoctrl_expiration_test.go

Lines changed: 49 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,21 @@ import (
3535
var _ = 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
})

operators/pkg/instautoctrl/test_e2e/instautoctrl_inactivity_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ var _ = Describe("Instautoctrl-inactivity", func() {
4646
CustomDeleteAfter = instautoctrl.NeverTimeoutValue
4747
CustomInactivityTimeout = instautoctrl.NeverTimeoutValue
4848
CustomDeleteAfterNonPersistent = instautoctrl.NeverTimeoutValue
49-
CustomInactivityTimeoutNonPersistent = "1m"
49+
CustomInactivityTimeoutNonPersistent = "0m"
5050
CustomDeleteAfterPersistent2 = instautoctrl.NeverTimeoutValue
5151
CustomInactivityTimeoutPersistent2 = "0m"
5252

53-
timeout = time.Second * 150
53+
timeout = time.Second * 60
5454
interval = time.Millisecond * 500
5555
)
5656

@@ -572,9 +572,9 @@ var _ = Describe("Instautoctrl-inactivity", func() {
572572
By("Getting current instance")
573573
currentInstance := &crownlabsv1alpha2.Instance{}
574574
instanceLookupKey := types.NamespacedName{Name: PersistentInstanceName2, Namespace: tenant.Namespace}
575-
Expect(k8sClient.Get(ctx, instanceLookupKey, currentInstance)).Should(Succeed())
575+
//Expect(k8sClient.Get(ctx, instanceLookupKey, currentInstance)).Should(Succeed())
576576

577-
// doesEventuallyExists(ctx, instanceLookupKey, currentInstance, BeTrue(), timeout, interval, k8sClient)
577+
doesEventuallyExists(ctx, instanceLookupKey, currentInstance, BeTrue(), timeout, interval, k8sClient)
578578

579579
By("Checking the instance is still running")
580580
Eventually(func() bool {

operators/pkg/instautoctrl/test_e2e/instautoctrl_suite_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ var _ = BeforeSuite(func() {
109109
NotificationInterval: 1 * time.Second,
110110
EnableInactivityNotifications: false,
111111
StatusCheckRequestTimeout: 10 * time.Second,
112+
MarginTime: 10 * time.Second,
112113
}).SetupWithManager(k8sManager, 1)
113114
Expect(err).ToNot(HaveOccurred())
114115

@@ -120,6 +121,7 @@ var _ = BeforeSuite(func() {
120121
MailClient: nil,
121122
NotificationInterval: 1 * time.Second,
122123
EnableExpirationNotifications: false,
124+
MarginTime: 2 * time.Second,
123125
}).SetupWithManager(k8sManager, 1)
124126
Expect(err).ToNot(HaveOccurred())
125127

operators/samples/templates.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ spec:
6464
reservedCPUPercentage: 50
6565
workspace.crownlabs.polito.it/WorkspaceRef:
6666
name: coffee
67-
deleteAfter: 10h
68-
inactivityTimeout: 30m
67+
deleteAfter: 1h
68+
inactivityTimeout: never
6969
---
7070
apiVersion: crownlabs.polito.it/v1alpha2
7171
kind: Template

0 commit comments

Comments
 (0)