diff --git a/cli/command/volume/create.go b/cli/command/volume/create.go index 6fbdb767ea..6f89933597 100644 --- a/cli/command/volume/create.go +++ b/cli/command/volume/create.go @@ -3,6 +3,7 @@ package volume import ( "context" "fmt" + "sort" "strings" "github.com/docker/cli/cli" @@ -153,6 +154,9 @@ func runCreate(dockerCli command.Cli, options createOptions) error { }, ) } + sort.SliceStable(volOpts.ClusterVolumeSpec.Secrets, func(i, j int) bool { + return volOpts.ClusterVolumeSpec.Secrets[i].Key < volOpts.ClusterVolumeSpec.Secrets[j].Key + }) // TODO(dperny): ignore if no topology specified topology := &volume.TopologyRequirement{} diff --git a/cli/command/volume/create_test.go b/cli/command/volume/create_test.go index 2dfb9e8467..f5c711bf88 100644 --- a/cli/command/volume/create_test.go +++ b/cli/command/volume/create_test.go @@ -3,6 +3,7 @@ package volume import ( "io" "reflect" + "sort" "strings" "testing" @@ -192,6 +193,9 @@ func TestVolumeCreateClusterOpts(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ volumeCreateFunc: func(body volume.CreateOptions) (volume.Volume, error) { + sort.SliceStable(body.ClusterVolumeSpec.Secrets, func(i, j int) bool { + return body.ClusterVolumeSpec.Secrets[i].Key < body.ClusterVolumeSpec.Secrets[j].Key + }) assert.DeepEqual(t, body, expectedBody) return volume.Volume{}, nil },