mirror of
https://github.com/kairos-io/immucore.git
synced 2025-09-17 15:40:27 +00:00
Sort bind mounts (#134)
* Sort bind mounts Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Add comment Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> --------- Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com>
This commit is contained in:
@@ -308,7 +308,7 @@ func (s *State) MountCustomBindsDagStep(g *herd.Graph) error {
|
|||||||
var err *multierror.Error
|
var err *multierror.Error
|
||||||
internalUtils.Log.Debug().Strs("mounts", s.BindMounts).Msg("Mounting binds")
|
internalUtils.Log.Debug().Strs("mounts", s.BindMounts).Msg("Mounting binds")
|
||||||
|
|
||||||
for _, p := range s.BindMounts {
|
for _, p := range s.SortedBindMounts() {
|
||||||
internalUtils.Log.Debug().Str("what", p).Msg("Bind mount start")
|
internalUtils.Log.Debug().Str("what", p).Msg("Bind mount start")
|
||||||
op := mountBind(p, s.Rootdir, s.StateDir)
|
op := mountBind(p, s.Rootdir, s.StateDir)
|
||||||
err2 := op.run()
|
err2 := op.run()
|
||||||
|
@@ -6,6 +6,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containerd/containerd/mount"
|
"github.com/containerd/containerd/mount"
|
||||||
@@ -31,6 +33,22 @@ type State struct {
|
|||||||
fstabs []*fstab.Mount
|
fstabs []*fstab.Mount
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SortedBindMounts returns the nodes with less depth first and in alphabetical order.
|
||||||
|
func (s *State) SortedBindMounts() []string {
|
||||||
|
bindMountsCopy := s.BindMounts
|
||||||
|
sort.Slice(bindMountsCopy, func(i, j int) bool {
|
||||||
|
iAry := strings.Split(bindMountsCopy[i], "/")
|
||||||
|
jAry := strings.Split(bindMountsCopy[j], "/")
|
||||||
|
iSize := len(iAry)
|
||||||
|
jSize := len(jAry)
|
||||||
|
if iSize == jSize {
|
||||||
|
return strings.Compare(iAry[len(iAry)-1], jAry[len(jAry)-1]) == -1
|
||||||
|
}
|
||||||
|
return iSize < jSize
|
||||||
|
})
|
||||||
|
return bindMountsCopy
|
||||||
|
}
|
||||||
|
|
||||||
func (s *State) path(p ...string) string {
|
func (s *State) path(p ...string) string {
|
||||||
return filepath.Join(append([]string{s.Rootdir}, p...)...)
|
return filepath.Join(append([]string{s.Rootdir}, p...)...)
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,27 @@ var _ = Describe("mounting immutable setup", func() {
|
|||||||
Expect(g).ToNot(BeNil())
|
Expect(g).ToNot(BeNil())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Context("SortedBindMounts()", func() {
|
||||||
|
It("returns the nodes with less depth first and in alfabetical order", func() {
|
||||||
|
s := &mount.State{
|
||||||
|
BindMounts: []string{
|
||||||
|
"/etc/nginx/config.d/",
|
||||||
|
"/etc/nginx",
|
||||||
|
"/etc/kubernetes/child",
|
||||||
|
"/etc/kubernetes",
|
||||||
|
"/etc/kubernetes/child/grand-child",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
Expect(s.SortedBindMounts()).To(Equal([]string{
|
||||||
|
"/etc/kubernetes",
|
||||||
|
"/etc/nginx",
|
||||||
|
"/etc/kubernetes/child",
|
||||||
|
"/etc/nginx/config.d/",
|
||||||
|
"/etc/kubernetes/child/grand-child",
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
Context("simple invocation", func() {
|
Context("simple invocation", func() {
|
||||||
It("generates normal dag", func() {
|
It("generates normal dag", func() {
|
||||||
Skip("Cant override bootstate yet")
|
Skip("Cant override bootstate yet")
|
||||||
|
Reference in New Issue
Block a user