mirror of https://github.com/docker/compose.git
Merge pull request #603 from docker/aci_volume_ids
Change volume IDs from “storageaccount@fileshare“ to “storageaccount/fileshare”
This commit is contained in:
commit
3db0db04cb
|
@ -207,7 +207,7 @@ func (p projectAciHelper) getAciFileVolumes(ctx context.Context, helper login.St
|
||||||
if v.Driver == azureFileDriverName {
|
if v.Driver == azureFileDriverName {
|
||||||
shareName, ok := v.DriverOpts[volumeDriveroptsShareNameKey]
|
shareName, ok := v.DriverOpts[volumeDriveroptsShareNameKey]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, nil, fmt.Errorf("cannot retrieve share name for Azurefile")
|
return nil, nil, fmt.Errorf("cannot retrieve fileshare name for Azurefile")
|
||||||
}
|
}
|
||||||
accountName, ok := v.DriverOpts[volumeDriveroptsAccountNameKey]
|
accountName, ok := v.DriverOpts[volumeDriveroptsAccountNameKey]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
|
@ -42,8 +42,8 @@ func GetRunVolumes(volumes []string) (map[string]types.VolumeConfig, []types.Ser
|
||||||
Name: vi.name,
|
Name: vi.name,
|
||||||
Driver: azureFileDriverName,
|
Driver: azureFileDriverName,
|
||||||
DriverOpts: map[string]string{
|
DriverOpts: map[string]string{
|
||||||
volumeDriveroptsAccountNameKey: vi.username,
|
volumeDriveroptsAccountNameKey: vi.storageAccount,
|
||||||
volumeDriveroptsShareNameKey: vi.share,
|
volumeDriveroptsShareNameKey: vi.fileshare,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
sv := types.ServiceVolumeConfig{
|
sv := types.ServiceVolumeConfig{
|
||||||
|
@ -58,29 +58,30 @@ func GetRunVolumes(volumes []string) (map[string]types.VolumeConfig, []types.Ser
|
||||||
}
|
}
|
||||||
|
|
||||||
type volumeInput struct {
|
type volumeInput struct {
|
||||||
name string
|
name string
|
||||||
username string
|
storageAccount string
|
||||||
share string
|
fileshare string
|
||||||
target string
|
target string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *volumeInput) parse(name string, s string) error {
|
func (v *volumeInput) parse(name string, s string) error {
|
||||||
v.name = name
|
v.name = name
|
||||||
tokens := strings.Split(s, "@")
|
tokens := strings.Split(s, ":")
|
||||||
if len(tokens) < 2 || tokens[0] == "" {
|
source := tokens[0]
|
||||||
return errors.Wrapf(errdefs.ErrParsingFailed, "volume specification %q does not include a storage account before '@'", v)
|
sourceTokens := strings.Split(source, "/")
|
||||||
|
if len(sourceTokens) < 2 || sourceTokens[0] == "" {
|
||||||
|
return errors.Wrapf(errdefs.ErrParsingFailed, "volume specification %q does not include a storage account before '/'", v)
|
||||||
}
|
}
|
||||||
v.username = tokens[0]
|
v.storageAccount = sourceTokens[0]
|
||||||
remaining := tokens[1]
|
if sourceTokens[1] == "" {
|
||||||
tokens = strings.Split(remaining, ":")
|
return errors.Wrapf(errdefs.ErrParsingFailed, "volume specification %q does not include a storage file fileshare after '/'", v)
|
||||||
if tokens[0] == "" {
|
|
||||||
return errors.Wrapf(errdefs.ErrParsingFailed, "volume specification %q does not include a storage file share after '@'", v)
|
|
||||||
}
|
}
|
||||||
v.share = tokens[0]
|
v.fileshare = sourceTokens[1]
|
||||||
|
|
||||||
if len(tokens) > 1 {
|
if len(tokens) > 1 {
|
||||||
v.target = tokens[1]
|
v.target = tokens[1]
|
||||||
} else {
|
} else {
|
||||||
v.target = "/run/volumes/" + v.share
|
v.target = "/run/volumes/" + v.fileshare
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,9 @@ const (
|
||||||
|
|
||||||
func TestGetRunVolumes(t *testing.T) {
|
func TestGetRunVolumes(t *testing.T) {
|
||||||
volumeStrings := []string{
|
volumeStrings := []string{
|
||||||
"myuser1@myshare1:/my/path/to/target1",
|
"myuser1/myshare1:/my/path/to/target1",
|
||||||
"myuser2@myshare2:/my/path/to/target2",
|
"myuser2/myshare2:/my/path/to/target2",
|
||||||
"myuser3@mydefaultsharename", // Use default placement at '/run/volumes/<share_name>'
|
"myuser3/mydefaultsharename", // Use default placement at '/run/volumes/<share_name>'
|
||||||
}
|
}
|
||||||
var goldenVolumeConfigs = map[string]types.VolumeConfig{
|
var goldenVolumeConfigs = map[string]types.VolumeConfig{
|
||||||
"volume-0": {
|
"volume-0": {
|
||||||
|
@ -89,16 +89,16 @@ func TestGetRunVolumes(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetRunVolumesMissingFileShare(t *testing.T) {
|
func TestGetRunVolumesMissingFileShare(t *testing.T) {
|
||||||
_, _, err := GetRunVolumes([]string{"myaccount@"})
|
_, _, err := GetRunVolumes([]string{"myaccount/"})
|
||||||
assert.ErrorContains(t, err, "does not include a storage file share after '@'")
|
assert.ErrorContains(t, err, "does not include a storage file fileshare after '/'")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetRunVolumesMissingUser(t *testing.T) {
|
func TestGetRunVolumesMissingUser(t *testing.T) {
|
||||||
_, _, err := GetRunVolumes([]string{"@myshare"})
|
_, _, err := GetRunVolumes([]string{"/myshare"})
|
||||||
assert.ErrorContains(t, err, "does not include a storage account before '@'")
|
assert.ErrorContains(t, err, "does not include a storage account before '/'")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetRunVolumesNoShare(t *testing.T) {
|
func TestGetRunVolumesNoShare(t *testing.T) {
|
||||||
_, _, err := GetRunVolumes([]string{"noshare"})
|
_, _, err := GetRunVolumes([]string{"noshare"})
|
||||||
assert.ErrorContains(t, err, "does not include a storage account before '@'")
|
assert.ErrorContains(t, err, "does not include a storage account before '/'")
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,7 +167,7 @@ func errorEvent(resource string) progress.Event {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *aciVolumeService) Delete(ctx context.Context, id string, options interface{}) error {
|
func (cs *aciVolumeService) Delete(ctx context.Context, id string, options interface{}) error {
|
||||||
tokens := strings.Split(id, "@")
|
tokens := strings.Split(id, "/")
|
||||||
if len(tokens) != 2 {
|
if len(tokens) != 2 {
|
||||||
return errors.New("wrong format for volume ID : should be storageaccount@fileshare")
|
return errors.New("wrong format for volume ID : should be storageaccount@fileshare")
|
||||||
}
|
}
|
||||||
|
@ -219,7 +219,7 @@ func toVolume(account storage.Account, fileShareName string) volumes.Volume {
|
||||||
|
|
||||||
// VolumeID generate volume ID from azure storage accoun & fileshare
|
// VolumeID generate volume ID from azure storage accoun & fileshare
|
||||||
func VolumeID(storageAccount string, fileShareName string) string {
|
func VolumeID(storageAccount string, fileShareName string) string {
|
||||||
return fmt.Sprintf("%s@%s", storageAccount, fileShareName)
|
return fmt.Sprintf("%s/%s", storageAccount, fileShareName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultStorageAccountParams(aciContext store.AciContext) storage.AccountCreateParameters {
|
func defaultStorageAccountParams(aciContext store.AciContext) storage.AccountCreateParameters {
|
||||||
|
|
|
@ -28,7 +28,7 @@ import (
|
||||||
func TestPrintList(t *testing.T) {
|
func TestPrintList(t *testing.T) {
|
||||||
secrets := []volumes.Volume{
|
secrets := []volumes.Volume{
|
||||||
{
|
{
|
||||||
ID: "volume@123",
|
ID: "volume/123",
|
||||||
Description: "volume 123",
|
Description: "volume 123",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
ID DESCRIPTION
|
ID DESCRIPTION
|
||||||
volume@123 volume 123
|
volume/123 volume 123
|
||||||
|
|
|
@ -162,7 +162,7 @@ func TestContainerRunVolume(t *testing.T) {
|
||||||
t.Run("create volumes", func(t *testing.T) {
|
t.Run("create volumes", func(t *testing.T) {
|
||||||
c.RunDockerCmd("volume", "create", "--storage-account", accountName, "--fileshare", fileshareName)
|
c.RunDockerCmd("volume", "create", "--storage-account", accountName, "--fileshare", fileshareName)
|
||||||
})
|
})
|
||||||
volumeID = accountName + "@" + fileshareName
|
volumeID = accountName + "/" + fileshareName
|
||||||
|
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
c.RunDockerCmd("volume", "rm", volumeID)
|
c.RunDockerCmd("volume", "rm", volumeID)
|
||||||
|
@ -174,7 +174,7 @@ func TestContainerRunVolume(t *testing.T) {
|
||||||
t.Run("create second fileshare", func(t *testing.T) {
|
t.Run("create second fileshare", func(t *testing.T) {
|
||||||
c.RunDockerCmd("volume", "create", "--storage-account", accountName, "--fileshare", "dockertestshare2")
|
c.RunDockerCmd("volume", "create", "--storage-account", accountName, "--fileshare", "dockertestshare2")
|
||||||
})
|
})
|
||||||
volumeID2 := accountName + "@dockertestshare2"
|
volumeID2 := accountName + "/dockertestshare2"
|
||||||
|
|
||||||
t.Run("list volumes", func(t *testing.T) {
|
t.Run("list volumes", func(t *testing.T) {
|
||||||
res := c.RunDockerCmd("volume", "ls")
|
res := c.RunDockerCmd("volume", "ls")
|
||||||
|
|
Loading…
Reference in New Issue