@@ -32,7 +32,47 @@ func getUnleash(k8sClient client.Client, ctx context.Context, unleash *unleashv1
32
32
return unsetConditionLastTransitionTime (unleash .Status .Conditions ), nil
33
33
}
34
34
35
+ func getDeployment (k8sClient client.Client , ctx context.Context , namespacedName client.ObjectKey , deployment * appsv1.Deployment ) error {
36
+ return k8sClient .Get (ctx , namespacedName , deployment )
37
+ }
38
+
39
+ func setDeploymentStatusFailed (deployment * appsv1.Deployment ) {
40
+ deployment .Status .Conditions = []appsv1.DeploymentCondition {
41
+ {
42
+ Type : appsv1 .DeploymentProgressing ,
43
+ Status : corev1 .ConditionFalse ,
44
+ Reason : "ProgressDeadlineExceeded" ,
45
+ Message : `Progress deadline exceeded.` ,
46
+ LastUpdateTime : metav1.Time {
47
+ Time : time .Now (),
48
+ },
49
+ LastTransitionTime : metav1.Time {
50
+ Time : time .Now (),
51
+ },
52
+ },
53
+ }
54
+ }
55
+
56
+ func setDeploymentStatusAvailable (deployment * appsv1.Deployment ) {
57
+ deployment .Status .Conditions = []appsv1.DeploymentCondition {
58
+ {
59
+ Type : appsv1 .DeploymentProgressing ,
60
+ Status : corev1 .ConditionTrue ,
61
+ Reason : "NewReplicaSetAvailable" ,
62
+ Message : `ReplicaSet "fake-abc123" has successfully progressed.` ,
63
+ LastUpdateTime : metav1.Time {
64
+ Time : time .Now (),
65
+ },
66
+ LastTransitionTime : metav1.Time {
67
+ Time : time .Now (),
68
+ },
69
+ },
70
+ }
71
+ }
72
+
35
73
var _ = Describe ("Unleash controller" , func () {
74
+ deploymentTimeout = time .Second * 1
75
+
36
76
const (
37
77
UnleashNamespace = "default"
38
78
UnleashVersion = "v5.1.2"
@@ -140,6 +180,40 @@ var _ = Describe("Unleash controller", func() {
140
180
Expect (k8sClient .Delete (ctx , createdUnleash )).Should (Succeed ())
141
181
})
142
182
183
+ It ("Should fail if Deployment rollout is not complete" , func () {
184
+ ctx := context .Background ()
185
+
186
+ By ("By creating a new Unleash" )
187
+ unleash := unleashResource ("test-unleash-rollout-fail" , UnleashNamespace , unleashv1.UnleashSpec {
188
+
189
+ Database : unleashv1.UnleashDatabaseConfig {
190
+ URL : "postgres://unleash:unleash@unleash-postgres:5432/unleash?ssl=false" ,
191
+ },
192
+ })
193
+ Expect (k8sClient .Create (ctx , unleash )).Should (Succeed ())
194
+
195
+ By ("By faking Deployment status as failed" )
196
+ createdDeployment := & appsv1.Deployment {}
197
+ Eventually (getDeployment , timeout , interval ).WithArguments (k8sClient , ctx , unleash .NamespacedName (), createdDeployment ).Should (Succeed ())
198
+ setDeploymentStatusFailed (createdDeployment )
199
+ Expect (k8sClient .Status ().Update (ctx , createdDeployment )).Should (Succeed ())
200
+
201
+ By ("By checking that Unleash is failed" )
202
+ createdUnleash := & unleashv1.Unleash {ObjectMeta : unleash .ObjectMeta }
203
+ Eventually (getUnleash , timeout , interval ).WithArguments (k8sClient , ctx , createdUnleash ).Should (ContainElement (metav1.Condition {
204
+ Type : unleashv1 .UnleashStatusConditionTypeReconciled ,
205
+ Status : metav1 .ConditionFalse ,
206
+ Reason : "Reconciling" ,
207
+ Message : "Deployment rollout timed out" ,
208
+ }))
209
+ Expect (createdUnleash .IsReady ()).To (BeFalse ())
210
+ Expect (createdUnleash .Status .Reconciled ).To (BeFalse ())
211
+ Expect (createdUnleash .Status .Connected ).To (BeFalse ())
212
+
213
+ By ("By cleaning up the Unleash" )
214
+ Expect (k8sClient .Delete (ctx , createdUnleash )).Should (Succeed ())
215
+ })
216
+
143
217
PIt ("Should fail when it cannot connect to Unleash" )
144
218
145
219
It ("Should succeed when it can connect to Unleash" , func () {
@@ -153,6 +227,13 @@ var _ = Describe("Unleash controller", func() {
153
227
})
154
228
Expect (k8sClient .Create (ctx , unleash )).Should (Succeed ())
155
229
230
+ By ("By faking Deployment status as available" )
231
+ createdDeployment := & appsv1.Deployment {}
232
+ Eventually (getDeployment , timeout , interval ).WithArguments (k8sClient , ctx , unleash .NamespacedName (), createdDeployment ).Should (Succeed ())
233
+ setDeploymentStatusAvailable (createdDeployment )
234
+ Expect (k8sClient .Status ().Update (ctx , createdDeployment )).Should (Succeed ())
235
+
236
+ By ("By checking that Unleash is connected" )
156
237
createdUnleash := & unleashv1.Unleash {ObjectMeta : unleash .ObjectMeta }
157
238
Eventually (getUnleash , timeout , interval ).WithArguments (k8sClient , ctx , createdUnleash ).Should (ContainElement (metav1.Condition {
158
239
Type : unleashv1 .UnleashStatusConditionTypeConnected ,
@@ -221,6 +302,13 @@ var _ = Describe("Unleash controller", func() {
221
302
})
222
303
Expect (k8sClient .Create (ctx , unleash )).Should (Succeed ())
223
304
305
+ By ("By faking Deployment status as available" )
306
+ createdDeployment := & appsv1.Deployment {}
307
+ Eventually (getDeployment , timeout , interval ).WithArguments (k8sClient , ctx , unleash .NamespacedName (), createdDeployment ).Should (Succeed ())
308
+ setDeploymentStatusAvailable (createdDeployment )
309
+ Expect (k8sClient .Status ().Update (ctx , createdDeployment )).Should (Succeed ())
310
+
311
+ By ("By checking that Unleash is connected" )
224
312
createdUnleash := & unleashv1.Unleash {ObjectMeta : unleash .ObjectMeta }
225
313
Eventually (getUnleash , timeout , interval ).WithArguments (k8sClient , ctx , createdUnleash ).Should (ContainElement (metav1.Condition {
226
314
Type : unleashv1 .UnleashStatusConditionTypeConnected ,
0 commit comments