Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify the data type and restore the default value #120

Merged
merged 1 commit into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions src/bosh-alicloud-cpi/action/create_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ type InstanceProps struct {
AvailabilityZone string `json:"availability_zone"`
InstanceName string `json:"instance_name"`
InstanceType string `json:"instance_type"`
SlbServerGroupWeight int `json:"slb_server_group_weight"`
SlbServerGroupPort int `json:"slb_server_group_port"`
SlbServerGroupWeight json.Number `json:"slb_server_group_weight"`
SlbServerGroupPort json.Number `json:"slb_server_group_port"`
SlbServerGroup []string `json:"slb_server_group"`
Slbs []string `json:"slbs"`
SlbWeight int `json:"slb_weight"`
SlbWeight json.Number `json:"slb_weight"`
Password string `json:"password"`
KeyPairName string `json:"key_pair_name"`
SecurityGroupIds []string `json:"security_group_ids"`
Expand Down Expand Up @@ -357,16 +357,34 @@ func (a CreateVMMethod) updateInstance(instCid string, associatedDiskCIDs []apiv
return bosherr.WrapErrorf(err, "bind eip %s to %s failed", eip, instCid)
}
}
slbWeight, err := instProps.SlbWeight.Int64()
if err != nil {
slbWeight = alicloud.DefaultSlbWeight
} else if slbWeight == 0 {
slbWeight = alicloud.DefaultSlbWeight
}
for _, slb := range instProps.Slbs {
err := a.networks.BindSLB(instProps.Region, instCid, slb, instProps.SlbWeight)
err := a.networks.BindSLB(instProps.Region, instCid, slb, int(slbWeight))
if err != nil {
return bosherr.WrapErrorf(err, "bind %s to slb %s failed ", instCid, slb)
}
}
slbServerGroupPort, err := instProps.SlbServerGroupPort.Int64()
if err != nil {
slbServerGroupPort = alicloud.DefaultSlbServerGroupPort
} else if slbServerGroupPort == 0 {
slbServerGroupPort = alicloud.DefaultSlbServerGroupPort
}
slbServerGroupWeight, err := instProps.SlbServerGroupWeight.Int64()
if err != nil {
slbServerGroupWeight = alicloud.DefaultSlbServerGroupWeight
} else if slbServerGroupWeight == 0 {
slbServerGroupWeight = alicloud.DefaultSlbServerGroupWeight
}
for _, slbServerGroup := range instProps.SlbServerGroup {
err := a.networks.BindSlbServerGroup(instProps.Region, instCid, slbServerGroup, instProps.SlbServerGroupWeight, instProps.SlbServerGroupPort)
err := a.networks.BindSlbServerGroup(instProps.Region, instCid, slbServerGroup, int(slbServerGroupWeight), int(slbServerGroupPort))
if err != nil {
return bosherr.WrapErrorf(err, "bind %s to slbServerGroup %s failed,weight:%d,port:%d ", instCid, slbServerGroup, instProps.SlbServerGroupWeight, instProps.SlbServerGroupPort)
return bosherr.WrapErrorf(err, "bind %s to slbServerGroup %s failed,weight:%d,port:%d ", instCid, slbServerGroup, slbServerGroupWeight, slbServerGroupPort)
}
}
return nil
Expand Down
9 changes: 6 additions & 3 deletions src/bosh-alicloud-cpi/alicloud/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ const (
WaitTimeout = time.Duration(600) * time.Second
WaitInterval = time.Duration(5) * time.Second

DefaultEipWaitSeconds = 120
BoshCPI = "Bosh-Alicloud-Cpi"
BoshCPIVersion = "1.0"
DefaultEipWaitSeconds = 120
DefaultSlbWeight = 100
BoshCPI = "Bosh-Alicloud-Cpi"
BoshCPIVersion = "1.0"
DefaultSlbServerGroupPort = 33333
DefaultSlbServerGroupWeight = 100
)

