Skip to content

Commit c7fb5f1

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

File tree

5 files changed

+154
-80
lines changed

5 files changed

+154
-80
lines changed

pkg/model/gcemodel/autoscalinggroup.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,13 @@ func (b *AutoscalingGroupModelBuilder) buildInstanceTemplate(c *fi.CloudupModelB
6565
{
6666
var volumeSize int32
6767
var volumeType string
68+
var volumeIops int32
69+
var volumeThroughput int32
6870
if ig.Spec.RootVolume != nil {
6971
volumeSize = fi.ValueOf(ig.Spec.RootVolume.Size)
7072
volumeType = fi.ValueOf(ig.Spec.RootVolume.Type)
73+
volumeIops = fi.ValueOf(ig.Spec.RootVolume.IOPS)
74+
volumeThroughput = fi.ValueOf(ig.Spec.RootVolume.Throughput)
7175
}
7276
if volumeSize == 0 {
7377
volumeSize, err = defaults.DefaultInstanceGroupVolumeSize(ig.Spec.Role)
@@ -120,6 +124,13 @@ func (b *AutoscalingGroupModelBuilder) buildInstanceTemplate(c *fi.CloudupModelB
120124
},
121125
}
122126

127+
if volumeIops > 0 {
128+
t.BootDiskIOPS = i64(int64(volumeIops))
129+
}
130+
if volumeThroughput > 0 {
131+
t.BootDiskThroughput = i64(int64(volumeThroughput))
132+
}
133+
123134
if startupScript != nil {
124135
if !fi.ValueOf(b.Cluster.Spec.CloudProvider.GCE.UseStartupScript) {
125136
// Use "user-data" instead of "startup-script", for compatibility with cloud-init

tests/integration/update_cluster/minimal_gce_plb/in-v1alpha2.yaml

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,50 @@ spec:
1616
cloudProvider: gce
1717
configBase: memfs://tests/minimal-gce-plb.example.com
1818
etcdClusters:
19-
- cpuRequest: 200m
20-
etcdMembers:
21-
- instanceGroup: master-us-test1-a
22-
name: a
23-
memoryRequest: 100Mi
24-
name: main
25-
- cpuRequest: 100m
26-
etcdMembers:
27-
- instanceGroup: master-us-test1-a
28-
name: a
29-
memoryRequest: 100Mi
30-
name: events
19+
- cpuRequest: 200m
20+
etcdMembers:
21+
- instanceGroup: master-us-test1-a
22+
name: a
23+
memoryRequest: 100Mi
24+
name: main
25+
volumeIops: 6000
26+
volumeSize: 120
27+
volumeThroughput: 1000
28+
type: hyperdisk-balanced
29+
- cpuRequest: 100m
30+
etcdMembers:
31+
- instanceGroup: master-us-test1-a
32+
name: a
33+
memoryRequest: 100Mi
34+
name: events
35+
type: hyperdisk-balanced
3136
cloudConfig:
3237
gceServiceAccount: default
3338
iam:
3439
legacy: false
3540
kubelet:
3641
anonymousAuth: false
3742
kubernetesApiAccess:
38-
- 0.0.0.0/0
39-
- ::/0
43+
- 0.0.0.0/0
44+
- ::/0
4045
kubernetesVersion: v1.32.0
4146
masterPublicName: api.minimal-gce-plb.example.com
4247
networking:
4348
cni: {}
4449
nonMasqueradeCIDR: 100.64.0.0/10
4550
project: testproject
4651
sshAccess:
47-
- 0.0.0.0/0
48-
- ::/0
52+
- 0.0.0.0/0
53+
- ::/0
4954
subnets:
50-
- name: us-test1
51-
region: us-test1
52-
type: Private
55+
- name: us-test1
56+
region: us-test1
57+
type: Private
5358
topology:
5459
dns:
5560
type: Public
5661

5762
---
58-
5963
apiVersion: kops.k8s.io/v1alpha2
6064
kind: InstanceGroup
6165
metadata:
@@ -65,17 +69,20 @@ metadata:
6569
name: master-us-test1-a
6670
spec:
6771
image: ubuntu-os-cloud/ubuntu-2004-focal-v20221018
68-
machineType: e2-medium
72+
machineType: c4-standard-4
73+
rootVolume:
74+
volumeIops: 6000
75+
volumeThroughput: 1000
76+
type: hyperdisk-balanced
6977
maxSize: 1
7078
minSize: 1
7179
role: Master
7280
subnets:
73-
- us-test1
81+
- us-test1
7482
zones:
75-
- us-test1-a
83+
- us-test1-a
7684

7785
---
78-
7986
apiVersion: kops.k8s.io/v1alpha2
8087
kind: InstanceGroup
8188
metadata:
@@ -85,11 +92,16 @@ metadata:
8592
name: nodes
8693
spec:
8794
image: ubuntu-os-cloud/ubuntu-2004-focal-v20221018
88-
machineType: e2-medium
95+
machineType: c4-standard-8
96+
rootVolume:
97+
size: 100
98+
volumeIops: 6000
99+
volumeThroughput: 1000
100+
type: hyperdisk-balanced
89101
maxSize: 2
90102
minSize: 2
91103
role: Node
92104
subnets:
93-
- us-test1
105+
- us-test1
94106
zones:
95-
- us-test1-a
107+
- us-test1-a

tests/integration/update_cluster/minimal_gce_plb/kubernetes.tf

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ resource "google_compute_disk" "a-etcd-events-minimal-gce-plb-example-com" {
189189
}
190190
name = "a-etcd-events-minimal-gce-plb-example-com"
191191
size = 20
192-
type = "pd-ssd"
192+
type = "hyperdisk-balanced"
193193
zone = "us-test1-a"
194194
}
195195

@@ -199,10 +199,12 @@ resource "google_compute_disk" "a-etcd-main-minimal-gce-plb-example-com" {
199199
"k8s-io-etcd-main" = "a-2fa"
200200
"k8s-io-role-master" = "master"
201201
}
202-
name = "a-etcd-main-minimal-gce-plb-example-com"
203-
size = 20
204-
type = "pd-ssd"
205-
zone = "us-test1-a"
202+
name = "a-etcd-main-minimal-gce-plb-example-com"
203+
size = 120
204+
type = "hyperdisk-balanced"
205+
provisioned_iops = 6000
206+
provisioned_throughput = 1000
207+
zone = "us-test1-a"
206208
}
207209

208210
resource "google_compute_firewall" "https-api-ipv6-minimal-gce-plb-example-com" {
@@ -492,17 +494,19 @@ resource "google_compute_instance_group_manager" "a-nodes-minimal-gce-plb-exampl
492494
resource "google_compute_instance_template" "master-us-test1-a-minimal-gce-plb-example-com" {
493495
can_ip_forward = true
494496
disk {
495-
auto_delete = true
496-
boot = true
497-
device_name = "persistent-disks-0"
498-
disk_name = ""
499-
disk_size_gb = 64
500-
disk_type = "pd-standard"
501-
interface = ""
502-
mode = "READ_WRITE"
503-
source = ""
504-
source_image = "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-2004-focal-v20221018"
505-
type = "PERSISTENT"
497+
auto_delete = true
498+
boot = true
499+
device_name = "persistent-disks-0"
500+
disk_name = ""
501+
disk_size_gb = 64
502+
disk_type = "hyperdisk-balanced"
503+
interface = ""
504+
mode = "READ_WRITE"
505+
provisioned_iops = 6000
506+
provisioned_throughput = 1000
507+
source = ""
508+
source_image = "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-2004-focal-v20221018"
509+
type = "PERSISTENT"
506510
}
507511
labels = {
508512
"k8s-io-cluster-name" = "minimal-gce-plb-example-com"
@@ -513,7 +517,7 @@ resource "google_compute_instance_template" "master-us-test1-a-minimal-gce-plb-e
513517
lifecycle {
514518
create_before_destroy = true
515519
}
516-
machine_type = "e2-medium"
520+
machine_type = "c4-standard-4"
517521
metadata = {
518522
"cluster-name" = "minimal-gce-plb.example.com"
519523
"kops-k8s-io-instance-group-name" = "master-us-test1-a"
@@ -542,17 +546,19 @@ resource "google_compute_instance_template" "master-us-test1-a-minimal-gce-plb-e
542546
resource "google_compute_instance_template" "nodes-minimal-gce-plb-example-com" {
543547
can_ip_forward = true
544548
disk {
545-
auto_delete = true
546-
boot = true
547-
device_name = "persistent-disks-0"
548-
disk_name = ""
549-
disk_size_gb = 128
550-
disk_type = "pd-standard"
551-
interface = ""
552-
mode = "READ_WRITE"
553-
source = ""
554-
source_image = "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-2004-focal-v20221018"
555-
type = "PERSISTENT"
549+
auto_delete = true
550+
boot = true
551+
device_name = "persistent-disks-0"
552+
disk_name = ""
553+
disk_size_gb = 100
554+
disk_type = "hyperdisk-balanced"
555+
interface = ""
556+
mode = "READ_WRITE"
557+
provisioned_iops = 6000
558+
provisioned_throughput = 1000
559+
source = ""
560+
source_image = "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-2004-focal-v20221018"
561+
type = "PERSISTENT"
556562
}
557563
labels = {
558564
"k8s-io-cluster-name" = "minimal-gce-plb-example-com"
@@ -562,7 +568,7 @@ resource "google_compute_instance_template" "nodes-minimal-gce-plb-example-com"
562568
lifecycle {
563569
create_before_destroy = true
564570
}
565-
machine_type = "e2-medium"
571+
machine_type = "c4-standard-8"
566572
metadata = {
567573
"cluster-name" = "minimal-gce-plb.example.com"
568574
"kops-k8s-io-instance-group-name" = "nodes"

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

Lines changed: 32 additions & 12 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,7 +109,7 @@ 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(),
@@ -118,6 +122,13 @@ func (_ *Disk) RenderGCE(t *gce.GCEAPITarget, a, e, changes *Disk) error {
118122
Type: typeURL,
119123
}
120124

125+
if e.VolumeIops != nil {
126+
disk.ProvisionedIops = *e.VolumeIops
127+
}
128+
if e.VolumeThroughput != nil {
129+
disk.ProvisionedThroughput = *e.VolumeThroughput
130+
}
131+
121132
if a == nil {
122133
op, err := cloud.Compute().Disks().Insert(t.Cloud.Project(), *e.Zone, disk)
123134
if err != nil {
@@ -164,14 +175,16 @@ func (_ *Disk) RenderGCE(t *gce.GCEAPITarget, a, e, changes *Disk) error {
164175
}
165176

166177
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"`
178+
Name *string `cty:"name"`
179+
VolumeType *string `cty:"type"`
180+
SizeGB *int64 `cty:"size"`
181+
ProvisionedIops *int64 `cty:"provisioned_iops"`
182+
ProvisionedThroughput *int64 `cty:"provisioned_throughput"`
183+
Zone *string `cty:"zone"`
184+
Labels map[string]string `cty:"labels"`
172185
}
173186

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

177190
labels := make(map[string]string)
@@ -185,5 +198,12 @@ func (_ *Disk) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *Disk
185198
Zone: e.Zone,
186199
Labels: labels,
187200
}
201+
if e.VolumeIops != nil {
202+
tf.ProvisionedIops = e.VolumeIops
203+
}
204+
205+
if e.VolumeThroughput != nil {
206+
tf.ProvisionedThroughput = e.VolumeThroughput
207+
}
188208
return t.RenderResource("google_compute_disk", *e.Name, tf)
189209
}

0 commit comments

Comments
 (0)