@@ -58,8 +58,10 @@ type initOptions struct {
58
58
}
59
59
60
60
const (
61
- capiOperatorProviderName = "capi-operator"
62
- capiOperatorManifestsURLTemplate = "https://github.com/kubernetes-sigs/cluster-api-operator/releases/%s/operator-components.yaml"
61
+ capiOperatorProviderName = "capi-operator"
62
+ // We have to specify a version here, because if we set "latest", clusterctl libs will try to fetch metadata.yaml file for the latest
63
+ // release and fail since CAPI operator doesn't provide this file.
64
+ capiOperatorManifestsURL = "https://github.com/kubernetes-sigs/cluster-api-operator/releases/v0.1.0/operator-components.yaml"
63
65
)
64
66
65
67
var initOpts = & initOptions {}
@@ -115,6 +117,13 @@ var initCmd = &cobra.Command{
115
117
},
116
118
}
117
119
120
+ var backoffOpts = wait.Backoff {
121
+ Duration : 500 * time .Millisecond ,
122
+ Factor : 1.5 ,
123
+ Steps : 10 ,
124
+ Jitter : 0.4 ,
125
+ }
126
+
118
127
func init () {
119
128
initCmd .PersistentFlags ().StringVar (& initOpts .kubeconfig , "kubeconfig" , "" ,
120
129
"Path to the kubeconfig for the management cluster. If unspecified, default discovery rules apply." )
@@ -186,16 +195,9 @@ func runInit() error {
186
195
return fmt .Errorf ("cannot deploy CAPI operator: %w" , err )
187
196
}
188
197
189
- opts := wait.Backoff {
190
- Duration : 500 * time .Millisecond ,
191
- Factor : 1.5 ,
192
- Steps : 10 ,
193
- Jitter : 0.4 ,
194
- }
195
-
196
198
log .Info ("Waiting for CAPI Operator to be available..." )
197
199
198
- if err := wait .ExponentialBackoff (opts , func () (bool , error ) {
200
+ if err := wait .ExponentialBackoff (backoffOpts , func () (bool , error ) {
199
201
return CheckDeploymentAvailability (ctx , client , capiOperatorLabels )
200
202
}); err != nil {
201
203
return fmt .Errorf ("cannot check CAPI operator availability: %w" , err )
@@ -383,8 +385,6 @@ func deployCAPIOperator(ctx context.Context, opts *initOptions) error {
383
385
return fmt .Errorf ("cannot create config client: %w" , err )
384
386
}
385
387
386
- capiOperatorManifestsURL := fmt .Sprintf (capiOperatorManifestsURLTemplate , opts .operatorVersion )
387
-
388
388
providerConfig := configclient .NewProvider (capiOperatorProviderName , capiOperatorManifestsURL , clusterctlv1 .ProviderTypeUnknown )
389
389
390
390
// Reduce waiting time for the repository creation from 30 seconds to 5.
@@ -397,7 +397,11 @@ func deployCAPIOperator(ctx context.Context, opts *initOptions) error {
397
397
}
398
398
399
399
if opts .operatorVersion == latestVersion {
400
- opts .operatorVersion = repo .DefaultVersion ()
400
+ // Detecting the latest release by sorting all available tags and picking that last one with release.
401
+ opts .operatorVersion , err = GetLatestRelease (ctx , repo )
402
+ if err != nil {
403
+ return fmt .Errorf ("cannot get latest release: %w" , err )
404
+ }
401
405
402
406
log .Info ("Detected latest operator version" , "Version" , opts .operatorVersion )
403
407
}
@@ -510,14 +514,21 @@ func createGenericProvider(ctx context.Context, client ctrlclient.Client, provid
510
514
log .Info ("Installing provider" , "Type" , provider .GetType (), "Name" , name , "Version" , version , "Namespace" , namespace )
511
515
512
516
// Create the provider
513
- if err := client .Create (ctx , provider ); err != nil {
514
- if ! apierrors .IsAlreadyExists (err ) {
515
- return nil , fmt .Errorf ("cannot create provider: %w" , err )
516
- }
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 )
522
+
523
+ return true , err
524
+ }
517
525
518
- log .Info ("Provider already exists, skipping creation" , "Type" , provider .GetType (), "Name" , name , "Version" , version , "Namespace" , namespace )
526
+ return false , err
527
+ }
519
528
520
- return nil , err
529
+ return true , nil
530
+ }); err != nil {
531
+ return nil , fmt .Errorf ("cannot create provider: %w" , err )
521
532
}
522
533
523
534
return provider , nil
0 commit comments