type OpenApi struct {
Expand Down
7 changes: 6 additions & 1 deletion src/bosh-alicloud-cpi/alicloud/network_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ func (a NetworkManagerImpl) BindSlbServerGroup(region, instanceId string, slbSer
if err != nil {
return err
}
if weight == 0 {
weight = DefaultSlbServerGroupWeight
}
bytes, _ := json.Marshal([]SlbServerGroupBackendServerType{
{ServerId: instanceId, Weight: weight, Port: port},
})
Expand All @@ -173,7 +176,9 @@ func (a NetworkManagerImpl) BindSLB(region, instanceId string, slbId string, wei
if err != nil {
return err
}

if weight == 0 {
weight = DefaultSlbWeight
}
bytes, _ := json.Marshal([]BackendServerType{
{ServerId: instanceId, Weight: weight},
})
Expand Down
21 changes: 9 additions & 12 deletions src/bosh-alicloud-cpi/integration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,15 @@ var (
imageOssBucket = envOrDefault("CPI_STEMCELL_OSS_BUCKET", "")
imageOssObject = envOrDefault("CPI_STEMCELL_OSS_OBJECT", "")

securityGroupId = os.Getenv("CPI_SECURITY_GROUP_ID")
vswitchId = os.Getenv("CPI_VSWITCH_ID")
internalIp = envOrDefault("CPI_INTERNAL_IP", "172.16.0.31")
internalCidr = envOrDefault("CPI_INTERNAL_CIDR", "172.16.0.0/24")
internalNetmask = envOrDefault("CPI_INTERNAL_NETMASK", "255.240.0.0")
internalGw = envOrDefault("CPI_INTERNAL_GW", "172.16.0.1")
slbId = envOrDefault("CPI_SLB_ID", "")
slbWeight = envOrDefault("CPI_SLB_WEIGHT", "100")
slbServerGroupId = envOrDefault("CPI_SLB_SERVER_GROUP_ID", "")
slbServerGroupPort = envOrDefault("CPI_SLB_SERVER_GROUP_PORT", "33333")
slbServerGroupWeight = envOrDefault("CPI_SLB_SERVER_GROUP_WEIGHT", "100")
externalIp = envOrDefault("CPI_EXTERNAL_IP", "")
securityGroupId = os.Getenv("CPI_SECURITY_GROUP_ID")
vswitchId = os.Getenv("CPI_VSWITCH_ID")
internalIp = envOrDefault("CPI_INTERNAL_IP", "172.16.0.31")
internalCidr = envOrDefault("CPI_INTERNAL_CIDR", "172.16.0.0/24")
internalNetmask = envOrDefault("CPI_INTERNAL_NETMASK", "255.240.0.0")
internalGw = envOrDefault("CPI_INTERNAL_GW", "172.16.0.1")
slbId = envOrDefault("CPI_SLB_ID", "")
slbServerGroupId = envOrDefault("CPI_SLB_SERVER_GROUP_ID", "")
externalIp = envOrDefault("CPI_EXTERNAL_IP", "")

// spot
spotStrategy = envOrDefault("CPI_SPOT_STRATEGY", "SpotWithPriceLimit")
Expand Down
6 changes: 0 additions & 6 deletions src/bosh-alicloud-cpi/integration/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ var _ = Describe("integration:vm", func() {
"instance_name": "bosh-test-cpi-integration",
"instance_type": "ecs.n4.small",
"slb_server_group": ["${SLB_SERVER_GROUP_ID}"],
"slb_server_group_port": ${SLB_SERVER_GROUP_PORT},
"slb_server_group_weight": ${SLB_SERVER_GROUP_WEIGHT},
"system_disk": {
"size": "61_440",
"category": "cloud_efficiency"
Expand Down Expand Up @@ -134,8 +132,6 @@ var _ = Describe("integration:vm", func() {
P("INTERNAL_NETMASK", internalNetmask).
P("INTERNAL_GW", internalGw).
P("SLB_SERVER_GROUP_ID", slbServerGroupId).
P("SLB_SERVER_GROUP_PORT", slbServerGroupPort).
P("SLB_SERVER_GROUP_WEIGHT", slbServerGroupWeight).
ToBytes()

r := caller.Run(in)
Expand Down Expand Up @@ -240,7 +236,6 @@ var _ = Describe("integration:vm", func() {
"instance_name": "bosh-test-cpi-integration",
"instance_type": "ecs.n4.small",
"slbs": ["${SLB_ID}"],
"slb_weight": ${SLB_WEIGHT},
"system_disk": {
"size": "61_440",
"category": "cloud_efficiency"
Expand Down Expand Up @@ -278,7 +273,6 @@ var _ = Describe("integration:vm", func() {
P("INTERNAL_NETMASK", internalNetmask).
P("INTERNAL_GW", internalGw).
P("SLB_ID", slbId).
P("SLB_WEIGHT", slbWeight).
ToBytes()

r := caller.Run(in)
Expand Down