@@ -10,6 +10,7 @@ import (
10
10
"os"
11
11
"strconv"
12
12
"strings"
13
+ "time"
13
14
14
15
"github.com/openshift/external-dns-operator/test/common"
15
16
@@ -19,6 +20,7 @@ import (
19
20
appsv1 "k8s.io/api/apps/v1"
20
21
corev1 "k8s.io/api/core/v1"
21
22
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23
+ "k8s.io/apimachinery/pkg/util/wait"
22
24
"sigs.k8s.io/controller-runtime/pkg/client"
23
25
24
26
operatorv1alpha1 "github.com/openshift/external-dns-operator/api/v1alpha1"
@@ -267,9 +269,9 @@ func (h *infobloxTestHelper) trustGridTLSCert() error {
267
269
}
268
270
269
271
// inject into subscription if there is one
270
- findOperatorSubscription := func () (* olmv1alpha1.Subscription , error ) {
272
+ findOperatorSubscription := func (ctx context. Context ) (* olmv1alpha1.Subscription , error ) {
271
273
list := & olmv1alpha1.SubscriptionList {}
272
- if err := common .KubeClient .List (context . TODO () , list , client .InNamespace (operatorNs )); err != nil {
274
+ if err := common .KubeClient .List (ctx , list , client .InNamespace (operatorNs )); err != nil {
273
275
return nil , err
274
276
}
275
277
for _ , sub := range list .Items {
@@ -284,25 +286,33 @@ func (h *infobloxTestHelper) trustGridTLSCert() error {
284
286
}
285
287
return nil , nil
286
288
}
287
- subscription , err := findOperatorSubscription ()
288
- if err != nil {
289
- return fmt .Errorf ("failed to find operator subscription: %w" , err )
290
- }
291
- if subscription != nil {
292
- if subscription .Spec .Config == nil {
293
- subscription .Spec .Config = & olmv1alpha1.SubscriptionConfig {}
289
+
290
+ if err := wait .PollUntilContextTimeout (context .TODO (), 2 * time .Second , 1 * time .Minute , true , func (ctx context.Context ) (bool , error ) {
291
+ subscription , err := findOperatorSubscription (ctx )
292
+ if err != nil {
293
+ fmt .Printf ("failed while finding operator subscription: %v, retrying ...\n " , err )
294
+ return false , nil
294
295
}
295
- subscription .Spec .Config .Env = ensureEnvVar (subscription .Spec .Config .Env , trustedCAEnvVar )
296
- if err := common .KubeClient .Update (context .TODO (), subscription ); err != nil {
297
- return fmt .Errorf ("failed to inject trusted CA environment variable into the subscription: %w" , err )
296
+ if subscription != nil {
297
+ if subscription .Spec .Config == nil {
298
+ subscription .Spec .Config = & olmv1alpha1.SubscriptionConfig {}
299
+ }
300
+ subscription .Spec .Config .Env = ensureEnvVar (subscription .Spec .Config .Env , trustedCAEnvVar )
301
+ if err := common .KubeClient .Update (ctx , subscription ); err != nil {
302
+ fmt .Printf ("failed to inject trusted CA environment variable into the subscription: %v, retrying ...\n " , err )
303
+ return false , nil
304
+ }
305
+ return true , nil
298
306
}
299
- return nil
307
+ fmt .Println ("no suscription was found, trying to update the deployment directly" )
308
+ return true , nil
309
+ }); err != nil {
310
+ return fmt .Errorf ("timed out trying to inject trusted CA into the subscription" )
300
311
}
301
312
302
- // no subscription was found, try to update the deployment directly
303
- findOperatorDeployment := func () (* appsv1.Deployment , error ) {
313
+ findOperatorDeployment := func (ctx context.Context ) (* appsv1.Deployment , error ) {
304
314
list := & appsv1.DeploymentList {}
305
- if err := common .KubeClient .List (context . TODO () , list , client .InNamespace (operatorNs )); err != nil {
315
+ if err := common .KubeClient .List (ctx , list , client .InNamespace (operatorNs )); err != nil {
306
316
return nil , err
307
317
}
308
318
for _ , depl := range list .Items {
@@ -312,22 +322,29 @@ func (h *infobloxTestHelper) trustGridTLSCert() error {
312
322
}
313
323
return nil , nil
314
324
}
315
- deployment , err := findOperatorDeployment ()
316
- if err != nil {
317
- return fmt .Errorf ("failed to find operator deployment: %w" , err )
318
- }
319
- if deployment == nil {
320
- return fmt .Errorf ("no operator deployment found" )
321
- }
325
+ if err := wait .PollUntilContextTimeout (context .TODO (), 2 * time .Second , 1 * time .Minute , true , func (ctx context.Context ) (bool , error ) {
326
+ deployment , err := findOperatorDeployment (ctx )
327
+ if err != nil {
328
+ fmt .Printf ("failed while finding operator deployment: %v, retrying ...\n " , err )
329
+ return false , nil
330
+ }
331
+ if deployment == nil {
332
+ return false , fmt .Errorf ("no operator deployment found" )
333
+ }
322
334
323
- for i := range deployment .Spec .Template .Spec .Containers {
324
- if deployment .Spec .Template .Spec .Containers [i ].Name == operatorContainerName {
325
- deployment .Spec .Template .Spec .Containers [i ].Env = ensureEnvVar (deployment .Spec .Template .Spec .Containers [i ].Env , trustedCAEnvVar )
326
- break
335
+ for i := range deployment .Spec .Template .Spec .Containers {
336
+ if deployment .Spec .Template .Spec .Containers [i ].Name == operatorContainerName {
337
+ deployment .Spec .Template .Spec .Containers [i ].Env = ensureEnvVar (deployment .Spec .Template .Spec .Containers [i ].Env , trustedCAEnvVar )
338
+ break
339
+ }
327
340
}
328
- }
329
- if err := common .KubeClient .Update (context .TODO (), deployment ); err != nil {
330
- return fmt .Errorf ("failed to inject trusted CA environment variable into the deployment: %w" , err )
341
+ if err := common .KubeClient .Update (ctx , deployment ); err != nil {
342
+ fmt .Printf ("failed to inject trusted CA environment variable into the deployment: %v\n " , err )
343
+ return false , nil
344
+ }
345
+ return true , nil
346
+ }); err != nil {
347
+ return fmt .Errorf ("failed trying to inject trusted CA into the subscription: %w" , err )
331
348
}
332
349
333
350
return nil
0 commit comments