@@ -77,7 +77,13 @@ func CreateStorage(ctx context.Context, ic *installconfig.InstallConfig, bucketH
7777}
7878
7979// CreateSignedURL creates a signed url and correlates the signed url with a storage bucket.
80- func CreateSignedURL (handle * storage.BucketHandle , objectName string ) (string , error ) {
80+ func CreateSignedURL (clusterID string ) (string , error ) {
81+ bucketName := GetBootstrapStorageName (clusterID )
82+ handle , err := CreateBucketHandle (context .Background (), bucketName )
83+ if err != nil {
84+ return "" , fmt .Errorf ("creating presigned url, failed to create bucket handle: %w" , err )
85+ }
86+
8187 // Signing a URL requires credentials authorized to sign a URL. You can pass
8288 // these in through SignedURLOptions with a Google Access ID with
8389 // iam.serviceAccounts.signBlob permissions.
@@ -89,44 +95,45 @@ func CreateSignedURL(handle *storage.BucketHandle, objectName string) (string, e
8995
9096 // The object has not been created yet. This is ok, it is expected to be created after this call.
9197 // However, if the object is never created this could cause major issues.
92- url , err := handle .SignedURL (objectName , & opts )
98+ url , err := handle .SignedURL (bootstrapIgnitionBucketObjName , & opts )
9399 if err != nil {
94100 return "" , fmt .Errorf ("failed to create a signed url: %w" , err )
95101 }
96102
97103 return url , nil
98104}
99105
100- // ProvisionBootstrapStorage will provision the required storage bucket and signed url for the bootstrap process .
101- func ProvisionBootstrapStorage (ctx context.Context , ic * installconfig. InstallConfig , bucketHandle * storage.BucketHandle , clusterID string ) ( string , error ) {
106+ // FillBucket will add the contents to the bootstrap storage bucket object .
107+ func FillBucket (ctx context.Context , bucketHandle * storage.BucketHandle , contents string ) error {
102108 ctx , cancel := context .WithTimeout (ctx , time .Minute * 1 )
103109 defer cancel ()
104110
105- if err := CreateStorage (ctx , ic , bucketHandle , clusterID ); err != nil {
106- return "" , fmt .Errorf ("failed to create storage: %w" , err )
111+ objWriter := bucketHandle .Object (bootstrapIgnitionBucketObjName ).NewWriter (ctx )
112+ if _ , err := fmt .Fprint (objWriter , contents ); err != nil {
113+ return fmt .Errorf ("failed to store content in bucket object: %w" , err )
107114 }
108115
109- url , err := CreateSignedURL (bucketHandle , bootstrapIgnitionBucketObjName )
110- if err != nil {
111- return "" , fmt .Errorf ("failed to sign url: %w" , err )
116+ if err := objWriter .Close (); err != nil {
117+ return fmt .Errorf ("failed to close bucket object writer: %w" , err )
112118 }
113119
114- return url , nil
120+ return nil
115121}
116122
117- // FillBucket will add the contents to the bootstrap storage bucket object .
118- func FillBucket (ctx context.Context , bucketHandle * storage. BucketHandle , contents string ) error {
123+ // DestroyStorage Destroy the bucket and the bucket objects that are associated with the bucket .
124+ func DestroyStorage (ctx context.Context , clusterID string ) error {
119125 ctx , cancel := context .WithTimeout (ctx , time .Minute * 1 )
120126 defer cancel ()
121127
122- objWriter := bucketHandle . Object ( bootstrapIgnitionBucketObjName ). NewWriter (ctx )
123- if _ , err := fmt . Fprint ( objWriter , contents ); err != nil {
124- return fmt .Errorf ("failed to store content in bucket object : %w" , err )
128+ client , err := NewStorageClient (ctx )
129+ if err != nil {
130+ return fmt .Errorf ("failed to create storage client : %w" , err )
125131 }
132+ bucketName := GetBootstrapStorageName (clusterID )
126133
127- if err := objWriter .Close (); err != nil {
128- return fmt .Errorf ("failed to close bucket object writer: %w" , err )
134+ // Deleting a bucket will delete the managed folders and bucket objects.
135+ if err := client .Bucket (bucketName ).Delete (ctx ); err != nil {
136+ return fmt .Errorf ("failed to delete bucket %s: %w" , bucketName , err )
129137 }
130-
131138 return nil
132139}
0 commit comments