1
0
mirror of https://github.com/rancher/rke.git synced 2025-08-01 23:33:39 +00:00

make cluster.yml optional in --local

This commit is contained in:
galal-hussein 2018-01-15 06:36:28 +02:00
parent 8ea54f573f
commit 447eb6a479
4 changed files with 65 additions and 24 deletions

View File

@ -298,13 +298,3 @@ func (c *Cluster) ApplyAuthzResources(ctx context.Context) error {
}
return nil
}
func GetLocalRKENodeConfig() *v3.RKEConfigNode {
rkeLocalNode := &v3.RKEConfigNode{
Address: LocalNodeAddress,
HostnameOverride: LocalNodeHostname,
User: LocalNodeUser,
Role: []string{services.ControlRole, services.WorkerRole, services.ETCDRole},
}
return rkeLocalNode
}

33
cluster/local.go Normal file
View File

@ -0,0 +1,33 @@
package cluster
import (
"github.com/rancher/rke/services"
"github.com/rancher/types/apis/management.cattle.io/v3"
)
func GetLocalRKEConfig() *v3.RancherKubernetesEngineConfig {
rkeLocalNode := GetLocalRKENodeConfig()
rkeServices := v3.RKEConfigServices{
Kubelet: v3.KubeletService{
BaseService: v3.BaseService{
Image: DefaultK8sImage,
ExtraArgs: map[string]string{"fail-swap-on": "false"},
},
},
}
return &v3.RancherKubernetesEngineConfig{
Nodes: []v3.RKEConfigNode{*rkeLocalNode},
Services: rkeServices,
}
}
func GetLocalRKENodeConfig() *v3.RKEConfigNode {
rkeLocalNode := &v3.RKEConfigNode{
Address: LocalNodeAddress,
HostnameOverride: LocalNodeHostname,
User: LocalNodeUser,
Role: []string{services.ControlRole, services.WorkerRole, services.ETCDRole},
}
return rkeLocalNode
}

View File

@ -68,7 +68,6 @@ func ClusterRemove(
}
func clusterRemoveFromCli(ctx *cli.Context) error {
var local bool
force := ctx.Bool("force")
if !force {
reader := bufio.NewReader(os.Stdin)
@ -82,6 +81,9 @@ func clusterRemoveFromCli(ctx *cli.Context) error {
return nil
}
}
if ctx.Bool("local") {
return clusterRemoveLocal(ctx)
}
clusterFile, filePath, err := resolveClusterFile(ctx)
if err != nil {
return fmt.Errorf("Failed to resolve cluster file: %v", err)
@ -91,9 +93,11 @@ func clusterRemoveFromCli(ctx *cli.Context) error {
if err != nil {
return fmt.Errorf("Failed to parse cluster file: %v", err)
}
if ctx.Bool("local") {
rkeConfig.Nodes = []v3.RKEConfigNode{*cluster.GetLocalRKENodeConfig()}
local = true
}
return ClusterRemove(context.Background(), rkeConfig, nil, local, "")
return ClusterRemove(context.Background(), rkeConfig, nil, false, "")
}
func clusterRemoveLocal(ctx *cli.Context) error {
var rkeConfig *v3.RancherKubernetesEngineConfig
rkeConfig = cluster.GetLocalRKEConfig()
return ClusterRemove(context.Background(), rkeConfig, nil, true, "")
}

View File

@ -114,8 +114,9 @@ func ClusterUp(
}
func clusterUpFromCli(ctx *cli.Context) error {
var local bool
var localConnDialerFactory hosts.DialerFactory
if ctx.Bool("local") {
return clusterUpLocal(ctx)
}
clusterFile, filePath, err := resolveClusterFile(ctx)
if err != nil {
return fmt.Errorf("Failed to resolve cluster file: %v", err)
@ -126,11 +127,24 @@ func clusterUpFromCli(ctx *cli.Context) error {
if err != nil {
return fmt.Errorf("Failed to parse cluster file: %v", err)
}
if ctx.Bool("local") {
rkeConfig.Nodes = []v3.RKEConfigNode{*cluster.GetLocalRKENodeConfig()}
localConnDialerFactory = hosts.LocalHealthcheckFactory
local = true
}
_, _, _, _, err = ClusterUp(context.Background(), rkeConfig, nil, localConnDialerFactory, local, "")
_, _, _, _, err = ClusterUp(context.Background(), rkeConfig, nil, nil, false, "")
return err
}
func clusterUpLocal(ctx *cli.Context) error {
var rkeConfig *v3.RancherKubernetesEngineConfig
clusterFile, filePath, err := resolveClusterFile(ctx)
if err != nil {
log.Infof(context.Background(), "Failed to resolve cluster file, using default cluster instead")
rkeConfig = cluster.GetLocalRKEConfig()
} else {
clusterFilePath = filePath
rkeConfig, err = cluster.ParseConfig(clusterFile)
if err != nil {
return fmt.Errorf("Failed to parse cluster file: %v", err)
}
rkeConfig.Nodes = []v3.RKEConfigNode{*cluster.GetLocalRKENodeConfig()}
}
_, _, _, _, err = ClusterUp(context.Background(), rkeConfig, nil, hosts.LocalHealthcheckFactory, true, "")
return err
}