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 DeleteWithInstance not working bug #46

Merged
merged 1 commit into from
Dec 25, 2018
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ IMPROVEMENTS

BUG FIXES

- Fix DeleteWithInstance not working bug ([#46](https://github.com/cloudfoundry-incubator/bosh-alicloud-cpi-release/pull/46))
- Fix upload stemcell bug and upgrade oss sdk version ([#42](https://github.com/cloudfoundry-incubator/bosh-alicloud-cpi-release/pull/42))

## [r19]
Expand Down
4 changes: 2 additions & 2 deletions src/bosh-alicloud-cpi/action/create_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ func (a CreateDiskMethod) CreateDisk(size int, props apiv1.DiskCloudProps, vmCid
args.Size = requests.NewInteger(disk.GetSizeGB())
args.DiskCategory = string(disk.GetCategory())
encrypt := disk.Encrypted
if &encrypt == nil {
if encrypt == nil {
encrypt = a.Config.OpenApi.Encrypted
}
args.Encrypted = requests.NewBoolean(encrypt)
args.Encrypted = requests.NewBoolean(*encrypt)
diskCid, err := a.disks.CreateDisk(inst.RegionId, args)

if err != nil {
Expand Down
17 changes: 11 additions & 6 deletions src/bosh-alicloud-cpi/action/disks.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ type Disks struct {
type DiskInfo struct {
SizeRaw interface{} `json:"size"`
Category string `json:"category"`
Encrypted bool `json:"encrypted"`
DeleteWithInstance bool `json:"delete_with_instance"`
Encrypted *bool `json:"encrypted,omitempty"`
DeleteWithInstance *bool `json:"delete_with_instance,omitempty"`
sizeGB int
path string
ecsCategory alicloud.DiskCategory
Expand Down Expand Up @@ -176,21 +176,26 @@ func (a DiskInfo) GetPath() string {
return a.path
}

func (a Disks) FillCreateInstanceArgs(golbalEncrypt bool, args *ecs.CreateInstanceRequest) {
func (a Disks) FillCreateInstanceArgs(golbalEncrypt *bool, args *ecs.CreateInstanceRequest) {
args.SystemDiskSize = requests.NewInteger(a.SystemDisk.sizeGB)
args.SystemDiskCategory = string(a.SystemDisk.ecsCategory)

encrypt := a.EphemeralDisk.Encrypted
if &encrypt == nil {
if encrypt == nil {
encrypt = golbalEncrypt
}
deleteWithInstance := a.EphemeralDisk.DeleteWithInstance
if deleteWithInstance == nil {
deleteWithInstance = new(bool)
*deleteWithInstance = true
}
if a.EphemeralDisk.sizeGB > 0 {
var disks []ecs.CreateInstanceDataDisk
disks = append(disks, ecs.CreateInstanceDataDisk{
Size: strconv.Itoa(a.EphemeralDisk.sizeGB),
Category: string(a.EphemeralDisk.GetCategory()),
Encrypted: strconv.FormatBool(encrypt),
DeleteWithInstance: strconv.FormatBool(a.EphemeralDisk.DeleteWithInstance),
Encrypted: strconv.FormatBool(*encrypt),
DeleteWithInstance: strconv.FormatBool(*deleteWithInstance),
})
args.DataDisk = &disks
}
Expand Down
11 changes: 9 additions & 2 deletions src/bosh-alicloud-cpi/alicloud/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type OpenApi struct {
AccessKeyId string `json:"access_key_id"`
AccessKeySecret string `json:"access_key_secret"`
SecurityToken string `json:"security_token"`
Encrypted bool `json:"encrypted"`
Encrypted *bool `json:"encrypted,omitempty"`
EcsEndpoint string `json:"ecs_endpoint"`
SlbEndpoint string `json:"slb_endpoint"`
OssEndpoint string `json:"oss_endpoint"`
Expand Down Expand Up @@ -221,7 +221,14 @@ func (c Config) NewOssClient(region string) (*oss.Client, error) {
endpointItem, _ := c.describeEndpointForService("oss")
if endpointItem != nil && len(endpointItem.Endpoint) > 0 {
if len(endpointItem.Protocols.Protocols) > 0 {
schma = endpointItem.Protocols.Protocols[0]
// HTTP or HTTPS
schma = strings.ToLower(endpointItem.Protocols.Protocols[0])
for _, p := range endpointItem.Protocols.Protocols {
if strings.ToLower(p) == "https" {
schma = strings.ToLower(p)
break
}
}
}
endpoint = endpointItem.Endpoint
} else {
Expand Down