refactor(master): fix aliyun infra (#822)

* refactor(master): fix aliyun infra
This commit is contained in:
cuisongliu
2022-01-06 22:21:02 +08:00
committed by GitHub
parent 3946f68649
commit db510bf2ab
3 changed files with 18 additions and 13 deletions
+10 -3
View File
@@ -15,9 +15,10 @@
package aliyun
import (
"fmt"
"strings"
"github.com/fanux/sealos/pkg/types/validation"
"github.com/fanux/sealos/pkg/logger"
"k8s.io/apimachinery/pkg/util/validation/field"
@@ -108,8 +109,8 @@ var RecocileFuncMap = map[ActionName]func(provider *AliProvider) error{
host := &h
statusIndex := aliProvider.Infra.Status.FindHostsByRoles(h.Roles)
if statusIndex < 0 {
errorMsg = append(errorMsg, fmt.Sprintf("infra status not fount in role tag: %v", h.Roles))
continue
aliProvider.Infra.Status.Hosts = append(aliProvider.Infra.Status.Hosts, v1beta1.HostStatus{Roles: h.Roles})
statusIndex = len(aliProvider.Infra.Status.Hosts) - 1
}
status := &aliProvider.Infra.Status.Hosts[statusIndex]
err := aliProvider.ReconcileInstances(host, status)
@@ -237,6 +238,12 @@ func (a *AliProvider) Reconcile() error {
}
func (a *AliProvider) Apply() error {
if err := v1beta1.Default(a.Infra, DefaultInfra); err != nil {
return err
}
if err := validation.ValidateInfra(a.Infra, DefaultValidate); len(err) != 0 {
return err.ToAggregate()
}
return a.Reconcile()
}
-6
View File
@@ -48,12 +48,6 @@ func loadConfig(infra *v2.Infra) {
func newAliProvider(infra *v2.Infra) (Interface, error) {
aliProvider := new(aliyun.AliProvider)
aliProvider.Infra = infra
if err := v2.Default(aliProvider.Infra, aliyun.DefaultInfra); err != nil {
return nil, err
}
if err := validation.ValidateInfra(aliProvider.Infra, aliyun.DefaultValidate); len(err) != 0 {
return nil, err.ToAggregate()
}
if err := aliProvider.NewClient(); err != nil {
return nil, err
}
+8 -4
View File
@@ -61,8 +61,9 @@ func TestAliApply(t *testing.T) {
Count: 1,
Disks: []v2.Disk{},
OS: v2.OS{
Name: "ubuntu",
ID: "centos_8_0_x64_20G_alibase_20210712.vhd",
},
EcsType: "ecs.c7a.large",
},
},
Provider: aliyun.AliyunProvider,
@@ -87,8 +88,9 @@ func TestAliApply(t *testing.T) {
Count: 1,
Disks: []v2.Disk{},
OS: v2.OS{
Name: "centos",
ID: "centos_8_0_x64_20G_alibase_20210712.vhd",
},
EcsType: "ecs.c7a.large",
},
{
Roles: []string{"master", "ssdxxx"},
@@ -97,8 +99,9 @@ func TestAliApply(t *testing.T) {
Count: 1,
Disks: []v2.Disk{},
OS: v2.OS{
Name: "ubuntu",
ID: "centos_8_0_x64_20G_alibase_20210712.vhd",
},
EcsType: "ecs.c7a.large",
},
}
t.Log(fmt.Sprintf("add server:%v", aliProvider.Apply()))
@@ -113,8 +116,9 @@ func TestAliApply(t *testing.T) {
Count: 1,
Disks: []v2.Disk{},
OS: v2.OS{
Name: "centos",
ID: "centos_8_0_x64_20G_alibase_20210712.vhd",
},
EcsType: "ecs.s6-c1m2.large",
},
}
t.Log(fmt.Sprintf("delete:%v", aliProvider.Apply()))