From 4c16456294aef29bf8f6b36519795fde87687daf Mon Sep 17 00:00:00 2001 From: Jason-ZW Date: Mon, 7 Sep 2020 14:38:34 +0800 Subject: [PATCH] fix(alibaba): readd missing nodes Signed-off-by: Jason-ZW --- pkg/common/common.go | 6 +++--- pkg/providers/alibaba/alibaba.go | 28 +++++++++++++++++++++++++--- pkg/types/autok3s.go | 1 + 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/pkg/common/common.go b/pkg/common/common.go index 30188c15..86e76fb0 100644 --- a/pkg/common/common.go +++ b/pkg/common/common.go @@ -7,9 +7,9 @@ import ( ) const ( - MasterInstancePrefix = "autok3s.%s.m" // autok3s..m - WorkerInstancePrefix = "autok3s.%s.w" // 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 193a401b..e249e985 100644 --- a/pkg/providers/alibaba/alibaba.go +++ b/pkg/providers/alibaba/alibaba.go @@ -193,7 +193,10 @@ func (p *Alibaba) Rollback() error { ids := make([]string, 0) p.m.Range(func(key, value interface{}) bool { - ids = append(ids, key.(string)) + v := value.(types.Node) + if v.RollBack { + ids = append(ids, key.(string)) + } return true }) @@ -276,9 +279,9 @@ func (p *Alibaba) runInstances(num int, master bool) error { } for _, id := range response.InstanceIdSets.InstanceIdSet { if master { - p.m.Store(id, types.Node{Master: true, InstanceID: id, InstanceStatus: alibaba.StatusPending}) + p.m.Store(id, types.Node{Master: true, RollBack: true, InstanceID: id, InstanceStatus: alibaba.StatusPending}) } else { - p.m.Store(id, types.Node{Master: false, InstanceID: id, InstanceStatus: alibaba.StatusPending}) + p.m.Store(id, types.Node{Master: false, RollBack: true, InstanceID: id, InstanceStatus: alibaba.StatusPending}) } } @@ -371,6 +374,25 @@ func (p *Alibaba) assembleInstanceStatus(ssh *types.SSH) (*types.Cluster, error) v.InternalIPAddress = status.VpcAttributes.PrivateIpAddress.IpAddress v.PublicIPAddress = status.PublicIpAddress.IpAddress p.m.Store(status.InstanceId, v) + continue + } + + if strings.Contains(status.InstanceName, ".m.") { + p.m.Store(status.InstanceId, types.Node{ + Master: true, + RollBack: false, + InstanceID: status.InstanceId, + InstanceStatus: alibaba.StatusRunning, + InternalIPAddress: status.VpcAttributes.PrivateIpAddress.IpAddress, + PublicIPAddress: status.PublicIpAddress.IpAddress}) + } else { + p.m.Store(status.InstanceId, types.Node{ + Master: false, + RollBack: false, + InstanceID: status.InstanceId, + InstanceStatus: alibaba.StatusRunning, + InternalIPAddress: status.VpcAttributes.PrivateIpAddress.IpAddress, + PublicIPAddress: status.PublicIpAddress.IpAddress}) } } diff --git a/pkg/types/autok3s.go b/pkg/types/autok3s.go index 9ae59f8c..275f382c 100644 --- a/pkg/types/autok3s.go +++ b/pkg/types/autok3s.go @@ -39,6 +39,7 @@ type Node struct { InstanceStatus string `json:"instance-status,omitempty" yaml:"instance-status,omitempty"` PublicIPAddress []string `json:"public-ip-address,omitempty" yaml:"public-ip-address,omitempty"` InternalIPAddress []string `json:"internal-ip-address,omitempty" yaml:"internal-ip-address,omitempty"` + RollBack bool `json:"-" yaml:"-"` } type SSH struct {