mirror of
https://github.com/kairos-io/immucore.git
synced 2025-09-19 09:12:40 +00:00
Merge branch 'master' into changes_v4
This commit is contained in:
40
internal/utils/mounts.go
Normal file
40
internal/utils/mounts.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// https://github.com/kairos-io/packages/blob/7c3581a8ba6371e5ce10c3a98bae54fde6a505af/packages/system/dracut/immutable-rootfs/30cos-immutable-rootfs/cos-mount-layout.sh#L58
|
||||
|
||||
// input: LABEL=FOO:/mount
|
||||
// output: /dev/disk...:/mount
|
||||
func ParseMount(s string) string {
|
||||
switch {
|
||||
case strings.Contains(s, "UUID="):
|
||||
dat := strings.Split(s, "UUID=")
|
||||
return fmt.Sprintf("/dev/disk/by-uuid/%s", dat[1])
|
||||
case strings.Contains(s, "LABEL="):
|
||||
dat := strings.Split(s, "LABEL=")
|
||||
return fmt.Sprintf("/dev/disk/by-label/%s", dat[1])
|
||||
default:
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
func ReadCMDLineArg(arg string) []string {
|
||||
cmdLine, err := os.ReadFile("/proc/cmdline")
|
||||
if err != nil {
|
||||
return []string{}
|
||||
}
|
||||
res := []string{}
|
||||
fields := strings.Fields(string(cmdLine))
|
||||
for _, f := range fields {
|
||||
if strings.HasPrefix(f, arg) {
|
||||
dat := strings.Split(f, arg)
|
||||
res = append(res, dat[1])
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
@@ -11,7 +11,6 @@ import (
|
||||
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/deniswernert/go-fstab"
|
||||
"github.com/kairos-io/immucore/pkg/profile"
|
||||
"github.com/kairos-io/kairos/pkg/utils"
|
||||
"github.com/moby/sys/mountinfo"
|
||||
)
|
||||
@@ -37,8 +36,7 @@ func appendSlash(path string) string {
|
||||
}
|
||||
|
||||
// https://github.com/kairos-io/packages/blob/94aa3bef3d1330cb6c6905ae164f5004b6a58b8c/packages/system/dracut/immutable-rootfs/30cos-immutable-rootfs/cos-mount-layout.sh#L129
|
||||
func baseOverlay(overlay profile.Overlay) (mountOperation, error) {
|
||||
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}).With().Caller().Logger()
|
||||
func baseOverlay(overlay Overlay) (mountOperation, error) {
|
||||
if err := os.MkdirAll(overlay.Base, 0700); err != nil {
|
||||
return mountOperation{}, err
|
||||
}
|
||||
|
@@ -3,19 +3,19 @@ package mount
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/kairos-io/kairos/sdk/state"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/kairos-io/kairos/sdk/state"
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/deniswernert/go-fstab"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/kairos-io/immucore/pkg/profile"
|
||||
internalUtils "github.com/kairos-io/immucore/internal/utils"
|
||||
"github.com/kairos-io/kairos/pkg/utils"
|
||||
"github.com/sanity-io/litter"
|
||||
"github.com/spectrocloud-labs/herd"
|
||||
@@ -290,8 +290,29 @@ func (s *State) Register(g *herd.Graph) error {
|
||||
// TODO: PERSISTENT_STATE_TARGET /usr/local/.state
|
||||
s.BindMounts = strings.Split(env["PERSISTENT_STATE_PATHS"], " ")
|
||||
|
||||
// TODO: this needs to be parsed
|
||||
// s.CustomMounts = strings.Split(env["VOLUMES"], " ")
|
||||
s.StateDir = env["PERSISTENT_STATE_TARGET"]
|
||||
if s.StateDir == "" {
|
||||
s.StateDir = "/usr/local/.state"
|
||||
}
|
||||
|
||||
// s.CustomMounts is special:
|
||||
// It gets parsed by the cmdline (TODO)
|
||||
// and from the env var
|
||||
// https://github.com/kairos-io/packages/blob/7c3581a8ba6371e5ce10c3a98bae54fde6a505af/packages/system/dracut/immutable-rootfs/30cos-immutable-rootfs/cos-generator.sh#L71
|
||||
// https://github.com/kairos-io/packages/blob/7c3581a8ba6371e5ce10c3a98bae54fde6a505af/packages/system/dracut/immutable-rootfs/30cos-immutable-rootfs/cos-mount-layout.sh#L80
|
||||
|
||||
addLine := func(d string) {
|
||||
dat := strings.Split(d, ":")
|
||||
if len(dat) == 2 {
|
||||
disk := dat[0]
|
||||
path := dat[1]
|
||||
s.CustomMounts[disk] = path
|
||||
}
|
||||
}
|
||||
for _, v := range append(internalUtils.ReadCMDLineArg("rd.cos.mount="), strings.Split(env["VOLUMES"], " ")...) {
|
||||
addLine(internalUtils.ParseMount(v))
|
||||
}
|
||||
|
||||
return nil
|
||||
}))
|
||||
if err != nil {
|
||||
@@ -305,7 +326,7 @@ func (s *State) Register(g *herd.Graph) error {
|
||||
err = g.Add(opMountBaseOverlay,
|
||||
herd.WithCallback(
|
||||
func(ctx context.Context) error {
|
||||
op, err := baseOverlay(profile.Overlay{
|
||||
op, err := baseOverlay(Overlay{
|
||||
Base: "/run/overlay",
|
||||
BackingBase: "tmpfs:20%",
|
||||
})
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package profile
|
||||
package mount
|
||||
|
||||
type Layout struct {
|
||||
Overlay Overlay
|
@@ -1,32 +0,0 @@
|
||||
package prepare
|
||||
|
||||
/*
|
||||
func hasMountpoint(path string, mounts []string) bool {
|
||||
for _, mount := range mounts {
|
||||
if strings.HasSuffix(mount, path) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func getStateMountpoints(statePaths []string, mountpoints []string) string {
|
||||
var stateMounts string
|
||||
for _, path := range statePaths {
|
||||
if !hasMountpoint(path, mountpoints) {
|
||||
stateMounts += path + " "
|
||||
}
|
||||
}
|
||||
return stateMounts
|
||||
}
|
||||
func getOverlayMountpoints(rwPaths []string, mounts []string) string {
|
||||
var mountpoints string
|
||||
|
||||
for _, path := range rwPaths {
|
||||
if !hasMountpoint(path, mounts) {
|
||||
mountpoints += path + ":overlay "
|
||||
}
|
||||
}
|
||||
return mountpoints
|
||||
}
|
||||
*/
|
@@ -1,7 +0,0 @@
|
||||
package profile
|
||||
|
||||
func Apply() {
|
||||
// Load all profiles
|
||||
// Apply mounts
|
||||
// Apply configurations to sysroot (/) or (/sysroot)
|
||||
}
|
@@ -1,4 +0,0 @@
|
||||
package profile
|
||||
|
||||
// profile.Mount mounts a profile to the system.
|
||||
func Mount() {}
|
Reference in New Issue
Block a user