2022-08-10 16:55:20 +00:00
|
|
|
package role
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
service "github.com/mudler/edgevpn/api/client/service"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Role func(*service.RoleConfig) error
|
|
|
|
|
|
|
|
func SentinelExist() bool {
|
2022-09-16 15:42:45 +00:00
|
|
|
if _, err := os.Stat("/usr/local/.kairos/deployed"); err == nil {
|
2022-08-10 16:55:20 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreateSentinel() error {
|
2022-09-16 15:42:45 +00:00
|
|
|
return ioutil.WriteFile("/usr/local/.kairos/deployed", []byte{}, os.ModePerm)
|
2022-08-10 16:55:20 +00:00
|
|
|
}
|
2022-12-01 16:44:19 +00:00
|
|
|
|
|
|
|
func getRoles(client *service.Client, nodes []string) ([]string, map[string]string, bool) {
|
|
|
|
unassignedNodes := []string{}
|
|
|
|
currentRoles := map[string]string{}
|
|
|
|
existsMaster := false
|
|
|
|
for _, a := range nodes {
|
|
|
|
role, _ := client.Get("role", a)
|
|
|
|
currentRoles[a] = role
|
|
|
|
if role == "master" {
|
|
|
|
existsMaster = true
|
|
|
|
} else if role == "" {
|
|
|
|
unassignedNodes = append(unassignedNodes, a)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return unassignedNodes, currentRoles, existsMaster
|
|
|
|
}
|