Full rework (#41)

* Full rework

 - Extract steps to a different file
 - Simplify dag for easy understanding
 - Load dag based on our boot process
 - Simplify steps to not depend on useless stuff
 - Better logging

Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com>

* Move sentinel file to the dag

Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com>

* Adapt tests

Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com>

---------

Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com>
This commit is contained in:
Itxaka
2023-02-15 22:30:08 +01:00
committed by GitHub
parent 4e2dd37e70
commit ad014e9f22
16 changed files with 793 additions and 728 deletions

View File

@@ -4,20 +4,9 @@ import (
"github.com/joho/godotenv"
"github.com/kairos-io/kairos/sdk/state"
"os"
"path/filepath"
"strings"
)
// BootedFromLiveMedia tells us if we are currently running off LIVE media like cd/usb or netboot
func BootedFromLiveMedia() (bool, error) {
runtime, err := state.NewRuntime()
if err != nil {
return false, err
}
return runtime.BootState == state.LiveCD, nil
}
// BootStateToLabel lets us know the label we need to mount sysroot on
func BootStateToLabel() string {
runtime, err := state.NewRuntime()
@@ -119,36 +108,3 @@ func CleanupSlice(slice []string) []string {
}
return cleanSlice
}
// SetSentinelFile sets the sentinel file to identify the boot mode.
// This is used by several things to know in which state they are, for example cloud configs
func SetSentinelFile() error {
var sentinel string
err := CreateIfNotExists("/run/cos/")
if err != nil {
return err
}
runtime, err := state.NewRuntime()
if err != nil {
return err
}
switch runtime.BootState {
case state.Active:
sentinel = "active_mode"
case state.Passive:
sentinel = "passive_mode"
case state.Recovery:
sentinel = "recovery_mode"
case state.LiveCD:
sentinel = "live_mode"
default:
sentinel = string(state.Unknown)
}
err = os.WriteFile(filepath.Join("/run/cos/", sentinel), []byte("1"), os.ModePerm)
if err != nil {
return err
}
return nil
}