mirror of
https://github.com/kairos-io/provider-kairos.git
synced 2025-09-25 14:36:49 +00:00
Move common
Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com>
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/kairos-io/kairos-sdk/utils"
|
||||
providerConfig "github.com/kairos-io/provider-kairos/v2/internal/provider/config"
|
||||
"github.com/kairos-io/provider-kairos/v2/internal/role"
|
||||
common "github.com/kairos-io/provider-kairos/v2/internal/role"
|
||||
p2p "github.com/kairos-io/provider-kairos/v2/internal/role/p2p"
|
||||
edgeVPNClient "github.com/mudler/edgevpn/api/client"
|
||||
|
||||
@@ -111,26 +112,26 @@ func Bootstrap(e *pluggable.Event) pluggable.EventResponse {
|
||||
service.WithUUID(machine.UUID()),
|
||||
service.WithStateDir("/usr/local/.kairos/state"),
|
||||
service.WithNetworkToken(prvConfig.P2P.NetworkToken),
|
||||
service.WithPersistentRoles(p2p.RoleAuto),
|
||||
service.WithPersistentRoles(common.RoleAuto),
|
||||
service.WithRoles(
|
||||
service.RoleKey{
|
||||
Role: p2p.RoleControlPlane,
|
||||
RoleHandler: p2p.ControlPlane(c, prvConfig, p2p.RoleControlPlane),
|
||||
Role: common.RoleControlPlane,
|
||||
RoleHandler: p2p.ControlPlane(c, prvConfig, common.RoleControlPlane),
|
||||
},
|
||||
service.RoleKey{
|
||||
Role: p2p.RoleControlPlaneClusterInit,
|
||||
RoleHandler: p2p.ControlPlane(c, prvConfig, p2p.RoleControlPlaneClusterInit),
|
||||
Role: common.RoleControlPlaneClusterInit,
|
||||
RoleHandler: p2p.ControlPlane(c, prvConfig, common.RoleControlPlaneClusterInit),
|
||||
},
|
||||
service.RoleKey{
|
||||
Role: p2p.RoleControlPlaneHA,
|
||||
RoleHandler: p2p.ControlPlane(c, prvConfig, p2p.RoleControlPlaneHA),
|
||||
Role: common.RoleControlPlaneHA,
|
||||
RoleHandler: p2p.ControlPlane(c, prvConfig, common.RoleControlPlaneHA),
|
||||
},
|
||||
service.RoleKey{
|
||||
Role: p2p.RoleWorker,
|
||||
Role: common.RoleWorker,
|
||||
RoleHandler: p2p.Worker(c, prvConfig),
|
||||
},
|
||||
service.RoleKey{
|
||||
Role: p2p.RoleAuto,
|
||||
Role: common.RoleAuto,
|
||||
RoleHandler: role.Auto(c, prvConfig),
|
||||
},
|
||||
),
|
||||
|
@@ -1,12 +1,19 @@
|
||||
package role
|
||||
|
||||
import (
|
||||
"io/ioutil" // nolint
|
||||
"os"
|
||||
|
||||
service "github.com/mudler/edgevpn/api/client/service"
|
||||
)
|
||||
|
||||
const (
|
||||
RoleWorker = "worker"
|
||||
RoleControlPlane = "master"
|
||||
RoleControlPlaneHA = "master/ha"
|
||||
RoleControlPlaneClusterInit = "master/clusterinit"
|
||||
RoleAuto = "auto"
|
||||
)
|
||||
|
||||
type Role func(*service.RoleConfig) error
|
||||
|
||||
func SentinelExist() bool {
|
||||
@@ -17,7 +24,7 @@ func SentinelExist() bool {
|
||||
}
|
||||
|
||||
func CreateSentinel() error {
|
||||
return ioutil.WriteFile("/usr/local/.kairos/deployed", []byte{}, os.ModePerm)
|
||||
return os.WriteFile("/usr/local/.kairos/deployed", []byte{}, os.ModePerm)
|
||||
}
|
||||
|
||||
func getRoles(client *service.Client, nodes []string) ([]string, map[string]string) {
|
||||
|
@@ -7,14 +7,6 @@ import (
|
||||
providerConfig "github.com/kairos-io/provider-kairos/v2/internal/provider/config"
|
||||
)
|
||||
|
||||
const (
|
||||
RoleWorker = "worker"
|
||||
RoleControlPlane = "master"
|
||||
RoleControlPlaneHA = "master/ha"
|
||||
RoleControlPlaneClusterInit = "master/clusterinit"
|
||||
RoleAuto = "auto"
|
||||
)
|
||||
|
||||
func guessInterface(pconfig *providerConfig.Config) string {
|
||||
if pconfig.KubeVIP.Interface != "" {
|
||||
return pconfig.KubeVIP.Interface
|
||||
|
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/kairos-io/kairos-sdk/machine"
|
||||
"github.com/kairos-io/kairos-sdk/utils"
|
||||
providerConfig "github.com/kairos-io/provider-kairos/v2/internal/provider/config"
|
||||
common "github.com/kairos-io/provider-kairos/v2/internal/role"
|
||||
service "github.com/mudler/edgevpn/api/client/service"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
@@ -213,7 +214,7 @@ func (k *K0sWorker) RoleConfig() *service.RoleConfig {
|
||||
}
|
||||
|
||||
func (k *K0sControlPlane) HA() bool {
|
||||
return k.role == RoleControlPlaneHA
|
||||
return k.role == common.RoleControlPlaneHA
|
||||
}
|
||||
|
||||
func (k *K0sControlPlane) ClusterInit() bool {
|
||||
|
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/kairos-io/kairos-sdk/machine"
|
||||
"github.com/kairos-io/kairos-sdk/utils"
|
||||
providerConfig "github.com/kairos-io/provider-kairos/v2/internal/provider/config"
|
||||
common "github.com/kairos-io/provider-kairos/v2/internal/role"
|
||||
service "github.com/mudler/edgevpn/api/client/service"
|
||||
)
|
||||
|
||||
@@ -176,11 +177,11 @@ func (k *K3sWorker) RoleConfig() *service.RoleConfig {
|
||||
}
|
||||
|
||||
func (k *K3sControlPlane) HA() bool {
|
||||
return k.role == RoleControlPlaneHA
|
||||
return k.role == common.RoleControlPlaneHA
|
||||
}
|
||||
|
||||
func (k *K3sControlPlane) ClusterInit() bool {
|
||||
return k.role == RoleControlPlaneClusterInit
|
||||
return k.role == common.RoleControlPlaneClusterInit
|
||||
}
|
||||
|
||||
func (k *K3sControlPlane) IP() string {
|
||||
|
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
providerConfig "github.com/kairos-io/provider-kairos/v2/internal/provider/config"
|
||||
"github.com/kairos-io/provider-kairos/v2/internal/role"
|
||||
common "github.com/kairos-io/provider-kairos/v2/internal/role"
|
||||
service "github.com/mudler/edgevpn/api/client/service"
|
||||
)
|
||||
|
||||
@@ -41,7 +42,7 @@ func Worker(cc *config.Config, pconfig *providerConfig.Config) role.Role { //nol
|
||||
}
|
||||
|
||||
ip := guessIP(pconfig)
|
||||
worker.SetRole(RoleWorker)
|
||||
worker.SetRole(common.RoleWorker)
|
||||
worker.SetRoleConfig(c)
|
||||
worker.SetIP(ip)
|
||||
|
||||
|
@@ -34,8 +34,6 @@ func scheduleRoles(nodes []string, c *service.RoleConfig, cc *config.Config, pco
|
||||
hasControlPlane := false
|
||||
|
||||
controlPlaneRole := "master"
|
||||
workerRole := "worker"
|
||||
controlPlaneHA := "master/ha"
|
||||
|
||||
if pconfig.P2P.Auto.HA.IsEnabled() {
|
||||
controlPlaneRole = "master/clusterinit"
|
||||
@@ -46,7 +44,7 @@ func scheduleRoles(nodes []string, c *service.RoleConfig, cc *config.Config, pco
|
||||
switch r {
|
||||
case controlPlaneRole:
|
||||
hasControlPlane = true
|
||||
case controlPlaneHA:
|
||||
case RoleControlPlaneHA:
|
||||
controlPlaneCounter++
|
||||
}
|
||||
}
|
||||
@@ -87,7 +85,7 @@ func scheduleRoles(nodes []string, c *service.RoleConfig, cc *config.Config, pco
|
||||
|
||||
if pconfig.P2P.Auto.HA.IsEnabled() && pconfig.P2P.Auto.HA.ExtraControlPlanes != nil && *pconfig.P2P.Auto.HA.ExtraControlPlanes() != controlPlaneCounter {
|
||||
if len(unassignedNodes) > 0 {
|
||||
if err := c.Client.Set("role", unassignedNodes[0], controlPlaneHA); err != nil {
|
||||
if err := c.Client.Set("role", unassignedNodes[0], RoleControlPlaneHA); err != nil {
|
||||
c.Logger.Error(err)
|
||||
return err
|
||||
}
|
||||
@@ -99,11 +97,11 @@ func scheduleRoles(nodes []string, c *service.RoleConfig, cc *config.Config, pco
|
||||
|
||||
// cycle all empty roles and assign worker roles
|
||||
for _, uuid := range unassignedNodes {
|
||||
if err := c.Client.Set("role", uuid, workerRole); err != nil {
|
||||
if err := c.Client.Set("role", uuid, RoleWorker); err != nil {
|
||||
c.Logger.Error(err)
|
||||
return err
|
||||
}
|
||||
c.Logger.Infof("-> Set %s to %s", workerRole, uuid)
|
||||
c.Logger.Infof("-> Set %s to %s", RoleWorker, uuid)
|
||||
}
|
||||
|
||||
c.Logger.Info("Done scheduling")
|
||||
|
Reference in New Issue
Block a user