mirror of
https://github.com/kairos-io/kairos-sdk.git
synced 2025-04-28 03:20:52 +00:00
Adapt machine to new sdk paths and format
Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com>
This commit is contained in:
parent
750eed7f93
commit
b3256fa436
@ -3,7 +3,7 @@ package machine_test
|
||||
import (
|
||||
"os"
|
||||
|
||||
. "github.com/kairos-io/kairos/pkg/machine"
|
||||
. "github.com/kairos-io/kairos-sdk/machine"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
@ -7,10 +7,10 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/denisbrodbeck/machineid"
|
||||
"github.com/kairos-io/kairos/pkg/machine/openrc"
|
||||
"github.com/kairos-io/kairos/pkg/machine/systemd"
|
||||
"github.com/kairos-io/kairos-sdk/machine/openrc"
|
||||
"github.com/kairos-io/kairos-sdk/machine/systemd"
|
||||
|
||||
"github.com/kairos-io/kairos/pkg/utils"
|
||||
"github.com/kairos-io/kairos-sdk/utils"
|
||||
)
|
||||
|
||||
type Service interface {
|
@ -6,7 +6,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/kairos-io/kairos/pkg/utils"
|
||||
"github.com/kairos-io/kairos-sdk/utils"
|
||||
)
|
||||
|
||||
type ServiceUnit struct {
|
@ -5,7 +5,7 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/kairos-io/kairos/pkg/utils"
|
||||
"github.com/kairos-io/kairos-sdk/utils"
|
||||
)
|
||||
|
||||
func Umount(path string) error {
|
||||
@ -33,7 +33,7 @@ func Mount(label, mountpoint string) error {
|
||||
|
||||
part = strings.TrimSuffix(part, "\n")
|
||||
|
||||
if !Exists(mountpoint) {
|
||||
if !utils.Exists(mountpoint) {
|
||||
err := os.MkdirAll(mountpoint, 0755)
|
||||
if err != nil {
|
||||
return err
|
@ -6,7 +6,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/kairos-io/kairos/pkg/utils"
|
||||
"github.com/kairos-io/kairos-sdk/utils"
|
||||
)
|
||||
|
||||
type ServiceUnit struct {
|
@ -1,9 +0,0 @@
|
||||
package machine
|
||||
|
||||
import "os"
|
||||
|
||||
func Exists(path string) bool {
|
||||
_, err := os.Stat(path)
|
||||
|
||||
return !os.IsNotExist(err)
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/denisbrodbeck/machineid"
|
||||
"github.com/joho/godotenv"
|
||||
@ -63,3 +65,44 @@ func FindCommand(def string, options []string) string {
|
||||
// Otherwise return default
|
||||
return def
|
||||
}
|
||||
|
||||
func K3sBin() string {
|
||||
for _, p := range []string{"/usr/bin/k3s", "/usr/local/bin/k3s"} {
|
||||
if _, err := os.Stat(p); err == nil {
|
||||
return p
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func WriteEnv(envFile string, config map[string]string) error {
|
||||
content, _ := os.ReadFile(envFile)
|
||||
env, _ := godotenv.Unmarshal(string(content))
|
||||
|
||||
for key, val := range config {
|
||||
env[key] = val
|
||||
}
|
||||
|
||||
return godotenv.Write(env, envFile)
|
||||
}
|
||||
|
||||
func Flavor() string {
|
||||
release, _ := godotenv.Read("/etc/os-release")
|
||||
v := release["NAME"]
|
||||
return strings.ReplaceAll(v, "kairos-", "")
|
||||
}
|
||||
|
||||
func IsOpenRCBased() bool {
|
||||
f := Flavor()
|
||||
return strings.Contains(f, "alpine")
|
||||
}
|
||||
|
||||
func ShellSTDIN(s, c string) (string, error) {
|
||||
cmd := exec.Command("/bin/sh", "-c", c)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdin = bytes.NewBuffer([]byte(s))
|
||||
o, err := cmd.CombinedOutput()
|
||||
return string(o), err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user