Skip to content

Commit

Permalink
feat(autok3s): support multiple region scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
rancher-sy-bot committed Aug 20, 2020
1 parent 2e4ce1d commit c90be86
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
4 changes: 4 additions & 0 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func CreateCommand() *cobra.Command {
logrus.Fatalln(err)
}

// generate cluster name. e.g. input: "--name k3s1 --region cn-hangzhou" output: "k3s1.cn-hangzhou"
cp.GenerateClusterName()

// create k3s cluster with generated cluster name.
if err := cp.CreateK3sCluster(cSSH); err != nil {
logrus.Errorln(err)
if rErr := cp.Rollback(); rErr != nil {
Expand Down
4 changes: 4 additions & 0 deletions cmd/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func JoinCommand() *cobra.Command {
logrus.Fatalln(err)
}

// generate cluster name. e.g. input: "--name k3s1 --region cn-hangzhou" output: "k3s1.cn-hangzhou"
cp.GenerateClusterName()

// join k3s node to the cluster which named with generated cluster name.
if err := jp.JoinK3sNode(jSSH); err != nil {
logrus.Errorln(err)
if rErr := cp.Rollback(); rErr != nil {
Expand Down
10 changes: 5 additions & 5 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
)

const (
MasterInstancePrefix = "autok3s.%s.m" // autok3s.<cluster>.m
WorkerInstancePrefix = "autok3s.%s.w" // autok3s.<cluster>.w
MasterInstanceName = MasterInstancePrefix + "[%d,%d]" // autok3s.<cluster>.m<index>
WorkerInstanceName = WorkerInstancePrefix + "[%d,%d]" // autok3s.<cluster>.w<index>
WildcardInstanceName = "autok3s.%s.*" // autok3s.<cluster>.*
MasterInstancePrefix = "autok3s.%s.m" // autok3s.<cluster.region>.m
WorkerInstancePrefix = "autok3s.%s.w" // autok3s.<cluster.region>.w
MasterInstanceName = MasterInstancePrefix + "[%d,%d]" // autok3s.<cluster.region>.m<index>
WorkerInstanceName = WorkerInstancePrefix + "[%d,%d]" // autok3s.<cluster.region>.w<index>
WildcardInstanceName = "autok3s.%s.*" // autok3s.<cluster.region>.*
BindPrefix = "autok3s.providers.%s.%s"
ConfigFile = "config.yaml"
StateFile = ".state"
Expand Down
4 changes: 4 additions & 0 deletions pkg/providers/alibaba/alibaba.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func (p *Alibaba) GetProviderName() string {
return "alibaba"
}

func (p *Alibaba) GenerateClusterName() {
p.Name = fmt.Sprintf("%s.%s", p.Name, p.Region)
}

func (p *Alibaba) CreateK3sCluster(ssh *types.SSH) error {
s := utils.NewSpinner("Generating K3s cluster: ")
s.Start()
Expand Down
2 changes: 2 additions & 0 deletions pkg/providers/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type Provider interface {
GetCredentialFlags(cmd *cobra.Command) *pflag.FlagSet
// Use this method to bind Viper, although it is somewhat repetitive.
BindCredentialFlags() *pflag.FlagSet
// Generate cluster name.
GenerateClusterName()
// K3s create cluster interface.
CreateK3sCluster(ssh *types.SSH) error
// K3s join node interface.
Expand Down

0 comments on commit c90be86

Please # to comment.