Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: kairos-io/kairos-sdk
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.0.13
Choose a base ref
...
head repository: kairos-io/kairos-sdk
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.0.14
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Sep 1, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9e420d9 View commit details
Showing with 29 additions and 0 deletions.
  1. +22 −0 state/state.go
  2. +7 −0 types/fs.go
22 changes: 22 additions & 0 deletions state/state.go
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ import (
"github.com/itchyny/gojq"
"github.com/jaypipes/ghw"
"github.com/jaypipes/ghw/pkg/block"
"github.com/kairos-io/kairos-sdk/types"
"github.com/kairos-io/kairos-sdk/utils"
"github.com/zcalusic/sysinfo"
"gopkg.in/yaml.v3"
@@ -132,6 +133,27 @@ func detectBoot() Boot {
}
}

// DetectBootWithVFS will detect the boot state using a vfs so it can be used for tests as well
func DetectBootWithVFS(fs types.KairosFS) (Boot, error) {
cmdline, err := fs.ReadFile("/proc/cmdline")
if err != nil {
return Unknown, err
}
cmdlineS := string(cmdline)
switch {
case strings.Contains(cmdlineS, "COS_ACTIVE"):
return Active, nil
case strings.Contains(cmdlineS, "COS_PASSIVE"):
return Passive, nil
case strings.Contains(cmdlineS, "COS_RECOVERY"), strings.Contains(cmdlineS, "COS_SYSTEM"):
return Recovery, nil
case strings.Contains(cmdlineS, "live:LABEL"), strings.Contains(cmdlineS, "live:CDLABEL"), strings.Contains(cmdlineS, "netboot"):
return LiveCD, nil
default:
return Unknown, nil
}
}

func detectRuntimeState(r *Runtime) error {
blockDevices, err := block.New(ghw.WithDisableTools(), ghw.WithDisableWarnings())
// ghw currently only detects if partitions are mounted via the device
7 changes: 7 additions & 0 deletions types/fs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package types

// KairosFS is our interface for methods that need an FS
// We should try to keep it to a minimum so we can change between backends easily if needed
type KairosFS interface {
ReadFile(filename string) ([]byte, error)
}