mirror of
https://github.com/kairos-io/kairos-sdk.git
synced 2025-04-27 11:11:29 +00:00
Add K0s utility functions and cleanup (#546)
* adding utils components to handle k0s
Signed-off-by: William Rizzo <william.rizzo@gmail.com>
* Adding systemd units for k0s
Signed-off-by: William Rizzo <william.rizzo@gmail.com>
* fix k0s services
Signed-off-by: William Rizzo <william.rizzo@gmail.com>
* Remove shutdown now, it will be addressed later
see kairos-io/kairos#3126
Signed-off-by: Mauro Morales <contact@mauromorales.com>
* Revert FindCommand changes
This function is not specific for k3s hence also not for k0s
Signed-off-by: Mauro Morales <contact@mauromorales.com>
* Remove utils.Version()
For versioning we now use the versioneer package also in this repo. I
couldn't find any instance of components depending on utils.Version() so
I think it's safe to remove
Signed-off-by: Mauro Morales <contact@mauromorales.com>
* Revert changes to the go.mod & go.sum files
Signed-off-by: Mauro Morales <contact@mauromorales.com>
* Revert "Remove utils.Version()"
This reverts commit c5f48d96d3
.
* Remove utils.Version()
This is not being used anymore, use Versioneer package instead
Signed-off-by: Mauro Morales <contact@mauromorales.com>
* Update machine/machine.go
Co-authored-by: Dimitris Karakasilis <dimitris@karakasilis.me>
---------
Signed-off-by: William Rizzo <william.rizzo@gmail.com>
Signed-off-by: Mauro Morales <contact@mauromorales.com>
Co-authored-by: Mauro Morales <contact@mauromorales.com>
Co-authored-by: Dimitris Karakasilis <dimitris@karakasilis.me>
This commit is contained in:
parent
a2d305dd6d
commit
716d3f4fca
@ -107,6 +107,37 @@ func K3sEnvUnit(unit string) string {
|
||||
return fmt.Sprintf("/etc/sysconfig/%s", unit)
|
||||
}
|
||||
|
||||
func K0s() (Service, error) {
|
||||
if utils.IsOpenRCBased() {
|
||||
return openrc.NewService(
|
||||
openrc.WithName("k0scontroller"),
|
||||
)
|
||||
}
|
||||
|
||||
return systemd.NewService(
|
||||
systemd.WithName("k0scontroller"),
|
||||
)
|
||||
}
|
||||
|
||||
func K0sWorker() (Service, error) {
|
||||
if utils.IsOpenRCBased() {
|
||||
return openrc.NewService(
|
||||
openrc.WithName("k0sworker"),
|
||||
)
|
||||
}
|
||||
|
||||
return systemd.NewService(
|
||||
systemd.WithName("k0sworker"),
|
||||
)
|
||||
}
|
||||
|
||||
func K0sEnvUnit(unit string) string {
|
||||
if utils.IsOpenRCBased() {
|
||||
return fmt.Sprintf("/etc/k0s/%s.env", unit)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("/etc/sysconfig/%s", unit)
|
||||
}
|
||||
func UUID() string {
|
||||
if os.Getenv("UUID") != "" {
|
||||
return os.Getenv("UUID")
|
||||
|
@ -135,8 +135,21 @@ func K3sBin() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func K0sBin() string {
|
||||
for _, p := range []string{"/usr/bin/k0s", "/usr/local/bin/k0s"} {
|
||||
if _, err := os.Stat(p); err == nil {
|
||||
return p
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func WriteEnv(envFile string, config map[string]string) error {
|
||||
content, _ := os.ReadFile(envFile)
|
||||
content, err := os.ReadFile(envFile)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
env, _ := godotenv.Unmarshal(string(content))
|
||||
|
||||
for key, val := range config {
|
||||
@ -157,18 +170,14 @@ func Flavor() string {
|
||||
|
||||
// GetInit Return the init system used by the OS
|
||||
func GetInit() string {
|
||||
for _, file := range []string{"/run/systemd/system", "/sbin/systemctl", "/usr/bin/systemctl", "/usr/sbin/systemctl", "/usr/bin/systemctl"} {
|
||||
_, err := os.Stat(file)
|
||||
// Found systemd
|
||||
if err == nil {
|
||||
for _, file := range []string{"/run/systemd/system", "/sbin/systemctl", "/usr/bin/systemctl", "/usr/sbin/systemctl"} {
|
||||
if _, err := os.Stat(file); err == nil {
|
||||
return systemd
|
||||
}
|
||||
}
|
||||
|
||||
for _, file := range []string{"/sbin/openrc", "/usr/sbin/openrc", "/bin/openrc", "/usr/bin/openrc"} {
|
||||
_, err := os.Stat(file)
|
||||
// Found openrc
|
||||
if err == nil {
|
||||
if _, err := os.Stat(file); err == nil {
|
||||
return openrc
|
||||
}
|
||||
}
|
||||
@ -262,16 +271,6 @@ func PowerOFF() {
|
||||
}
|
||||
}
|
||||
|
||||
func Version() string {
|
||||
v, err := OSRelease("VERSION")
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
v = strings.ReplaceAll(v, "+k3s1-Kairos", "-")
|
||||
v = strings.ReplaceAll(v, "+k3s-Kairos", "-")
|
||||
return strings.ReplaceAll(v, "Kairos", "")
|
||||
}
|
||||
|
||||
func ListToOutput(rels []string, output string) []string {
|
||||
switch strings.ToLower(output) {
|
||||
case "yaml":
|
||||
|
Loading…
Reference in New Issue
Block a user