From d08cd5e484a044a687b760f118d72a192e306e63 Mon Sep 17 00:00:00 2001 From: Julien Castets Date: Tue, 25 Jun 2024 21:25:01 +0200 Subject: [PATCH] Fix volume removal in service update --- pkg/koyeb/flags_list/volumes.go | 47 +++++++++++++++++---------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/pkg/koyeb/flags_list/volumes.go b/pkg/koyeb/flags_list/volumes.go index 7321d6dc..e0adf46e 100644 --- a/pkg/koyeb/flags_list/volumes.go +++ b/pkg/koyeb/flags_list/volumes.go @@ -24,19 +24,6 @@ func GetNewVolumeListFromFlags(resolveVolumeId func(string) (string, error)) fun hc := &FlagVolume{BaseFlag: BaseFlag{cliValue: value}} components := strings.Split(value, ":") - if len(components) != 2 { - return nil, &errors.CLIError{ - What: "Error while configuring the service", - Why: fmt.Sprintf("unable to parse the volume \"%s\"", hc.cliValue), - Additional: []string{ - "Volumes must be specified as VOLUME_ID:PATH", - "To remove a volume from the service, prefix it with '!', e.g. '!myvolume'", - }, - Orig: nil, - Solution: "Fix the volume and try again", - } - } - if strings.HasPrefix(components[0], "!") { if len(components) > 1 { return nil, &errors.CLIError{ @@ -50,18 +37,32 @@ func GetNewVolumeListFromFlags(resolveVolumeId func(string) (string, error)) fun Solution: "Fix the volume and try again", } } + volumeId, err := resolveVolumeId(components[0][1:]) + if err != nil { + return nil, err + } hc.markedForDeletion = true - components[0] = components[0][1:] - } - - volumeId, err := resolveVolumeId(components[0]) - if err != nil { - return nil, err + hc.volumeId = volumeId + } else { + if len(components) > 2 { + return nil, &errors.CLIError{ + What: "Error while configuring the service", + Why: fmt.Sprintf("unable to parse the volume \"%s\"", hc.cliValue), + Additional: []string{ + "Volumes must be specified as VOLUME_ID:PATH", + "To remove a volume from the service, prefix it with '!', e.g. '!myvolume'", + }, + Orig: nil, + Solution: "Fix the volume and try again", + } + } + volumeId, err := resolveVolumeId(components[0]) + if err != nil { + return nil, err + } + hc.volumeId = volumeId + hc.path = components[1] } - - hc.volumeId = volumeId - hc.path = components[1] - ret = append(ret, hc) } return ret, nil