1
0
mirror of https://github.com/rancher/rke.git synced 2025-08-31 14:36:32 +00:00

Structure and config changes

This commit is contained in:
galal-hussein
2017-11-28 19:45:24 +02:00
parent c77d3b51be
commit 41c48877ba
22 changed files with 255 additions and 135 deletions

View File

@@ -3,6 +3,8 @@ package cluster
import (
"fmt"
"strings"
"github.com/rancher/rke/services"
)
func (c *Cluster) ValidateCluster() error {
@@ -10,19 +12,79 @@ func (c *Cluster) ValidateCluster() error {
if len(c.ControlPlaneHosts) == 0 {
return fmt.Errorf("Cluster must have at least one control plane host")
}
if len(c.EtcdHosts) == 0 {
return fmt.Errorf("Cluster must have at least one etcd host")
if len(c.EtcdHosts)%2 == 0 {
return fmt.Errorf("Cluster must have odd number of etcd nodes")
}
if len(c.WorkerHosts) == 0 {
return fmt.Errorf("Cluster must have at least one worker plane host")
}
// validate hosts options
if err := validateHostsOptions(c); err != nil {
return err
}
// validate Auth options
if err := validateAuthOptions(c); err != nil {
return err
}
// validate Network options
if err := validateNetworkOptions(c); err != nil {
return err
}
// validate services options
err := validateServicesOption(c)
if err != nil {
if err := validateServicesOptions(c); err != nil {
return err
}
return nil
}
func validateServicesOption(c *Cluster) error {
func validateAuthOptions(c *Cluster) error {
if c.Authentication.Strategy != DefaultAuthStrategy {
return fmt.Errorf("Authentication strategy [%s] is not supported", c.Authentication.Strategy)
}
return nil
}
func validateNetworkOptions(c *Cluster) error {
if c.Network.Plugin != FlannelNetworkPlugin && c.Network.Plugin != CalicoNetworkPlugin && c.Network.Plugin != CanalNetworkPlugin {
return fmt.Errorf("Network plugin [%s] is not supported", c.Network.Plugin)
}
return nil
}
func validateHostsOptions(c *Cluster) error {
for i, host := range c.Nodes {
if len(host.Address) == 0 {
return fmt.Errorf("User for host (%d) is not provided", i+1)
}
if len(host.User) == 0 {
return fmt.Errorf("User for host (%d) is not provided", i+1)
}
if len(host.Role) == 0 {
return fmt.Errorf("Role for host (%d) is not provided", i+1)
}
for _, role := range host.Role {
if role != services.ETCDRole && role != services.ControlRole && role != services.WorkerRole {
return fmt.Errorf("Role [%s] for host (%d) is not recognized", role, i+1)
}
}
k := 0
for _, role := range host.Role {
if role == services.ControlRole || role == services.WorkerRole {
k++
}
}
if k > 1 {
return fmt.Errorf("Host (%d) can't contain both worker and controlplane roles", i+1)
}
}
return nil
}
func validateServicesOptions(c *Cluster) error {
servicesOptions := map[string]string{
"etcd_image": c.Services.Etcd.Image,
"kube_api_image": c.Services.KubeAPI.Image,