Skip to content

Commit 0327e11

Browse files
committed
add support for specifying iops and thoroughput when using hyperdisks
1 parent e0629cc commit 0327e11

File tree

3 files changed

+52
-34
lines changed

3 files changed

+52
-34
lines changed

pkg/model/gcemodel/autoscalinggroup.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,16 @@ func (b *AutoscalingGroupModelBuilder) buildInstanceTemplate(c *fi.CloudupModelB
9494
}
9595

9696
t := &gcetasks.InstanceTemplate{
97-
Name: s(name),
98-
NamePrefix: s(namePrefix),
99-
Lifecycle: b.Lifecycle,
100-
Network: network,
101-
MachineType: s(ig.Spec.MachineType),
102-
BootDiskType: s(volumeType),
103-
BootDiskSizeGB: i64(int64(volumeSize)),
104-
BootDiskImage: s(ig.Spec.Image),
97+
Name: s(name),
98+
NamePrefix: s(namePrefix),
99+
Lifecycle: b.Lifecycle,
100+
Network: network,
101+
MachineType: s(ig.Spec.MachineType),
102+
BootDiskType: s(volumeType),
103+
BootDiskSizeGB: i64(int64(volumeSize)),
104+
BootDiskImage: s(ig.Spec.Image),
105+
BootDiskIOPS: fi.PtrTo(int64(fi.ValueOf(ig.Spec.RootVolume.IOPS))),
106+
BootDiskThroughput: fi.PtrTo(int64(fi.ValueOf(ig.Spec.RootVolume.Throughput))),
105107

106108
Preemptible: fi.PtrTo(fi.ValueOf(ig.Spec.GCPProvisioningModel) == "SPOT"),
107109
GCPProvisioningModel: ig.Spec.GCPProvisioningModel,

upup/pkg/fi/cloudup/gcetasks/disk.go

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ type Disk struct {
3535
Name *string
3636
Lifecycle fi.Lifecycle
3737

38-
VolumeType *string
39-
SizeGB *int64
40-
Zone *string
41-
Labels map[string]string
38+
VolumeType *string
39+
SizeGB *int64
40+
VolumeIops *int64
41+
VolumeThroughput *int64
42+
Zone *string
43+
Labels map[string]string
4244
}
4345

4446
var _ fi.CompareWithID = &Disk{}
@@ -63,6 +65,8 @@ func (e *Disk) Find(c *fi.CloudupContext) (*Disk, error) {
6365
actual.VolumeType = fi.PtrTo(gce.LastComponent(r.Type))
6466
actual.Zone = fi.PtrTo(gce.LastComponent(r.Zone))
6567
actual.SizeGB = &r.SizeGb
68+
actual.VolumeIops = &r.ProvisionedIops
69+
actual.VolumeThroughput = &r.ProvisionedThroughput
6670

6771
actual.Labels = r.Labels
6872

@@ -86,7 +90,7 @@ func (e *Disk) Run(c *fi.CloudupContext) error {
8690
return fi.CloudupDefaultDeltaRunMethod(e, c)
8791
}
8892

89-
func (_ *Disk) CheckChanges(a, e, changes *Disk) error {
93+
func (*Disk) CheckChanges(a, e, changes *Disk) error {
9094
if a != nil {
9195
if changes.SizeGB != nil {
9296
return fi.CannotChangeField("SizeGB")
@@ -105,17 +109,19 @@ func (_ *Disk) CheckChanges(a, e, changes *Disk) error {
105109
return nil
106110
}
107111

108-
func (_ *Disk) RenderGCE(t *gce.GCEAPITarget, a, e, changes *Disk) error {
112+
func (*Disk) RenderGCE(t *gce.GCEAPITarget, a, e, changes *Disk) error {
109113
cloud := t.Cloud
110114
typeURL := fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/zones/%s/diskTypes/%s",
111115
cloud.Project(),
112116
*e.Zone,
113117
*e.VolumeType)
114118

115119
disk := &compute.Disk{
116-
Name: *e.Name,
117-
SizeGb: *e.SizeGB,
118-
Type: typeURL,
120+
Name: *e.Name,
121+
SizeGb: *e.SizeGB,
122+
Type: typeURL,
123+
ProvisionedIops: *e.VolumeIops,
124+
ProvisionedThroughput: *e.VolumeThroughput,
119125
}
120126

121127
if a == nil {
@@ -164,26 +170,30 @@ func (_ *Disk) RenderGCE(t *gce.GCEAPITarget, a, e, changes *Disk) error {
164170
}
165171

166172
type terraformDisk struct {
167-
Name *string `cty:"name"`
168-
VolumeType *string `cty:"type"`
169-
SizeGB *int64 `cty:"size"`
170-
Zone *string `cty:"zone"`
171-
Labels map[string]string `cty:"labels"`
173+
Name *string `cty:"name"`
174+
VolumeType *string `cty:"type"`
175+
SizeGB *int64 `cty:"size"`
176+
ProvisionedIops *int64 `cty:"provisioned_iops"`
177+
ProvisionedThroughput *int64 `cty:"provisioned_throughput"`
178+
Zone *string `cty:"zone"`
179+
Labels map[string]string `cty:"labels"`
172180
}
173181

174-
func (_ *Disk) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *Disk) error {
182+
func (*Disk) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *Disk) error {
175183
cloud := t.Cloud.(gce.GCECloud)
176184

177185
labels := make(map[string]string)
178186
maps.Copy(labels, cloud.Labels())
179187
maps.Copy(labels, e.Labels)
180188

181189
tf := &terraformDisk{
182-
Name: e.Name,
183-
VolumeType: e.VolumeType,
184-
SizeGB: e.SizeGB,
185-
Zone: e.Zone,
186-
Labels: labels,
190+
Name: e.Name,
191+
VolumeType: e.VolumeType,
192+
SizeGB: e.SizeGB,
193+
ProvisionedIops: e.VolumeIops,
194+
ProvisionedThroughput: e.VolumeThroughput,
195+
Zone: e.Zone,
196+
Labels: labels,
187197
}
188198
return t.RenderResource("google_compute_disk", *e.Name, tf)
189199
}

upup/pkg/fi/cloudup/gcetasks/instancetemplate.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ type InstanceTemplate struct {
5757
Preemptible *bool
5858
GCPProvisioningModel *string
5959

60-
BootDiskImage *string
61-
BootDiskSizeGB *int64
62-
BootDiskType *string
60+
BootDiskImage *string
61+
BootDiskSizeGB *int64
62+
BootDiskType *string
63+
BootDiskIOPS *int64
64+
BootDiskThroughput *int64
6365

6466
CanIPForward *bool
6567
Subnet *Subnet
@@ -133,6 +135,8 @@ func (e *InstanceTemplate) Find(c *fi.CloudupContext) (*InstanceTemplate, error)
133135
actual.BootDiskImage = fi.PtrTo(bootDiskImage)
134136
actual.BootDiskType = &p.Disks[0].InitializeParams.DiskType
135137
actual.BootDiskSizeGB = &p.Disks[0].InitializeParams.DiskSizeGb
138+
actual.BootDiskIOPS = &p.Disks[0].InitializeParams.ProvisionedIops
139+
actual.BootDiskThroughput = &p.Disks[0].InitializeParams.ProvisionedThroughput
136140

137141
if p.Scheduling != nil {
138142
actual.Preemptible = &p.Scheduling.Preemptible
@@ -279,9 +283,11 @@ func (e *InstanceTemplate) mapToGCE(project string, region string) (*compute.Ins
279283
disks = append(disks, &compute.AttachedDisk{
280284
Kind: "compute#attachedDisk",
281285
InitializeParams: &compute.AttachedDiskInitializeParams{
282-
SourceImage: BuildImageURL(project, *e.BootDiskImage),
283-
DiskSizeGb: *e.BootDiskSizeGB,
284-
DiskType: *e.BootDiskType,
286+
SourceImage: BuildImageURL(project, *e.BootDiskImage),
287+
DiskSizeGb: *e.BootDiskSizeGB,
288+
DiskType: *e.BootDiskType,
289+
ProvisionedIops: *e.BootDiskIOPS,
290+
ProvisionedThroughput: *e.BootDiskThroughput,
285291
},
286292
Boot: true,
287293
DeviceName: "persistent-disks-0",

0 commit comments

Comments
 (0)