mirror of
https://github.com/kairos-io/provider-kairos.git
synced 2025-09-12 13:24:34 +00:00
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package role
|
|
|
|
import (
|
|
"os"
|
|
|
|
service "github.com/mudler/edgevpn/api/client/service"
|
|
)
|
|
|
|
const (
|
|
RoleWorker = "worker"
|
|
RoleControlPlane = "control-plane"
|
|
RoleControlPlaneHA = "control-plane/ha"
|
|
RoleControlPlaneClusterInit = "control-plane/clusterinit"
|
|
RoleControlPlaneSingle = "control-plane/single"
|
|
|
|
RoleAuto = "auto"
|
|
// these are kept for backwards compatibility with old configs
|
|
RoleMaster = "master"
|
|
RoleMasterHA = "master/ha"
|
|
RoleMasterInit = "master/clusterinit"
|
|
)
|
|
|
|
type Role func(*service.RoleConfig) error
|
|
|
|
func SentinelExist() bool {
|
|
if _, err := os.Stat("/usr/local/.kairos/deployed"); err == nil {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func CreateSentinel() error {
|
|
return os.WriteFile("/usr/local/.kairos/deployed", []byte{}, os.ModePerm)
|
|
}
|
|
|
|
func getRoles(client *service.Client, nodes []string) ([]string, map[string]string) {
|
|
unassignedNodes := []string{}
|
|
currentRoles := map[string]string{}
|
|
for _, a := range nodes {
|
|
role, _ := client.Get("role", a)
|
|
currentRoles[a] = role
|
|
if role == "" {
|
|
unassignedNodes = append(unassignedNodes, a)
|
|
}
|
|
}
|
|
return unassignedNodes, currentRoles
|
|
}
|