@@ -38,17 +38,34 @@ var _ = Describe("AppWrapper Controller", func() {
38
38
var awReconciler * AppWrapperReconciler
39
39
var awName types.NamespacedName
40
40
markerPodSet := podset.PodSetInfo {
41
- Labels : map [string ]string {"testkey1" : "value1" },
42
- Annotations : map [string ]string {"test2" : "test2" },
41
+ Labels : map [string ]string {"testkey1" : "value1" },
42
+ Annotations : map [string ]string {"test2" : "test2" },
43
+ NodeSelector : map [string ]string {"nodeName" : "myNode" },
44
+ Tolerations : []v1.Toleration {{Key : "aKey" , Operator : "Exists" , Effect : "NoSchedule" }},
43
45
}
44
46
var kueuePodSets []kueue.PodSet
45
47
46
- advanceToRunning := func () {
48
+ advanceToResuming := func (components ... workloadv1beta2.AppWrapperComponent ) {
49
+ By ("Create an AppWrapper" )
50
+ aw := toAppWrapper (components ... )
51
+ aw .Spec .Suspend = true
52
+ Expect (k8sClient .Create (ctx , aw )).To (Succeed ())
53
+ awName = types.NamespacedName {
54
+ Name : aw .Name ,
55
+ Namespace : aw .Namespace ,
56
+ }
57
+ awReconciler = & AppWrapperReconciler {
58
+ Client : k8sClient ,
59
+ Scheme : k8sClient .Scheme (),
60
+ Config : & config.AppWrapperConfig {ManageJobsWithoutQueueName : true , StandaloneMode : false },
61
+ }
62
+ kueuePodSets = (* workload .AppWrapper )(aw ).PodSets ()
63
+
47
64
By ("Reconciling: Empty -> Suspended" )
48
65
_ , err := awReconciler .Reconcile (ctx , reconcile.Request {NamespacedName : awName })
49
66
Expect (err ).NotTo (HaveOccurred ())
50
67
51
- aw : = getAppWrapper (awName )
68
+ aw = getAppWrapper (awName )
52
69
Expect (aw .Status .Phase ).Should (Equal (workloadv1beta2 .AppWrapperSuspended ))
53
70
Expect (controllerutil .ContainsFinalizer (aw , AppWrapperFinalizer )).Should (BeTrue ())
54
71
@@ -67,12 +84,14 @@ var _ = Describe("AppWrapper Controller", func() {
67
84
Expect (meta .IsStatusConditionTrue (aw .Status .Conditions , string (workloadv1beta2 .QuotaReserved ))).Should (BeTrue ())
68
85
Expect ((* workload .AppWrapper )(aw ).IsActive ()).Should (BeTrue ())
69
86
Expect ((* workload .AppWrapper )(aw ).IsSuspended ()).Should (BeFalse ())
87
+ }
70
88
89
+ beginRunning := func () {
71
90
By ("Reconciling: Resuming -> Running" )
72
- _ , err = awReconciler .Reconcile (ctx , reconcile.Request {NamespacedName : awName })
91
+ _ , err : = awReconciler .Reconcile (ctx , reconcile.Request {NamespacedName : awName })
73
92
Expect (err ).NotTo (HaveOccurred ())
74
93
75
- aw = getAppWrapper (awName )
94
+ aw : = getAppWrapper (awName )
76
95
Expect (aw .Status .Phase ).Should (Equal (workloadv1beta2 .AppWrapperRunning ))
77
96
Expect (meta .IsStatusConditionTrue (aw .Status .Conditions , string (workloadv1beta2 .ResourcesDeployed ))).Should (BeTrue ())
78
97
Expect (meta .IsStatusConditionTrue (aw .Status .Conditions , string (workloadv1beta2 .QuotaReserved ))).Should (BeTrue ())
@@ -83,10 +102,30 @@ var _ = Describe("AppWrapper Controller", func() {
83
102
Expect (err ).NotTo (HaveOccurred ())
84
103
Expect (podStatus .pending ).Should (Equal (utils .ExpectedPodCount (aw )))
85
104
105
+ By ("Simulating first Pod Running" )
106
+ Expect (setPodStatus (aw , v1 .PodRunning , 1 )).To (Succeed ())
107
+ By ("Reconciling: Running -> Running" )
108
+ _ , err = awReconciler .Reconcile (ctx , reconcile.Request {NamespacedName : awName })
109
+ Expect (err ).NotTo (HaveOccurred ())
110
+
111
+ aw = getAppWrapper (awName )
112
+ Expect (aw .Status .Phase ).Should (Equal (workloadv1beta2 .AppWrapperRunning ))
113
+ Expect (meta .IsStatusConditionTrue (aw .Status .Conditions , string (workloadv1beta2 .ResourcesDeployed ))).Should (BeTrue ())
114
+ Expect (meta .IsStatusConditionTrue (aw .Status .Conditions , string (workloadv1beta2 .QuotaReserved ))).Should (BeTrue ())
115
+ Expect (meta .IsStatusConditionTrue (aw .Status .Conditions , string (workloadv1beta2 .PodsReady ))).Should (BeFalse ())
116
+ Expect ((* workload .AppWrapper )(aw ).IsActive ()).Should (BeTrue ())
117
+ Expect ((* workload .AppWrapper )(aw ).IsSuspended ()).Should (BeFalse ())
118
+ podStatus , err = awReconciler .workloadStatus (ctx , aw )
119
+ Expect (err ).NotTo (HaveOccurred ())
120
+ Expect (podStatus .pending ).Should (Equal (utils .ExpectedPodCount (aw ) - 1 ))
121
+ }
122
+
123
+ fullyRunning := func () {
124
+ aw := getAppWrapper (awName )
86
125
By ("Simulating all Pods Running" )
87
126
Expect (setPodStatus (aw , v1 .PodRunning , utils .ExpectedPodCount (aw ))).To (Succeed ())
88
127
By ("Reconciling: Running -> Running" )
89
- _ , err = awReconciler .Reconcile (ctx , reconcile.Request {NamespacedName : awName })
128
+ _ , err : = awReconciler .Reconcile (ctx , reconcile.Request {NamespacedName : awName })
90
129
Expect (err ).NotTo (HaveOccurred ())
91
130
92
131
aw = getAppWrapper (awName )
@@ -97,30 +136,13 @@ var _ = Describe("AppWrapper Controller", func() {
97
136
Expect ((* workload .AppWrapper )(aw ).IsActive ()).Should (BeTrue ())
98
137
Expect ((* workload .AppWrapper )(aw ).IsSuspended ()).Should (BeFalse ())
99
138
Expect ((* workload .AppWrapper )(aw ).PodsReady ()).Should (BeTrue ())
100
- podStatus , err = awReconciler .workloadStatus (ctx , aw )
139
+ podStatus , err : = awReconciler .workloadStatus (ctx , aw )
101
140
Expect (err ).NotTo (HaveOccurred ())
102
141
Expect (podStatus .running ).Should (Equal (utils .ExpectedPodCount (aw )))
103
142
_ , finished := (* workload .AppWrapper )(aw ).Finished ()
104
143
Expect (finished ).Should (BeFalse ())
105
144
}
106
145
107
- BeforeEach (func () {
108
- By ("Create an AppWrapper containing two Pods" )
109
- aw := toAppWrapper (pod (100 ), pod (100 ))
110
- aw .Spec .Suspend = true
111
- Expect (k8sClient .Create (ctx , aw )).To (Succeed ())
112
- awName = types.NamespacedName {
113
- Name : aw .Name ,
114
- Namespace : aw .Namespace ,
115
- }
116
- awReconciler = & AppWrapperReconciler {
117
- Client : k8sClient ,
118
- Scheme : k8sClient .Scheme (),
119
- Config : & config.AppWrapperConfig {ManageJobsWithoutQueueName : true , StandaloneMode : false },
120
- }
121
- kueuePodSets = (* workload .AppWrapper )(aw ).PodSets ()
122
- })
123
-
124
146
AfterEach (func () {
125
147
By ("Cleanup the AppWrapper and ensure no Pods remain" )
126
148
aw := & workloadv1beta2.AppWrapper {}
@@ -139,7 +161,9 @@ var _ = Describe("AppWrapper Controller", func() {
139
161
})
140
162
141
163
It ("Happy Path Lifecycle" , func () {
142
- advanceToRunning ()
164
+ advanceToResuming (pod (100 ), pod (100 ))
165
+ beginRunning ()
166
+ fullyRunning ()
143
167
144
168
By ("Simulating one Pod Completing" )
145
169
aw := getAppWrapper (awName )
@@ -176,9 +200,11 @@ var _ = Describe("AppWrapper Controller", func() {
176
200
})
177
201
178
202
It ("Running Workloads can be Suspended" , func () {
179
- advanceToRunning ()
203
+ advanceToResuming (pod (100 ), pod (100 ))
204
+ beginRunning ()
205
+ fullyRunning ()
180
206
181
- By ("Updating aw.Spec by invoking RunWithPodSetsInfo " )
207
+ By ("Inoking Suspend and RestorePodSetsInfo " )
182
208
aw := getAppWrapper (awName )
183
209
(* workload .AppWrapper )(aw ).Suspend ()
184
210
Expect ((* workload .AppWrapper )(aw ).RestorePodSetsInfo (utilslices .Map (kueuePodSets , podset .FromPodSet ))).To (BeTrue ())
@@ -212,8 +238,10 @@ var _ = Describe("AppWrapper Controller", func() {
212
238
Expect (podStatus .failed + podStatus .succeeded + podStatus .running + podStatus .pending ).Should (Equal (int32 (0 )))
213
239
})
214
240
215
- It ("A Pod Failure leads to a failed AppWrappers" , func () {
216
- advanceToRunning ()
241
+ It ("A Pod Failure leads to a failed AppWrapper" , func () {
242
+ advanceToResuming (pod (100 ), pod (100 ))
243
+ beginRunning ()
244
+ fullyRunning ()
217
245
218
246
By ("Simulating one Pod Failing" )
219
247
aw := getAppWrapper (awName )
@@ -248,4 +276,23 @@ var _ = Describe("AppWrapper Controller", func() {
248
276
Expect (finished ).Should (BeTrue ())
249
277
})
250
278
279
+ It ("Failure during resource creation leads to a failed AppWrapper" , func () {
280
+ advanceToResuming (pod (100 ), malformedPod (100 ))
281
+
282
+ By ("Reconciling: Resuming -> Failed" )
283
+ _ , err := awReconciler .Reconcile (ctx , reconcile.Request {NamespacedName : awName })
284
+ Expect (err ).NotTo (HaveOccurred ())
285
+
286
+ aw := getAppWrapper (awName )
287
+ Expect (aw .Status .Phase ).Should (Equal (workloadv1beta2 .AppWrapperFailed ))
288
+ Expect (meta .IsStatusConditionTrue (aw .Status .Conditions , string (workloadv1beta2 .ResourcesDeployed ))).Should (BeTrue ())
289
+ Expect (meta .IsStatusConditionTrue (aw .Status .Conditions , string (workloadv1beta2 .QuotaReserved ))).Should (BeTrue ())
290
+ Expect (meta .IsStatusConditionTrue (aw .Status .Conditions , string (workloadv1beta2 .PodsReady ))).Should (BeFalse ())
291
+ Expect ((* workload .AppWrapper )(aw ).IsActive ()).Should (BeTrue ())
292
+ Expect ((* workload .AppWrapper )(aw ).IsSuspended ()).Should (BeFalse ())
293
+ podStatus , err := awReconciler .workloadStatus (ctx , aw )
294
+ Expect (err ).NotTo (HaveOccurred ())
295
+ Expect (podStatus .pending ).Should (Equal (int32 (1 )))
296
+ })
297
+
251
298
})
0 commit comments