File tree Expand file tree Collapse file tree 2 files changed +41
-9
lines changed Expand file tree Collapse file tree 2 files changed +41
-9
lines changed Original file line number Diff line number Diff line change @@ -355,7 +355,7 @@ func ensureOCIHooks(spec *oci.Spec) {
355355func sortMounts (specgen * ocigen.Generator ) {
356356 mounts := specgen .Mounts ()
357357 specgen .ClearMounts ()
358- sort .Sort (orderedMounts (mounts ))
358+ sort .Stable (orderedMounts (mounts ))
359359 specgen .Config .Mounts = mounts
360360}
361361
@@ -375,14 +375,7 @@ func (m orderedMounts) Len() int {
375375// mount indexed by parameter 1 is less than that of the mount indexed by
376376// parameter 2. Used in sorting.
377377func (m orderedMounts ) Less (i , j int ) bool {
378- ip , jp := m .parts (i ), m .parts (j )
379- if ip < jp {
380- return true
381- }
382- if jp < ip {
383- return false
384- }
385- return m [i ].Destination < m [j ].Destination
378+ return m .parts (i ) < m .parts (j )
386379}
387380
388381// Swap swaps two items in an array of mounts. Used in sorting
Original file line number Diff line number Diff line change @@ -599,6 +599,45 @@ func TestApplyContainerEdits(t *testing.T) {
599599 },
600600 result : & oci.Spec {},
601601 },
602+ {
603+ name : "apply mount edits do not change the order of original mounts" ,
604+ spec : & oci.Spec {
605+ Mounts : []oci.Mount {
606+ {
607+ Source : "/some/host/path1" ,
608+ Destination : "/dest/path/b" ,
609+ },
610+ {
611+ Source : "/some/host/path2" ,
612+ Destination : "/dest/path/a" ,
613+ },
614+ },
615+ },
616+ edits : & cdi.ContainerEdits {
617+ Mounts : []* cdi.Mount {
618+ {
619+ HostPath : "/some/host/path3" ,
620+ ContainerPath : "/dest/edit" ,
621+ },
622+ },
623+ },
624+ result : & oci.Spec {
625+ Mounts : []oci.Mount {
626+ {
627+ Source : "/some/host/path3" ,
628+ Destination : "/dest/edit" ,
629+ },
630+ {
631+ Source : "/some/host/path1" ,
632+ Destination : "/dest/path/b" ,
633+ },
634+ {
635+ Source : "/some/host/path2" ,
636+ Destination : "/dest/path/a" ,
637+ },
638+ },
639+ },
640+ },
602641 } {
603642 t .Run (tc .name , func (t * testing.T ) {
604643 edits := ContainerEdits {tc .edits }
You can’t perform that action at this time.
0 commit comments