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

fix(nas): do not set vpc endpoint for all regions #1002

Merged
merged 1 commit into from
Mar 21, 2024
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
8 changes: 6 additions & 2 deletions pkg/nas/cloud/nas_client_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ import (
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/utils"
)

func init() {
for region := range regionsCanUseVpcEndpoint {
_ = aliyunep.AddEndpointMapping(region, "Nas", fmt.Sprintf("nas-vpc.%s.aliyuncs.com", region))
}
}

func newNasClientV1(region string) (*nassdk.Client, error) {
if ep := os.Getenv("NAS_ENDPOINT"); ep != "" {
_ = aliyunep.AddEndpointMapping(region, "Nas", ep)
} else {
_ = aliyunep.AddEndpointMapping(region, "Nas", fmt.Sprintf("nas-vpc.%s.aliyuncs.com", region))
tydra-wang marked this conversation as resolved.
Show resolved Hide resolved
}

ac := utils.GetAccessControl()
Expand Down
2 changes: 1 addition & 1 deletion pkg/nas/cloud/nas_client_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func newNasClientV2(region string) (*sdk.Client, error) {
// set endpoint
ep := os.Getenv("NAS_ENDPOINT")
if ep == "" {
ep = fmt.Sprintf("nas-vpc.%s.aliyuncs.com", region)
ep = GetEndpointForRegion(region)
tydra-wang marked this conversation as resolved.
Show resolved Hide resolved
}
config = config.SetEndpoint(ep)
// set protocol
Expand Down
52 changes: 51 additions & 1 deletion pkg/nas/cloud/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package cloud

import "strings"
import (
"fmt"
"strings"

"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/util/sets"
)

func GetFilesystemTypeByMountTargetDomain(domain string) string {
switch {
Expand All @@ -14,3 +20,47 @@ func GetFilesystemTypeByMountTargetDomain(domain string) string {
return ""
}
}

var regionsCanUseVpcEndpoint = sets.NewString(
tydra-wang marked this conversation as resolved.
Show resolved Hide resolved
"cn-hangzhou",
"cn-zhangjiakou",
"cn-shanghai",
"cn-hongkong",
"us-west-1",
"eu-west-1",
"ap-southeast-5",
"cn-huhehaote",
"cn-beijing",
"cn-shenzhen",
"eu-central-1",
"ap-southeast-3",
"ap-south-1",
"ap-southeast-2",
"cn-north-2-gov-1",
"ap-southeast-1",
"us-east-1",
"cn-chengdu",
"cn-wulanchabu",
"cn-guangzhou",
"ap-northeast-1",
"cn-heyuan-acdr-1",
"cn-beijing-finance-1",
"ap-southeast-7",
"cn-heyuan",
"me-central-1",
"ap-northeast-2",
"cn-hangzhou-finance",
"cn-qingdao",
"cn-shanghai-finance-1",
"cn-shenzhen-finance-1",
"ap-southeast-6",
)

func GetEndpointForRegion(region string) string {
if regionsCanUseVpcEndpoint.Has(region) {
return fmt.Sprintf("nas-vpc.%s.aliyuncs.com", region)
}
endpoint := fmt.Sprintf("nas.%s.aliyuncs.com", region)
logrus.Warnf("region %s do not support vpc endpoint, use public network endpoint: %s", region, endpoint)
return endpoint
}