Skip to content

Commit

Permalink
upgrades the alibaba cloud sdk verison and go version to 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaozhu36 committed Aug 1, 2024
1 parent f2cf23b commit 2d93b7e
Show file tree
Hide file tree
Showing 944 changed files with 34,071 additions and 7,591 deletions.
2 changes: 1 addition & 1 deletion ci/assets/terraform/terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ terraform {
}
required_providers {
alicloud = {
source = "aliyun/alicloud"
source = "aliyun/alicloud"
version = "1.193.0"
}
}
Expand Down
2 changes: 1 addition & 1 deletion ci/tasks/build-candidate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pushd bosh-cpi-src
do
if [[ ${LINE//:/} =~ ^go[0-9.]+linux-[a-z0-9]+.tar.gz$ ]]; then
gorelease=${LINE//:/}
echo "Downloading ${gorelease}..."
echo "Downloading ${gorelease} with url:https://dl.google.com/go/${gorelease}..."
wget -q https://dl.google.com/go/${gorelease}
echo "Adding ${gorelease} to blob..."
bosh add-blob ./${gorelease} ${gorelease}
Expand Down
3 changes: 0 additions & 3 deletions config/blobs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
go1.20.10.linux-amd64.tar.gz:
size: 100663296
sha: sha256:80d34f1fd74e382d86c2d6102e0e60d4318461a7c2f457ec1efc4042752d4248
go1.21.4.linux-amd64.tar.gz:
size: 66615271
sha: sha256:73cac0215254d0c7d1241fa40837851f3b9a8a742d0b54714cbdfb3feaf8f0af
1 change: 1 addition & 0 deletions src/bosh-alicloud-cpi/action/create_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type InstanceProps struct {
NlbServerGroupWeight json.Number `json:"nlb_server_group_weight"`
NlbServerGroupPort json.Number `json:"nlb_server_group_port"`
NlbServerGroupIds []string `json:"nlb_server_group_ids"`
NlbServerGroups []NlbServerGroupProps `json:"nlb_server_groups"`
Password string `json:"password"`
KeyPairName string `json:"key_pair_name"`
SecurityGroupIds []string `json:"security_group_ids"`
Expand Down
5 changes: 5 additions & 0 deletions src/bosh-alicloud-cpi/action/networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ type NetworkProps struct {
VSwitchId string `json:"vswitch_id"`
InternetChargeType string `json:"internet_charge_type,omitempty"`
}
type NlbServerGroupProps struct {
ServerGroupId string `json:"server_group_id"`
Port []string `json:"port"`
Weight string `json:"weight"`
}

func NewNetworks(args apiv1.Networks) (Networks, error) {
r := Networks{networks: args}
Expand Down
17 changes: 0 additions & 17 deletions src/bosh-alicloud-cpi/alicloud/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import (
"strings"
"time"

rpc "github.com/alibabacloud-go/tea-rpc/client"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
credential "github.com/aliyun/credentials-go/credentials"

"github.com/google/uuid"
)

Expand Down Expand Up @@ -99,20 +96,6 @@ func getSdkConfig() *sdk.Config {
WithScheme("HTTPS")
}

func (c *Config) getTeaDslSdkConfig(stsSupported bool) (config rpc.Config, err error) {
config.SetRegionId(c.OpenApi.Region)
config.SetUserAgent(fmt.Sprintf("%s/%s", BoshCPI, BoshCPIVersion))
credential, err := credential.NewCredential(c.getCredentialConfig(stsSupported))
config.SetCredential(credential).
SetRegionId(c.OpenApi.Region).
SetProtocol("HTTPS").
SetReadTimeout(60000).
SetConnectTimeout(60000).
SetMaxIdleConns(500)

return
}

func getTransport() *http.Transport {
handshakeTimeout, err := strconv.Atoi(os.Getenv("TLSHandshakeTimeout"))
if err != nil {
Expand Down
58 changes: 29 additions & 29 deletions src/bosh-alicloud-cpi/alicloud/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"bosh-alicloud-cpi/registry"
"encoding/json"
"fmt"
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
"github.com/alibabacloud-go/tea/tea"
credential "github.com/aliyun/credentials-go/credentials"
"os"
"strings"
"sync"
"time"

rpc "github.com/alibabacloud-go/tea-rpc/client"
credential "github.com/aliyun/credentials-go/credentials"

bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
boshsys "github.com/cloudfoundry/bosh-utils/system"
Expand Down Expand Up @@ -200,7 +200,7 @@ func (c Config) NewEcsClient(region string) (*ecs.Client, error) {
return client, nil
}

func (c Config) EcsTeaClient(region string) (*rpc.Client, error) {
func (c Config) EcsTeaClient(region string) (*openapi.Client, error) {
var mutex = sync.RWMutex{}
mutex.Lock()
defer mutex.Unlock()
Expand All @@ -220,18 +220,9 @@ func (c Config) EcsTeaClient(region string) (*rpc.Client, error) {
}
}

sdkConfig, err := c.getTeaDslSdkConfig(true)
if err != nil {
return nil, bosherr.WrapErrorf(err, "Initiating ECS Client in '%s' got an error.", c.OpenApi.GetRegion(region))
}
sdkConfig.SetEndpoint(endpoint).SetReadTimeout(60000)

conn, err := rpc.NewClient(&sdkConfig)
if err != nil {
return nil, bosherr.WrapErrorf(err, "Initiating ECS Client in '%s' got an error.", c.OpenApi.GetRegion(region))
}

return conn, nil
config := c.getTeaSdkConfig()
config.SetEndpoint(endpoint)
return openapi.NewClient(config)
}

func (c Config) NewSlbClient(region string) (*slb.Client, error) {
Expand All @@ -254,7 +245,7 @@ func (c Config) NewSlbClient(region string) (*slb.Client, error) {
return client, nil
}

func (c Config) NlbTeaClient(region string) (*rpc.Client, error) {
func (c Config) NlbTeaClient(region string) (*openapi.Client, error) {
var mutex = sync.RWMutex{}
mutex.Lock()
defer mutex.Unlock()
Expand All @@ -271,20 +262,29 @@ func (c Config) NlbTeaClient(region string) (*rpc.Client, error) {
endpoint = fmt.Sprintf("nlb.%s.aliyuncs.com", region)
}

sdkConfig, err := c.getTeaDslSdkConfig(true)
if err != nil {
return nil, bosherr.WrapErrorf(err, "Initiating NLB Client in '%s' got an error.", c.OpenApi.GetRegion(region))
}
sdkConfig.SetEndpoint(endpoint).SetReadTimeout(60000)

conn, err := rpc.NewClient(&sdkConfig)
if err != nil {
return nil, bosherr.WrapErrorf(err, "Initiating NLB Client in '%s' got an error.", c.OpenApi.GetRegion(region))
}

return conn, nil
config := c.getTeaSdkConfig()
config.SetEndpoint(endpoint)
return openapi.NewClient(config)
}

func (c Config) getTeaSdkConfig() *openapi.Config {
config := &openapi.Config{
RegionId: tea.String(c.OpenApi.Region),
AccessKeyId: tea.String(c.OpenApi.AccessKeyId),
AccessKeySecret: tea.String(c.OpenApi.AccessKeySecret),
ReadTimeout: tea.Int(60000),
UserAgent: tea.String(fmt.Sprintf("%s/%s", BoshCPI, BoshCPIVersion)),
MaxIdleConns: tea.Int(500),
Protocol: tea.String("HTTPS"),
HttpProxy: tea.String(os.Getenv("HTTP_PROXY")),
HttpsProxy: tea.String(os.Getenv("HTTPS_PROXY")),
NoProxy: tea.String(os.Getenv("NO_PROXY")),
}
if c.OpenApi.SecurityToken != "" {
config.SecurityToken = tea.String(c.OpenApi.SecurityToken)
}
return config
}
func (c Config) GetRegistryClient(logger boshlog.Logger) RegistryManager {
//if !c.Registry.IsEmpty() {
// return c.GetHttpRegistryClient(logger)
Expand Down
36 changes: 28 additions & 8 deletions src/bosh-alicloud-cpi/alicloud/disk_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
package alicloud

import (
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
openapiutil "github.com/alibabacloud-go/openapi-util/service"
"github.com/alibabacloud-go/tea/tea"
"strings"

util "github.com/alibabacloud-go/tea-utils/service"
util "github.com/alibabacloud-go/tea-utils/v2/service"
"github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"

"encoding/json"
Expand Down Expand Up @@ -387,28 +390,45 @@ func (a DiskManagerImpl) GetDiskPath(path, diskId, instanceType string, category
invoker.AddCatcher(CreateInstanceCatcher_IpUsed2)

action := "DescribeInstanceTypes"
request := map[string]interface{}{
queries := map[string]interface{}{
"InstanceTypes.1": instanceType,
"NvmeSupport": "required",
}
runtime := util.RuntimeOptions{}
params := &openapi.Params{
Action: tea.String(action),
Version: tea.String("2014-05-26"),
Protocol: tea.String("HTTPS"),
Method: tea.String("POST"),
AuthType: tea.String("AK"),
Style: tea.String("RPC"),
Pathname: tea.String("/"),
ReqBodyType: tea.String("json"),
BodyType: tea.String("json"),
}
runtime := &util.RuntimeOptions{}
runtime.SetAutoretry(true)
request := &openapi.OpenApiRequest{
Query: openapiutil.Query(queries),
}
err = invoker.Run(func() error {
resp, e := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2014-05-26"), StringPointer("AK"), nil, request, &runtime)
resp, e := conn.CallApi(params, request, runtime)
if e != nil {
return e
}
if resp["InstanceTypes"] != nil &&
resp["InstanceTypes"].(map[string]interface{})["InstanceType"] != nil &&
len(resp["InstanceTypes"].(map[string]interface{})["InstanceType"].([]interface{})) > 0 {
if resp["body"] == nil {
return fmt.Errorf("invoking DescribeInstanceTypes got an empty response: %v", resp)
}
instanceTypes := resp["body"].(map[string]interface{})["InstanceTypes"]
if instanceTypes != nil && instanceTypes.(map[string]interface{})["InstanceType"] != nil &&
len(instanceTypes.(map[string]interface{})["InstanceType"].([]interface{})) > 0 {
amendPath = "/dev/disk/by-id/nvme-Alibaba_Cloud_Elastic_Block_Storage_" + strings.Split(diskId, "-")[1]
} else {
amendPath = "/dev/disk/by-id/virtio-" + strings.Split(diskId, "-")[1]
}
return e
})
if err != nil {
a.log(action, err, request, "")
a.log(action, err, queries, "")
}

return amendPath
Expand Down
31 changes: 24 additions & 7 deletions src/bosh-alicloud-cpi/alicloud/instance_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ package alicloud
import (
"encoding/json"
"fmt"
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
openapiutil "github.com/alibabacloud-go/openapi-util/service"
"github.com/alibabacloud-go/tea/tea"
"strings"
"time"

"github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"

util "github.com/alibabacloud-go/tea-utils/service"
util "github.com/alibabacloud-go/tea-utils/v2/service"

"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
Expand Down Expand Up @@ -103,7 +106,7 @@ func (a InstanceManagerImpl) GetInstance(cid string) (inst *ecs.Instance, err er
return
}

func (a InstanceManagerImpl) CreateInstance(region string, request map[string]interface{}) (string, error) {
func (a InstanceManagerImpl) CreateInstance(region string, queries map[string]interface{}) (string, error) {
conn, err := a.config.EcsTeaClient(region)
if err != nil {
return "", err
Expand All @@ -116,20 +119,34 @@ func (a InstanceManagerImpl) CreateInstance(region string, request map[string]in
invoker.AddCatcher(CreateInstanceCatcher_IpUsed2)

action := "CreateInstance"
request["ClientToken"] = buildClientToken(action)
runtime := util.RuntimeOptions{}
params := &openapi.Params{
Action: tea.String(action),
Version: tea.String("2014-05-26"),
Protocol: tea.String("HTTPS"),
Method: tea.String("POST"),
AuthType: tea.String("AK"),
Style: tea.String("RPC"),
Pathname: tea.String("/"),
ReqBodyType: tea.String("json"),
BodyType: tea.String("json"),
}
queries["ClientToken"] = buildClientToken(action)
runtime := &util.RuntimeOptions{}
runtime.SetAutoretry(true)
request := &openapi.OpenApiRequest{
Query: openapiutil.Query(queries),
}
var cid string
err = invoker.Run(func() error {
resp, e := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2014-05-26"), StringPointer("AK"), nil, request, &runtime)
resp, e := conn.CallApi(params, request, runtime)
if e != nil {
if IsExceptedErrors(e, []string{"IdempotentFailed"}) {
// If the error is not 5xx, the client token should be updated
request["ClientToken"] = buildClientToken(action)
queries["ClientToken"] = buildClientToken(action)
}
return e
}
cid = fmt.Sprint(resp["InstanceId"])
cid = fmt.Sprint(resp["body"].(map[string]interface{})["InstanceId"])
return e
})
return cid, err
Expand Down
43 changes: 32 additions & 11 deletions src/bosh-alicloud-cpi/alicloud/network_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ package alicloud
import (
"encoding/json"
"fmt"
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
openapiutil "github.com/alibabacloud-go/openapi-util/service"
util "github.com/alibabacloud-go/tea-utils/v2/service"
"github.com/alibabacloud-go/tea/tea"
"strings"

util "github.com/alibabacloud-go/tea-utils/service"

"github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors"
"github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
"github.com/aliyun/alibaba-cloud-sdk-go/services/slb"
Expand All @@ -18,7 +20,7 @@ import (
)

type NetworkManager interface {
DescribeEip(region, eip string) (ecs.EipAddressInDescribeEipAddresses, error)
DescribeEip(region, eip string) (ecs.EipAddress, error)
BindEip(region, instanceId, eip string) error
WaitForEipStatus(region, eip string, toStatus EipStatus) error

Expand Down Expand Up @@ -60,7 +62,7 @@ func (a NetworkManagerImpl) log(action string, err error, args interface{}, resu
}
}

func (a NetworkManagerImpl) DescribeEip(region, eip string) (eipAddress ecs.EipAddressInDescribeEipAddresses, err error) {
func (a NetworkManagerImpl) DescribeEip(region, eip string) (eipAddress ecs.EipAddress, err error) {
client, err := a.config.NewEcsClient(region)
if err != nil {
return
Expand Down Expand Up @@ -177,24 +179,43 @@ func (a NetworkManagerImpl) BindNlbServerGroup(region, instanceId string, nlbSer
if err != nil {
return err
}
request := map[string]interface{}{
action := "AddServersToServerGroup"
params := &openapi.Params{
Action: tea.String(action),
Version: tea.String("2022-04-30"),
Protocol: tea.String("HTTPS"),
Method: tea.String("POST"),
AuthType: tea.String("AK"),
Style: tea.String("RPC"),
Pathname: tea.String("/"),
ReqBodyType: tea.String("formData"),
BodyType: tea.String("json"),
}
queries := map[string]interface{}{
"Servers.1.Port": port,
"ServerGroupId": nlbServerGroupId,
"Servers.1.ServerId": instanceId,
"Servers.1.ServerType": "Ecs",
"ClientToken": buildClientToken("AddServersToServerGroup"),
"RegionId": tea.String(a.config.OpenApi.Region),
}
if weight != 0 {
request["Servers.1.Weight"] = weight
queries["Servers.1.Weight"] = weight
}
action := "AddServersToServerGroup"
queries["ClientToken"] = buildClientToken(action)
request := &openapi.OpenApiRequest{
Query: openapiutil.Query(queries),
}
runtime := &util.RuntimeOptions{}
runtime.SetAutoretry(true)
invoker := NewInvoker()
invoker.AddCatcher(NlbBindServerCatcher_Conflict_Lock)
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)

err = invoker.Run(func() error {
_, e := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2022-04-30"), StringPointer("AK"), nil, request, &runtime)
a.logger.Error("NetworkManager", "BindNlbServerGroup %s to %s failed %v. Retry...", instanceId, nlbServerGroupId, err)
_, e := conn.CallApi(params, request, runtime)
if e != nil {
a.logger.Error("NetworkManager", "BindNlbServerGroup %s to %s failed %v. Retry...", instanceId, nlbServerGroupId, err)
}
return e
})
return err
Expand Down
Loading

0 comments on commit 2d93b7e

Please sign in to comment.