GCP: clean up resources after canceled image import
Add method to fetch Cloudbuild job log. Add method to parse Cloudbuild job log for created resources. Parsing is specific to the Image import Cloudbuild job and its logs format. Add unit tests for the parsing function. Add method to clean up all resources (instances, disks, storage objects) after a Cloudbuild job. Modify the worker osbuild job implementation and also the GCP upload CLI tool to use the new cleanup method CloudbuildBuildCleanup(). Keep the StorageImageImportCleanup() method, because it is still used by the cloud-cleaner tool. There is no way for the cloud-cleaner to figure out the Cloudbuild job ID to be able to call CloudbuildBuildCleanup() instead. Add methods to delete Compute instance and disk. Add method to get Compute instance information. This is useful for checking if the instance has been already deleted, or whether it still exists. Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
parent
6d51d285cf
commit
e799f752be
5 changed files with 709 additions and 19 deletions
|
|
@ -80,6 +80,15 @@ func main() {
|
|||
if imageBuild != nil {
|
||||
log.Printf("[GCP] 📜 Image import log URL: %s", imageBuild.LogUrl)
|
||||
log.Printf("[GCP] 🎉 Image import finished with status: %s", imageBuild.Status)
|
||||
|
||||
// Cleanup all resources potentially left after the image import job
|
||||
deleted, err := g.CloudbuildBuildCleanup(ctx, imageBuild.Id)
|
||||
for _, d := range deleted {
|
||||
log.Printf("[GCP] 🧹 Deleted resource after image import job: %s", d)
|
||||
}
|
||||
if err != nil {
|
||||
log.Printf("[GCP] Encountered error during image import cleanup: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup storage before checking for errors
|
||||
|
|
@ -88,14 +97,6 @@ func main() {
|
|||
log.Printf("[GCP] Encountered error while deleting object: %v", err)
|
||||
}
|
||||
|
||||
deleted, errs := g.StorageImageImportCleanup(ctx, imageName)
|
||||
for _, d := range deleted {
|
||||
log.Printf("[GCP] 🧹 Deleted image import job file '%s'", d)
|
||||
}
|
||||
for _, e := range errs {
|
||||
log.Printf("[GCP] Encountered error during image import cleanup: %v", e)
|
||||
}
|
||||
|
||||
// check error from ComputeImageImport()
|
||||
if importErr != nil {
|
||||
log.Fatalf("[GCP] Importing image failed: %v", importErr)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue