@@ -287,7 +287,7 @@ var _ = Describe("OperatorCondition", func() {
287
287
Expect (k8sClient .Create (ctx , operatorCondition )).To (Succeed ())
288
288
})
289
289
290
- It ("injects the OperatorCondition name into the deployment's Environment Variables " , func () {
290
+ It ("should always inject the OperatorCondition Environment Variable into containers defined in the deployment " , func () {
291
291
deployment := & appsv1.Deployment {}
292
292
Eventually (func () error {
293
293
err := k8sClient .Get (ctx , types.NamespacedName {Name : operatorCondition .Spec .Deployments [0 ], Namespace : namespace .GetName ()}, deployment )
@@ -313,6 +313,42 @@ var _ = Describe("OperatorCondition", func() {
313
313
Value : operatorCondition .GetName (),
314
314
}))
315
315
}
316
+
317
+ // Remove the container's Environment Variables defined in the deployment
318
+ Eventually (func () error {
319
+ err := k8sClient .Get (ctx , types.NamespacedName {Name : operatorCondition .Spec .Deployments [0 ], Namespace : namespace .GetName ()}, deployment )
320
+ if err != nil {
321
+ return err
322
+ }
323
+ deployment .Spec .Template .Spec .Containers [0 ].Env = nil
324
+ return k8sClient .Update (ctx , deployment )
325
+ }, timeout , interval ).Should (BeNil ())
326
+
327
+ // Ensure that the OPERATOR_CONDITION_NAME Environment Variable is recreated
328
+ Eventually (func () error {
329
+ err := k8sClient .Get (ctx , types.NamespacedName {Name : operatorCondition .Spec .Deployments [0 ], Namespace : namespace .GetName ()}, deployment )
330
+ if err != nil {
331
+ return err
332
+ }
333
+ if len (deployment .Spec .Template .Spec .Containers ) != 1 {
334
+ return fmt .Errorf ("Deployment should contain a single container" )
335
+ }
336
+ for _ , container := range deployment .Spec .Template .Spec .Containers {
337
+ if len (container .Env ) == 0 {
338
+ return fmt .Errorf ("env vars should exist" )
339
+ }
340
+ }
341
+ return nil
342
+ }, timeout , interval ).Should (BeNil ())
343
+
344
+ Expect (len (deployment .Spec .Template .Spec .Containers )).Should (Equal (1 ))
345
+ for _ , container := range deployment .Spec .Template .Spec .Containers {
346
+ Expect (len (container .Env )).Should (Equal (1 ))
347
+ Expect (container .Env ).Should (ContainElement (corev1.EnvVar {
348
+ Name : "OPERATOR_CONDITION_NAME" ,
349
+ Value : operatorCondition .GetName (),
350
+ }))
351
+ }
316
352
})
317
353
})
318
354
})
0 commit comments