From 8481c3547cccd895f02e63f3cec1a3fcc03931c2 Mon Sep 17 00:00:00 2001 From: Jason-ZW Date: Mon, 7 Sep 2020 13:53:06 +0800 Subject: [PATCH] fix(alibaba): rename instance hostname Signed-off-by: Jason-ZW --- pkg/common/common.go | 8 +++----- pkg/providers/alibaba/alibaba.go | 15 +++++++-------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/pkg/common/common.go b/pkg/common/common.go index 0619e188..30188c15 100644 --- a/pkg/common/common.go +++ b/pkg/common/common.go @@ -7,11 +7,9 @@ import ( ) const ( - MasterInstancePrefix = "autok3s.%s.m" // autok3s..m - WorkerInstancePrefix = "autok3s.%s.w" // autok3s..w - MasterInstanceName = MasterInstancePrefix + "[%d,%d]" // autok3s..m - WorkerInstanceName = WorkerInstancePrefix + "[%d,%d]" // autok3s..w - WildcardInstanceName = "autok3s.%s.*" // autok3s..* + MasterInstancePrefix = "autok3s.%s.m" // autok3s..m + WorkerInstancePrefix = "autok3s.%s.w" // autok3s..w + WildcardInstanceName = "autok3s.%s.*" // autok3s..* BindPrefix = "autok3s.providers.%s.%s" ConfigFile = "config.yaml" StateFile = ".state" diff --git a/pkg/providers/alibaba/alibaba.go b/pkg/providers/alibaba/alibaba.go index 247780a1..193a401b 100644 --- a/pkg/providers/alibaba/alibaba.go +++ b/pkg/providers/alibaba/alibaba.go @@ -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 } @@ -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 } @@ -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 @@ -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)