@@ -117,6 +117,13 @@ var initCmd = &cobra.Command{
117
117
},
118
118
}
119
119
120
+ var backoffOpts = wait.Backoff {
121
+ Duration : 500 * time .Millisecond ,
122
+ Factor : 1.5 ,
123
+ Steps : 10 ,
124
+ Jitter : 0.4 ,
125
+ }
126
+
120
127
func init () {
121
128
initCmd .PersistentFlags ().StringVar (& initOpts .kubeconfig , "kubeconfig" , "" ,
122
129
"Path to the kubeconfig for the management cluster. If unspecified, default discovery rules apply." )
@@ -188,16 +195,9 @@ func runInit() error {
188
195
return fmt .Errorf ("cannot deploy CAPI operator: %w" , err )
189
196
}
190
197
191
- opts := wait.Backoff {
192
- Duration : 500 * time .Millisecond ,
193
- Factor : 1.5 ,
194
- Steps : 10 ,
195
- Jitter : 0.4 ,
196
- }
197
-
198
198
log .Info ("Waiting for CAPI Operator to be available..." )
199
199
200
- if err := wait .ExponentialBackoff (opts , func () (bool , error ) {
200
+ if err := wait .ExponentialBackoff (backoffOpts , func () (bool , error ) {
201
201
return CheckDeploymentAvailability (ctx , client , capiOperatorLabels )
202
202
}); err != nil {
203
203
return fmt .Errorf ("cannot check CAPI operator availability: %w" , err )
@@ -514,14 +514,21 @@ func createGenericProvider(ctx context.Context, client ctrlclient.Client, provid
514
514
log .Info ("Installing provider" , "Type" , provider .GetType (), "Name" , name , "Version" , version , "Namespace" , namespace )
515
515
516
516
// Create the provider
517
- if err := client .Create (ctx , provider ); err != nil {
518
- if ! apierrors .IsAlreadyExists (err ) {
519
- return nil , fmt .Errorf ("cannot create provider: %w" , err )
520
- }
517
+ if err := wait .ExponentialBackoff (backoffOpts , func () (bool , error ) {
518
+ if err := client .Create (ctx , provider ); err != nil {
519
+ // If the provider already exists, return immediately and do not retry.
520
+ if apierrors .IsAlreadyExists (err ) {
521
+ log .Info ("Provider already exists, skipping creation" , "Type" , provider .GetType (), "Name" , name , "Version" , version , "Namespace" , namespace )
521
522
522
- log .Info ("Provider already exists, skipping creation" , "Type" , provider .GetType (), "Name" , name , "Version" , version , "Namespace" , namespace )
523
+ return true , err
524
+ }
523
525
524
- return nil , err
526
+ return false , err
527
+ }
528
+
529
+ return true , nil
530
+ }); err != nil {
531
+ return nil , fmt .Errorf ("cannot create provider: %w" , err )
525
532
}
526
533
527
534
return provider , nil
0 commit comments