Skip to content

Commit

Permalink
Merge pull request #31 from haoshuwei/support-use-internal-oss-endpoint
Browse files Browse the repository at this point in the history
support use internal oss-endpoint
  • Loading branch information
haoshuwei authored Jan 13, 2020
2 parents 20a8d2d + d975181 commit b0af683
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
33 changes: 32 additions & 1 deletion velero-plugin-for-alibabacloud/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const (
kindKey = "kind"
persistentVolumeKey = "PersistentVolume"
persistentVolumeClaimKey = "PersistentVolumeClaim"
networkTypeConfigKey = "network"
networkTypeAccelerate = "accelerate"
networkTypeInternal = "internal"
)

// load environment vars from $ALIBABA_CLOUD_CREDENTIALS_FILE, if it exists
Expand Down Expand Up @@ -49,8 +52,36 @@ func getMetaData(resource string) (string, error) {
return string(body), nil
}

// getOssEndpoint return oss endpoint in format "oss-%s.aliyuncs.com"
// getOssEndpoint:
// return oss public endpoint in format "oss-%s.aliyuncs.com"
// return oss accelerate endpoint in format "oss-accelerate.aliyuncs.com"
// return oss internal endpoint in format "oss-%s-internal.aliyuncs.com"
func getOssEndpoint(config map[string]string) string {
if networkType := config[networkTypeConfigKey]; networkType != "" {
switch networkType {
case networkTypeInternal:
if value := config[regionConfigKey]; value != "" {
return fmt.Sprintf("oss-%s-internal.aliyuncs.com", value)
} else {
if value, err := getMetaData(metadataRegionKey); err != nil || value == "" {
// set default region
return "oss-cn-hangzhou-internal.aliyuncs.com"
}
}
case networkTypeAccelerate:
return "oss-accelerate.aliyuncs.com"
default:
if value := config[regionConfigKey]; value != "" {
return fmt.Sprintf("oss-%s.aliyuncs.com", value)
} else {
if value, err := getMetaData(metadataRegionKey); err != nil || value == "" {
// set default region
return "oss-cn-hangzhou.aliyuncs.com"
}
}
}
}

if value := config[regionConfigKey]; value == "" {
if value, err := getMetaData(metadataRegionKey); err != nil || value == "" {
// set default region
Expand Down
2 changes: 1 addition & 1 deletion velero-plugin-for-alibabacloud/object_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (o *ObjectStore) getBucket(bucket string) (ossBucket, error) {

// Init init oss client with os envs
func (o *ObjectStore) Init(config map[string]string) error {
if err := veleroplugin.ValidateObjectStoreConfigKeys(config, regionConfigKey); err != nil {
if err := veleroplugin.ValidateObjectStoreConfigKeys(config, regionConfigKey, networkTypeConfigKey); err != nil {
return err
}

Expand Down

0 comments on commit b0af683

Please sign in to comment.