@@ -63,8 +63,8 @@ type initOptions struct {
63
63
}
64
64
65
65
const (
66
- capiOperatorProviderName = "capi-operator"
67
- capiOperatorManifestsURL = "https://github.com/kubernetes-sigs/cluster-api-operator/releases/latest /operator-components.yaml"
66
+ capiOperatorProviderName = "capi-operator"
67
+ capiOperatorManifestsURLTemplate = "https://github.com/kubernetes-sigs/cluster-api-operator/releases/%s /operator-components.yaml"
68
68
)
69
69
70
70
var initOpts = & initOptions {}
@@ -127,7 +127,7 @@ func init() {
127
127
"Path to the kubeconfig for the management cluster. If unspecified, default discovery rules apply." )
128
128
initCmd .PersistentFlags ().StringVar (& initOpts .kubeconfigContext , "kubeconfig-context" , "" ,
129
129
"Context to be used within the kubeconfig file. If empty, current context will be used." )
130
- initCmd .PersistentFlags ().StringVar (& initOpts .operatorVersion , "operator-version" , "" ,
130
+ initCmd .PersistentFlags ().StringVar (& initOpts .operatorVersion , "operator-version" , GetLatestPluginVersion () ,
131
131
"CAPI Operator version (e.g. v0.7.0) to install on the management cluster. If unspecified, the latest release is used." )
132
132
initCmd .PersistentFlags ().StringVar (& initOpts .coreProvider , "core" , "" ,
133
133
"Core provider version (e.g. cluster-api:v1.1.5) to add to the management cluster. If unspecified, Cluster API's latest release is used." )
@@ -168,7 +168,7 @@ func runInit() error {
168
168
log .Info ("Checking that Cert Manager is installed and running." )
169
169
170
170
// Ensure that cert manager is installed.
171
- if err := ensureCertManager (initOpts ); err != nil {
171
+ if err := ensureCertManager (ctx , initOpts ); err != nil {
172
172
return fmt .Errorf ("cannot ensure that cert manager is installed: %w" , err )
173
173
}
174
174
@@ -187,7 +187,7 @@ func runInit() error {
187
187
if ! deploymentExists {
188
188
log .Info ("Installing CAPI operator" , "Version" , initOpts .operatorVersion )
189
189
190
- if err := deployCAPIOperator (initOpts ); err != nil {
190
+ if err := deployCAPIOperator (ctx , initOpts ); err != nil {
191
191
return fmt .Errorf ("cannot deploy CAPI operator: %w" , err )
192
192
}
193
193
@@ -340,8 +340,8 @@ func checkProviderReadiness(ctx context.Context, client ctrlclient.Client, gener
340
340
}
341
341
}
342
342
343
- func ensureCertManager (opts * initOptions ) error {
344
- configClient , err := configclient .New ("" )
343
+ func ensureCertManager (ctx context. Context , opts * initOptions ) error {
344
+ configClient , err := configclient .New (ctx , "" )
345
345
if err != nil {
346
346
return fmt .Errorf ("cannot create config client: %w" , err )
347
347
}
@@ -355,23 +355,29 @@ func ensureCertManager(opts *initOptions) error {
355
355
356
356
// Before installing the operator, ensure the cert-manager Webhook is in place.
357
357
certManager := clusterClient .CertManager ()
358
- if err := certManager .EnsureInstalled (); err != nil {
358
+ if err := certManager .EnsureInstalled (ctx ); err != nil {
359
359
return fmt .Errorf ("cannot install cert-manager Webhook: %w" , err )
360
360
}
361
361
362
362
return nil
363
363
}
364
364
365
365
// deployCAPIOperator deploys the CAPI operator on the management cluster.
366
- func deployCAPIOperator (opts * initOptions ) error {
367
- configClient , err := configclient .New ("" )
366
+ func deployCAPIOperator (ctx context. Context , opts * initOptions ) error {
367
+ configClient , err := configclient .New (ctx , "" )
368
368
if err != nil {
369
369
return fmt .Errorf ("cannot create config client: %w" , err )
370
370
}
371
371
372
+ if opts .operatorVersion == "" {
373
+ return fmt .Errorf ("cannot deploy CAPI operator without specifying an operator version" )
374
+ }
375
+
376
+ capiOperatorManifestsURL := fmt .Sprintf (capiOperatorManifestsURLTemplate , opts .operatorVersion )
377
+
372
378
providerConfig := configclient .NewProvider (capiOperatorProviderName , capiOperatorManifestsURL , clusterctlv1 .ProviderTypeUnknown )
373
379
374
- repo , err := util .RepositoryFactory (providerConfig , configClient .Variables ())
380
+ repo , err := util .RepositoryFactory (ctx , providerConfig , configClient .Variables ())
375
381
if err != nil {
376
382
return fmt .Errorf ("cannot create repository: %w" , err )
377
383
}
@@ -380,7 +386,7 @@ func deployCAPIOperator(opts *initOptions) error {
380
386
opts .operatorVersion = repo .DefaultVersion ()
381
387
}
382
388
383
- componentsFile , err := repo .GetFile (opts .operatorVersion , repo .ComponentsPath ())
389
+ componentsFile , err := repo .GetFile (ctx , opts .operatorVersion , repo .ComponentsPath ())
384
390
if err != nil {
385
391
return fmt .Errorf ("cannot get components file: %w" , err )
386
392
}
@@ -409,10 +415,7 @@ func deployCAPIOperator(opts *initOptions) error {
409
415
410
416
clusterClient := cluster .New (clusterKubeconfig , configClient )
411
417
412
- // TODO(mfedosin): we have to ignore wait-providers and wait-providers-timeout options until we upgrade
413
- // to CAPI v1.6.0 where clusterctl functions have Context support.
414
-
415
- if err := clusterClient .ProviderComponents ().Create (components .Objs ()); err != nil {
418
+ if err := clusterClient .ProviderComponents ().Create (ctx , components .Objs ()); err != nil {
416
419
return fmt .Errorf ("cannot create CAPI operator components: %w" , err )
417
420
}
418
421
0 commit comments