From db7f34ae5adf123fbbe55d0be3e1e708dd886997 Mon Sep 17 00:00:00 2001 From: Ashley Dumaine Date: Mon, 26 Feb 2024 14:54:29 -0500 Subject: [PATCH] need to wait for volume to detach to not spam deletion failures --- cloud/services/volumes.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/cloud/services/volumes.go b/cloud/services/volumes.go index e8a120d69..b0654f740 100644 --- a/cloud/services/volumes.go +++ b/cloud/services/volumes.go @@ -13,7 +13,10 @@ import ( "github.com/linode/cluster-api-provider-linode/util" ) -const defaultEtcdSizeGB = 10 +const ( + defaultEtcdSizeGB = 10 + defaultVolumeDetachTimeoutSeconds = 10 +) // CreateEtcdVolume creates an etcd Volume for a given linode instance ID func CreateEtcdVolume(ctx context.Context, @@ -58,6 +61,21 @@ func DeleteEtcdVolume(ctx context.Context, return err } } + + // need to wait for volume to actually detach before we can proceed with + // deleting it + if _, err := machineScope.LinodeClient.WaitForVolumeLinodeID( + ctx, + volumeID, + nil, + defaultVolumeDetachTimeoutSeconds, + ); err != nil { + logger.Error(err, "Timed out waiting for volume to detach") + + return err + } + + // now that the volume is detached it can be properly deleted if err := machineScope.LinodeClient.DeleteVolume(ctx, volumeID); err != nil { if util.IgnoreLinodeAPIError(err, http.StatusNotFound) != nil { logger.Error(err, "Failed to delete volume")