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")