Skip to content

Commit

Permalink
fix(alibaba): rename instance hostname
Browse files Browse the repository at this point in the history
Signed-off-by: Jason-ZW <zhenyang@rancher.com>
  • Loading branch information
rancher-sy-bot committed Sep 8, 2020
1 parent 83554f6 commit 8481c35
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
8 changes: 3 additions & 5 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import (
)

const (
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>.*
MasterInstancePrefix = "autok3s.%s.m" // autok3s.<cluster.region>.m
WorkerInstancePrefix = "autok3s.%s.w" // autok3s.<cluster.region>.w
WildcardInstanceName = "autok3s.%s.*" // autok3s.<cluster.region>.*
BindPrefix = "autok3s.providers.%s.%s"
ConfigFile = "config.yaml"
StateFile = ".state"
Expand Down
15 changes: 7 additions & 8 deletions pkg/providers/alibaba/alibaba.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ func (p *Alibaba) CreateK3sCluster(ssh *types.SSH) (err error) {
workerNum, _ := strconv.Atoi(p.Worker)

// run ecs master instances.
if err = p.runInstances(masterNum, 1, true); err != nil {
if err = p.runInstances(masterNum, true); err != nil {
return
}

// run ecs worker instances.
if err = p.runInstances(workerNum, 1, false); err != nil {
if err = p.runInstances(workerNum, false); err != nil {
return
}

Expand Down Expand Up @@ -152,7 +152,7 @@ func (p *Alibaba) JoinK3sNode(ssh *types.SSH) error {
workerNum, _ := strconv.Atoi(p.Worker)

// run ecs worker instances.
if err := p.runInstances(workerNum, len(p.WorkerNodes)+1, false); err != nil {
if err := p.runInstances(workerNum, false); err != nil {
return err
}

Expand Down Expand Up @@ -246,7 +246,7 @@ func (p *Alibaba) generateClientSDK() error {
return nil
}

func (p *Alibaba) runInstances(num, startIndex int, master bool) error {
func (p *Alibaba) runInstances(num int, master bool) error {
request := ecs.CreateRunInstancesRequest()
request.Scheme = "https"
request.InstanceType = p.Type
Expand All @@ -259,15 +259,14 @@ func (p *Alibaba) runInstances(num, startIndex int, master bool) error {
outBandWidth, _ := strconv.Atoi(p.InternetMaxBandwidthOut)
request.InternetMaxBandwidthOut = requests.NewInteger(outBandWidth)
request.Amount = requests.NewInteger(num)
request.UniqueSuffix = requests.NewBoolean(true)

if master {
// TODO: HA mode will be added soon, temporary set master number to 1.
request.Amount = requests.NewInteger(1)
request.InstanceName = fmt.Sprintf(common.MasterInstanceName, p.Name, startIndex, 4)
request.HostName = fmt.Sprintf(common.MasterInstanceName, p.Name, startIndex, 4)
request.InstanceName = fmt.Sprintf(common.MasterInstancePrefix, p.Name)
} else {
request.InstanceName = fmt.Sprintf(common.WorkerInstanceName, p.Name, startIndex, 4)
request.HostName = fmt.Sprintf(common.WorkerInstanceName, p.Name, startIndex, 4)
request.InstanceName = fmt.Sprintf(common.WorkerInstancePrefix, p.Name)
}

response, err := p.c.RunInstances(request)
Expand Down

0 comments on commit 8481c35

Please # to comment.