Skip to content

Commit

Permalink
Ignore destroyed volumes
Browse files Browse the repository at this point in the history
Now that we use the Machines API to work on volumes, the volume states
that we receive correspond directly to the volume states in `flyd`.
Several of these states are for volumes that have been effectively
"destroyed" but aren't truly destroyed yet. Filter out volumes in these
states so that we don't try to use them.

`GetAllVolumes` provides an unfiltered version.
  • Loading branch information
matttpt committed Aug 14, 2023
1 parent 3bdd9d0 commit 4253162
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion flaps/flaps_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ import (
"fmt"
"net/http"

"github.com/samber/lo"
"github.com/superfly/flyctl/api"
"golang.org/x/exp/slices"
)

var destroyedVolumeStates = []string{"scheduling_destroy", "fork_cleanup", "waiting_for_detach", "pending_destroy", "destroying"}

func (f *Client) sendRequestVolumes(ctx context.Context, method, endpoint string, in, out interface{}, headers map[string][]string) error {
endpoint = fmt.Sprintf("/apps/%s/volumes%s", f.appName, endpoint)
return f._sendRequest(ctx, method, endpoint, in, out, headers)
}

func (f *Client) GetVolumes(ctx context.Context) ([]api.Volume, error) {
func (f *Client) GetAllVolumes(ctx context.Context) ([]api.Volume, error) {
listVolumesEndpoint := ""

out := make([]api.Volume, 0)
Expand All @@ -25,6 +29,16 @@ func (f *Client) GetVolumes(ctx context.Context) ([]api.Volume, error) {
return out, nil
}

func (f *Client) GetVolumes(ctx context.Context) ([]api.Volume, error) {
volumes, err := f.GetAllVolumes(ctx)
if err != nil {
return nil, err
}
return lo.Filter(volumes, func(v api.Volume, _ int) bool {
return !slices.Contains(destroyedVolumeStates, v.State)
}), nil
}

func (f *Client) CreateVolume(ctx context.Context, req api.CreateVolumeRequest) (*api.Volume, error) {
createVolumeEndpoint := ""

Expand Down

0 comments on commit 4253162

Please sign in to comment.