🌱 Change config to be more user friendly

Signed-off-by: Ettore Di Giacinto <mudler@mocaccino.org>
This commit is contained in:
Ettore Di Giacinto
2022-12-12 15:38:21 +01:00
parent e193a3f3b2
commit 4857ff8879
4 changed files with 27 additions and 15 deletions

View File

@@ -50,7 +50,7 @@ func Bootstrap(e *pluggable.Event) pluggable.EventResponse {
p2pBlockDefined := providerConfig.P2P != nil
tokenNotDefined := ((p2pBlockDefined && providerConfig.P2P.NetworkToken == "") || !p2pBlockDefined)
skipAuto := (p2pBlockDefined && providerConfig.P2P.SkipAuto)
skipAuto := (p2pBlockDefined && !providerConfig.P2P.Auto.IsEnabled())
if providerConfig.P2P == nil && !providerConfig.K3s.Enabled && !providerConfig.K3sAgent.Enabled {
return pluggable.EventResponse{State: fmt.Sprintf("no kairos or k3s configuration. nothing to do: %s", cfg.Config)}

View File

@@ -9,9 +9,8 @@ type P2P struct {
VPN VPN `yaml:"vpn,omitempty"`
MinimumNodes int `yaml:"minimum_nodes,omitempty"`
SkipAuto bool `yaml:"skip_auto"`
DisableDHT bool `yaml:"disable_dht,omitempty"`
AutoHA AutoHA `yaml:"auto-ha,omitempty"`
Auto Auto `yaml:"auto,omitempty"`
DynamicRoles bool `yaml:"dynamic_roles,omitempty"`
}
@@ -45,17 +44,30 @@ type KubeVIP struct {
EIP string `yaml:"eip,omitempty"`
ManifestURL string `yaml:"manifest_url,omitempty"`
Interface string `yaml:"interface,omitempty"`
Enable bool `yaml:"enable,omitempty"`
Enable *bool `yaml:"enable,omitempty"`
}
func (k KubeVIP) IsEnabled() bool {
return k.Enable || k.EIP != ""
return k.Enable == nil || k.EIP != "" || (k.Enable != nil && *k.Enable)
}
type AutoHA struct {
Enable bool `yaml:"enable,omitempty"`
type Auto struct {
Enable *bool `yaml:"enable,omitempty"`
HA HA `yaml:"ha,omitempty"`
}
func (a Auto) IsEnabled() bool {
return a.Enable == nil || (a.Enable != nil && *a.Enable)
}
func (ha HA) IsEnabled() bool {
return (ha.Enable != nil && *ha.Enable) || (ha.Enable == nil && ha.MasterNodes != nil)
}
type HA struct {
Enable *bool `yaml:"enable,omitempty"`
ExternalDB string `yaml:"external_db,omitempty"`
MasterNodes int `yaml:"master_nodes,omitempty"`
MasterNodes *int `yaml:"master_nodes,omitempty"`
}
type K3s struct {

View File

@@ -183,8 +183,8 @@ func Master(cc *config.Config, pconfig *providerConfig.Config, clusterInit, ha b
}
}
if pconfig.P2P.AutoHA.ExternalDB != "" {
args = []string{fmt.Sprintf("--datastore-endpoint=%s", pconfig.P2P.AutoHA.ExternalDB)}
if pconfig.P2P.Auto.HA.ExternalDB != "" {
args = []string{fmt.Sprintf("--datastore-endpoint=%s", pconfig.P2P.Auto.HA.ExternalDB)}
}
if ha && !clusterInit {
@@ -198,7 +198,7 @@ func Master(cc *config.Config, pconfig *providerConfig.Config, clusterInit, ha b
args = append(args, k3sConfig.Args...)
}
if clusterInit && ha && pconfig.P2P.AutoHA.ExternalDB == "" {
if clusterInit && ha && pconfig.P2P.Auto.HA.ExternalDB == "" {
args = append(args, "--cluster-init")
}

View File

@@ -40,7 +40,7 @@ func scheduleRoles(nodes []string, c *service.RoleConfig, cc *config.Config, pco
workerRole := "worker"
masterHA := "master/ha"
if pconfig.P2P.AutoHA.Enable {
if pconfig.P2P.Auto.HA.IsEnabled() {
masterRole = "master/clusterinit"
}
mastersHA := 0
@@ -88,7 +88,7 @@ func scheduleRoles(nodes []string, c *service.RoleConfig, cc *config.Config, pco
return nil
}
if pconfig.P2P.AutoHA.Enable && pconfig.P2P.AutoHA.MasterNodes != mastersHA {
if pconfig.P2P.Auto.HA.IsEnabled() && pconfig.P2P.Auto.HA.MasterNodes != nil && *pconfig.P2P.Auto.HA.MasterNodes != mastersHA {
if len(unassignedNodes) > 0 {
if err := c.Client.Set("role", unassignedNodes[0], masterHA); err != nil {
c.Logger.Error(err)