@@ -21,6 +21,7 @@ import (
2121 capz "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
2222 "sigs.k8s.io/controller-runtime/pkg/client"
2323
24+ "github.com/openshift/installer/pkg/asset/ignition/bootstrap"
2425 "github.com/openshift/installer/pkg/asset/manifests/capiutils"
2526 "github.com/openshift/installer/pkg/infrastructure/clusterapi"
2627 "github.com/openshift/installer/pkg/rhcos"
@@ -43,6 +44,7 @@ type Provider struct {
4344var _ clusterapi.PreProvider = (* Provider )(nil )
4445var _ clusterapi.InfraReadyProvider = (* Provider )(nil )
4546var _ clusterapi.PostProvider = (* Provider )(nil )
47+ var _ clusterapi.IgnitionProvider = (* Provider )(nil )
4648
4749// Name returns the name of the provider.
4850func (p * Provider ) Name () string {
@@ -69,6 +71,7 @@ func (p *Provider) PreProvision(ctx context.Context, in clusterapi.PreProvisionI
6971 for k , v := range userTags {
7072 tags [k ] = ptr .To (v )
7173 }
74+ p .Tags = tags
7275
7376 // Create resource group
7477 resourcesClientFactory , err := armresources .NewClientFactory (
@@ -98,9 +101,7 @@ func (p *Provider) PreProvision(ctx context.Context, in clusterapi.PreProvisionI
98101 return fmt .Errorf ("error creating resource group %s: %w" , resourceGroupName , err )
99102 }
100103 logrus .Debugf ("ResourceGroup.ID=%s" , * resourceGroup .ID )
101-
102104 p .ResourceGroupName = resourceGroupName
103- p .Tags = tags
104105
105106 return nil
106107}
@@ -116,9 +117,8 @@ func (p *Provider) InfraReady(ctx context.Context, in clusterapi.InfraReadyInput
116117 platform := installConfig .Platform .Azure
117118 subscriptionID := session .Credentials .SubscriptionID
118119 cloudConfiguration := session .CloudConfig
119- resourceGroupName := p .ResourceGroupName
120- tags := p .Tags
121120
121+ resourceGroupName := p .ResourceGroupName
122122 storageAccountName := fmt .Sprintf ("cluster%s" , randomString (5 ))
123123 containerName := "vhd"
124124 blobName := fmt .Sprintf ("rhcos%s.vhd" , randomString (5 ))
@@ -155,6 +155,13 @@ func (p *Provider) InfraReady(ctx context.Context, in clusterapi.InfraReadyInput
155155 return fmt .Errorf ("image length is not alisnged on a 512 byte boundary" )
156156 }
157157
158+ userTags := platform .UserTags
159+ tags := make (map [string ]* string , len (userTags )+ 1 )
160+ tags [fmt .Sprintf ("kubernetes.io_cluster.%s" , in .InfraID )] = ptr .To ("owned" )
161+ for k , v := range userTags {
162+ tags [k ] = ptr .To (v )
163+ }
164+
158165 tokenCredential := session .TokenCreds
159166 storageURL := fmt .Sprintf ("https://%s.blob.core.windows.net" , storageAccountName )
160167 blobURL := fmt .Sprintf ("%s/%s/%s" , storageURL , containerName , blobName )
@@ -471,3 +478,53 @@ func randomString(length int) string {
471478
472479 return string (s )
473480}
481+
482+ // Ignition provisions the Azure container that holds the bootstrap ignition
483+ // file.
484+ func (p Provider ) Ignition (ctx context.Context , in clusterapi.IgnitionInput ) ([]byte , error ) {
485+ session , err := in .InstallConfig .Azure .Session ()
486+ if err != nil {
487+ return nil , fmt .Errorf ("failed to get session: %w" , err )
488+ }
489+
490+ bootstrapIgnData := in .BootstrapIgnData
491+ subscriptionID := session .Credentials .SubscriptionID
492+ cloudConfiguration := session .CloudConfig
493+
494+ ignitionContainerName := "ignition"
495+ blobName := "bootstrap.ign"
496+ blobURL := fmt .Sprintf ("%s/%s/%s" , p .StorageURL , ignitionContainerName , blobName )
497+
498+ // Create ignition blob storage container
499+ createBlobContainerOutput , err := CreateBlobContainer (ctx , & CreateBlobContainerInput {
500+ ContainerName : ignitionContainerName ,
501+ SubscriptionID : subscriptionID ,
502+ ResourceGroupName : p .ResourceGroupName ,
503+ StorageAccountName : p .StorageAccountName ,
504+ StorageClientFactory : p .StorageClientFactory ,
505+ })
506+ if err != nil {
507+ return nil , err
508+ }
509+
510+ blobIgnitionContainer := createBlobContainerOutput .BlobContainer
511+ logrus .Debugf ("BlobIgnitionContainer.ID=%s" , * blobIgnitionContainer .ID )
512+
513+ sasURL , err := CreateBlockBlob (ctx , & CreateBlockBlobInput {
514+ StorageURL : p .StorageURL ,
515+ BlobURL : blobURL ,
516+ StorageAccountName : p .StorageAccountName ,
517+ StorageAccountKeys : p .StorageAccountKeys ,
518+ CloudConfiguration : cloudConfiguration ,
519+ BootstrapIgnData : bootstrapIgnData ,
520+ })
521+ if err != nil {
522+ return nil , err
523+ }
524+ ignShim , err := bootstrap .GenerateIgnitionShimWithCertBundleAndProxy (sasURL , in .InstallConfig .Config .AdditionalTrustBundle , in .InstallConfig .Config .Proxy )
525+ if err != nil {
526+ return nil , fmt .Errorf ("failed to create ignition shim: %w" , err )
527+ }
528+
529+ return ignShim , nil
530+ }
0 commit comments