Skip to content

Commit

Permalink
fix(gcp): disk tag with server
Browse files Browse the repository at this point in the history
  • Loading branch information
ioito committed Sep 18, 2024
1 parent eb79f61 commit 6f0f314
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions pkg/multicloud/google/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,13 +569,20 @@ func (region *SRegion) _createVM(zone string, desc *cloudprovider.SManagedVMCrea
name = pinyinutils.Text2Pinyin(name)
return strings.ToLower(name)
}

labels := map[string]string{}
for k, v := range desc.Tags {
labels[encode.EncodeGoogleLabel(k)] = encode.EncodeGoogleLabel(v)
}

disks = append(disks, map[string]interface{}{
"boot": true,
"initializeParams": map[string]interface{}{
"diskName": nameConv(desc.SysDisk.Name),
"sourceImage": desc.ExternalImageId,
"diskSizeGb": desc.SysDisk.SizeGB,
"diskType": fmt.Sprintf("zones/%s/diskTypes/%s", zone, desc.SysDisk.StorageType),
"labels": labels,
},
"autoDelete": true,
})
Expand All @@ -589,6 +596,7 @@ func (region *SRegion) _createVM(zone string, desc *cloudprovider.SManagedVMCrea
"diskName": nameConv(disk.Name),
"diskSizeGb": disk.SizeGB,
"diskType": fmt.Sprintf("zones/%s/diskTypes/%s", zone, disk.StorageType),
"labels": labels,
},
"autoDelete": true,
})
Expand All @@ -610,11 +618,6 @@ func (region *SRegion) _createVM(zone string, desc *cloudprovider.SManagedVMCrea
"disks": disks,
}

labels := map[string]string{}
for k, v := range desc.Tags {
labels[encode.EncodeGoogleLabel(k)] = encode.EncodeGoogleLabel(v)
}

if len(labels) > 0 {
params["labels"] = labels
}
Expand Down Expand Up @@ -642,24 +645,6 @@ func (region *SRegion) _createVM(zone string, desc *cloudprovider.SManagedVMCrea
},
}
}
//if len(serviceAccounts) > 0 {
// params["serviceAccounts"] = []struct {
// Email string
// Scopes []string
// }{
// {
// Email: serviceAccounts[0],
// Scopes: []string{
// "https://www.googleapis.com/auth/devstorage.read_only",
// "https://www.googleapis.com/auth/logging.write",
// "https://www.googleapis.com/auth/monitoring.write",
// "https://www.googleapis.com/auth/servicecontrol",
// "https://www.googleapis.com/auth/service.management.readonly",
// "https://www.googleapis.com/auth/trace.append",
// },
// },
// }
//}
log.Debugf("create google instance params: %s", jsonutils.Marshal(params).String())
instance := &SInstance{}
resource := fmt.Sprintf("zones/%s/instances", zone)
Expand Down

0 comments on commit 6f0f314

Please sign in to comment.