@@ -76,7 +76,13 @@ func CreateStorage(ctx context.Context, ic *installconfig.InstallConfig, bucketH
7676}
7777
7878// CreateSignedURL creates a signed url and correlates the signed url with a storage bucket.
79- func CreateSignedURL (handle * storage.BucketHandle , objectName string ) (string , error ) {
79+ func CreateSignedURL (clusterID string ) (string , error ) {
80+ bucketName := GetBootstrapStorageName (clusterID )
81+ handle , err := CreateBucketHandle (context .Background (), bucketName )
82+ if err != nil {
83+ return "" , fmt .Errorf ("creating presigned url, failed to create bucket handle: %w" , err )
84+ }
85+
8086 // Signing a URL requires credentials authorized to sign a URL. You can pass
8187 // these in through SignedURLOptions with a Google Access ID with
8288 // iam.serviceAccounts.signBlob permissions.
@@ -88,44 +94,45 @@ func CreateSignedURL(handle *storage.BucketHandle, objectName string) (string, e
8894
8995 // The object has not been created yet. This is ok, it is expected to be created after this call.
9096 // However, if the object is never created this could cause major issues.
91- url , err := handle .SignedURL (objectName , & opts )
97+ url , err := handle .SignedURL (bootstrapIgnitionBucketObjName , & opts )
9298 if err != nil {
9399 return "" , fmt .Errorf ("failed to create a signed url: %w" , err )
94100 }
95101
96102 return url , nil
97103}
98104
99- // ProvisionBootstrapStorage will provision the required storage bucket and signed url for the bootstrap process .
100- func ProvisionBootstrapStorage (ctx context.Context , ic * installconfig. InstallConfig , bucketHandle * storage.BucketHandle , clusterID string ) ( string , error ) {
105+ // FillBucket will add the contents to the bootstrap storage bucket object .
106+ func FillBucket (ctx context.Context , bucketHandle * storage.BucketHandle , contents string ) error {
101107 ctx , cancel := context .WithTimeout (ctx , time .Minute * 1 )
102108 defer cancel ()
103109
104- if err := CreateStorage (ctx , ic , bucketHandle , clusterID ); err != nil {
105- return "" , fmt .Errorf ("failed to create storage: %w" , err )
110+ objWriter := bucketHandle .Object (bootstrapIgnitionBucketObjName ).NewWriter (ctx )
111+ if _ , err := fmt .Fprint (objWriter , contents ); err != nil {
112+ return fmt .Errorf ("failed to store content in bucket object: %w" , err )
106113 }
107114
108- url , err := CreateSignedURL (bucketHandle , bootstrapIgnitionBucketObjName )
109- if err != nil {
110- return "" , fmt .Errorf ("failed to sign url: %w" , err )
115+ if err := objWriter .Close (); err != nil {
116+ return fmt .Errorf ("failed to close bucket object writer: %w" , err )
111117 }
112118
113- return url , nil
119+ return nil
114120}
115121
116- // FillBucket will add the contents to the bootstrap storage bucket object .
117- func FillBucket (ctx context.Context , bucketHandle * storage. BucketHandle , contents string ) error {
122+ // DestroyStorage Destroy the bucket and the bucket objects that are associated with the bucket .
123+ func DestroyStorage (ctx context.Context , clusterID string ) error {
118124 ctx , cancel := context .WithTimeout (ctx , time .Minute * 1 )
119125 defer cancel ()
120126
121- objWriter := bucketHandle . Object ( bootstrapIgnitionBucketObjName ). NewWriter (ctx )
122- if _ , err := fmt . Fprint ( objWriter , contents ); err != nil {
123- return fmt .Errorf ("failed to store content in bucket object : %w" , err )
127+ client , err := NewStorageClient (ctx )
128+ if err != nil {
129+ return fmt .Errorf ("failed to create storage client : %w" , err )
124130 }
131+ bucketName := GetBootstrapStorageName (clusterID )
125132
126- if err := objWriter .Close (); err != nil {
127- return fmt .Errorf ("failed to close bucket object writer: %w" , err )
133+ // Deleting a bucket will delete the managed folders and bucket objects.
134+ if err := client .Bucket (bucketName ).Delete (ctx ); err != nil {
135+ return fmt .Errorf ("failed to delete bucket %s: %w" , bucketName , err )
128136 }
129-
130137 return nil
131138}
0 commit comments