Skip to content

Commit f6716ea

Browse files
Merge pull request openshift#3595 from rna-afk/gcp-disk-types
Bug 1836339: GCP: Enable disk type and size customization
2 parents be624d9 + d90c191 commit f6716ea

File tree

11 files changed

+263
-4
lines changed

11 files changed

+263
-4
lines changed

data/data/install.openshift.io_installconfigs.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,26 @@ spec:
148148
description: GCP is the configuration used when installing on
149149
GCP
150150
properties:
151+
osDisk:
152+
description: OSDisk defines the storage for instance.
153+
properties:
154+
DiskSizeGB:
155+
description: DiskSizeGB defines the size of disk in
156+
GB.
157+
format: int64
158+
minimum: 0
159+
type: integer
160+
DiskType:
161+
description: DiskType defines the type of disk. The
162+
valid values are pd-standard and pd-ssd For control
163+
plane nodes, the valid value is pd-ssd.
164+
enum:
165+
- pd-ssd
166+
- pd-standard
167+
type: string
168+
required:
169+
- DiskSizeGB
170+
type: object
151171
type:
152172
description: InstanceType defines the GCP instance type.
153173
eg. n1-standard-4
@@ -405,6 +425,25 @@ spec:
405425
description: GCP is the configuration used when installing on
406426
GCP
407427
properties:
428+
osDisk:
429+
description: OSDisk defines the storage for instance.
430+
properties:
431+
DiskSizeGB:
432+
description: DiskSizeGB defines the size of disk in GB.
433+
format: int64
434+
minimum: 0
435+
type: integer
436+
DiskType:
437+
description: DiskType defines the type of disk. The valid
438+
values are pd-standard and pd-ssd For control plane
439+
nodes, the valid value is pd-ssd.
440+
enum:
441+
- pd-ssd
442+
- pd-standard
443+
type: string
444+
required:
445+
- DiskSizeGB
446+
type: object
408447
type:
409448
description: InstanceType defines the GCP instance type. eg.
410449
n1-standard-4
@@ -980,6 +1019,25 @@ spec:
9801019
used when installing on GCP for machine pools which do not define
9811020
their own platform configuration.
9821021
properties:
1022+
osDisk:
1023+
description: OSDisk defines the storage for instance.
1024+
properties:
1025+
DiskSizeGB:
1026+
description: DiskSizeGB defines the size of disk in GB.
1027+
format: int64
1028+
minimum: 0
1029+
type: integer
1030+
DiskType:
1031+
description: DiskType defines the type of disk. The valid
1032+
values are pd-standard and pd-ssd For control plane
1033+
nodes, the valid value is pd-ssd.
1034+
enum:
1035+
- pd-ssd
1036+
- pd-standard
1037+
type: string
1038+
required:
1039+
- DiskSizeGB
1040+
type: object
9831041
type:
9841042
description: InstanceType defines the GCP instance type. eg.
9851043
n1-standard-4

docs/user/gcp/customization.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Beyond the [platform-agnostic `install-config.yaml` properties](../customization
1313

1414
* `type` (optional string): The [GCP machine type][machine-type].
1515
* `zones` (optional array of strings): The availability zones used for machines in the pool.
16+
* `osDisk` (optional object):
17+
* `diskSizeGB` (optional integer): The size of the disk in gigabytes (GB).
18+
* `diskType` (optional string): The type of disk (allowed values are: `pd-ssd`, and `pd-standard`. Default: `pd-ssd`).
1619

1720
## Installing to Existing Networks & Subnetworks
1821

@@ -44,6 +47,9 @@ platform:
4447
gcp:
4548
project: example-project
4649
region: us-east1
50+
osDisk:
51+
diskType: pd-ssd
52+
diskSizeGB: 120
4753
pullSecret: '{"auths": ...}'
4854
sshKey: ssh-ed25519 AAAA...
4955
```
@@ -63,6 +69,9 @@ compute:
6369
zones:
6470
- us-central1-a
6571
- us-central1-c
72+
osDisk:
73+
diskType: pd-standard
74+
diskSizeGB: 128
6675
replicas: 3
6776
controlPlane:
6877
name: master
@@ -72,6 +81,9 @@ controlPlane:
7281
zones:
7382
- us-central1-a
7483
- us-central1-c
84+
osDisk:
85+
diskType: pd-ssd
86+
diskSizeGB: 1024
7587
replicas: 3
7688
metadata:
7789
name: example-cluster

pkg/asset/machines/gcp/machines.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine
3131
if pool.Replicas != nil {
3232
total = *pool.Replicas
3333
}
34+
3435
var machines []machineapi.Machine
3536
for idx := int64(0); idx < total; idx++ {
3637
azIndex := int(idx) % len(azs)
@@ -84,8 +85,8 @@ func provider(clusterID string, platform *gcp.Platform, mpool *gcp.MachinePool,
8485
Disks: []*gcpprovider.GCPDisk{{
8586
AutoDelete: true,
8687
Boot: true,
87-
SizeGb: 128,
88-
Type: "pd-ssd",
88+
SizeGb: mpool.OSDisk.DiskSizeGB,
89+
Type: mpool.OSDisk.DiskType,
8990
Image: fmt.Sprintf("%s-rhcos-image", clusterID),
9091
}},
9192
NetworkInterfaces: []*gcpprovider.GCPNetworkInterface{{

pkg/asset/machines/worker.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ func defaultAzureMachinePoolPlatform() azuretypes.MachinePool {
9595
func defaultGCPMachinePoolPlatform() gcptypes.MachinePool {
9696
return gcptypes.MachinePool{
9797
InstanceType: "n1-standard-4",
98+
OSDisk: gcptypes.OSDisk{
99+
DiskSizeGB: 128,
100+
DiskType: "pd-ssd",
101+
},
98102
}
99103
}
100104

pkg/types/gcp/machinepools.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,26 @@ type MachinePool struct {
1212
//
1313
// +optional
1414
InstanceType string `json:"type"`
15+
16+
// OSDisk defines the storage for instance.
17+
//
18+
// +optional
19+
OSDisk `json:"osDisk"`
20+
}
21+
22+
// OSDisk defines the disk for machines on GCP.
23+
type OSDisk struct {
24+
// DiskType defines the type of disk.
25+
// The valid values are pd-standard and pd-ssd
26+
// For control plane nodes, the valid value is pd-ssd.
27+
// +optional
28+
// +kubebuilder:validation:Enum=pd-ssd;pd-standard
29+
DiskType string `json:"DiskType"`
30+
31+
// DiskSizeGB defines the size of disk in GB.
32+
//
33+
// +kubebuilder:validation:Minimum=0
34+
DiskSizeGB int64 `json:"DiskSizeGB"`
1535
}
1636

1737
// Set sets the values from `required` to `a`.
@@ -27,4 +47,12 @@ func (a *MachinePool) Set(required *MachinePool) {
2747
if required.InstanceType != "" {
2848
a.InstanceType = required.InstanceType
2949
}
50+
51+
if required.OSDisk.DiskSizeGB > 0 {
52+
a.OSDisk.DiskSizeGB = required.OSDisk.DiskSizeGB
53+
}
54+
55+
if required.OSDisk.DiskType != "" {
56+
a.OSDisk.DiskType = required.OSDisk.DiskType
57+
}
3058
}

pkg/types/gcp/validation/machinepool.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import (
44
"fmt"
55
"strings"
66

7+
"github.com/openshift/installer/pkg/types"
78
"github.com/openshift/installer/pkg/types/gcp"
9+
"k8s.io/apimachinery/pkg/util/sets"
810
"k8s.io/apimachinery/pkg/util/validation/field"
911
)
1012

@@ -17,5 +19,42 @@ func ValidateMachinePool(platform *gcp.Platform, p *gcp.MachinePool, fldPath *fi
1719
}
1820
}
1921

22+
if p.OSDisk.DiskSizeGB < 0 {
23+
allErrs = append(allErrs, field.Invalid(fldPath.Child("diskSizeGB"), p.OSDisk.DiskSizeGB, "must be a positive value"))
24+
}
25+
26+
if p.OSDisk.DiskType != "" {
27+
diskTypes := sets.NewString("pd-standard", "pd-ssd")
28+
if !diskTypes.Has(p.OSDisk.DiskType) {
29+
allErrs = append(allErrs, field.NotSupported(fldPath.Child("diskType"), p.OSDisk.DiskType, diskTypes.List()))
30+
}
31+
}
32+
33+
return allErrs
34+
}
35+
36+
// ValidateMasterDiskType checks that the specified disk type is valid for control plane.
37+
func ValidateMasterDiskType(p *types.MachinePool, fldPath *field.Path) field.ErrorList {
38+
allErrs := field.ErrorList{}
39+
40+
if p.Name == "master" && p.Platform.GCP.OSDisk.DiskType == "pd-standard" {
41+
allErrs = append(allErrs, field.Invalid(fldPath.Child("diskType"), p.Platform.GCP.OSDisk.DiskType, fmt.Sprintf("%s not compatible with control planes.", p.Platform.GCP.OSDisk.DiskType)))
42+
}
43+
44+
return allErrs
45+
}
46+
47+
// ValidateDefaultDiskType checks that the specified disk type is valid for default GCP Machine Platform.
48+
func ValidateDefaultDiskType(p *gcp.MachinePool, fldPath *field.Path) field.ErrorList {
49+
allErrs := field.ErrorList{}
50+
51+
if p != nil && p.OSDisk.DiskType != "" {
52+
diskTypes := sets.NewString("pd-ssd")
53+
54+
if !diskTypes.Has(p.OSDisk.DiskType) {
55+
allErrs = append(allErrs, field.NotSupported(fldPath.Child("diskType"), p.OSDisk.DiskType, diskTypes.List()))
56+
}
57+
}
58+
2059
return allErrs
2160
}

pkg/types/gcp/validation/machinepool_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,40 @@ func TestValidateMachinePool(t *testing.T) {
3333
},
3434
expected: `^test-path\.zones\[1]: Invalid value: "us-central1-f": Zone not in configured region \(us-east1\)$`,
3535
},
36+
{
37+
name: "valid disk type",
38+
pool: &gcp.MachinePool{
39+
OSDisk: gcp.OSDisk{
40+
DiskType: "pd-standard",
41+
},
42+
},
43+
},
44+
{
45+
name: "invalid disk type",
46+
pool: &gcp.MachinePool{
47+
OSDisk: gcp.OSDisk{
48+
DiskType: "pd-",
49+
},
50+
},
51+
expected: `^test-path\.diskType: Unsupported value: "pd-": supported values: "pd-ssd", "pd-standard"$`,
52+
},
53+
{
54+
name: "valid disk size",
55+
pool: &gcp.MachinePool{
56+
OSDisk: gcp.OSDisk{
57+
DiskSizeGB: 100,
58+
},
59+
},
60+
},
61+
{
62+
name: "invalid disk type",
63+
pool: &gcp.MachinePool{
64+
OSDisk: gcp.OSDisk{
65+
DiskSizeGB: -120,
66+
},
67+
},
68+
expected: `^test-path\.diskSizeGB: Invalid value: -120: must be a positive value$`,
69+
},
3670
}
3771
for _, tc := range cases {
3872
t.Run(tc.name, func(t *testing.T) {

pkg/types/gcp/validation/platform.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func ValidatePlatform(p *gcp.Platform, fldPath *field.Path) field.ErrorList {
5555
}
5656
if p.DefaultMachinePlatform != nil {
5757
allErrs = append(allErrs, ValidateMachinePool(p, p.DefaultMachinePlatform, fldPath.Child("defaultMachinePlatform"))...)
58+
allErrs = append(allErrs, ValidateDefaultDiskType(p.DefaultMachinePlatform, fldPath.Child("defaultMachinePlatform"))...)
5859
}
5960
if p.Network != "" {
6061
if p.ComputeSubnet == "" {

pkg/types/gcp/validation/platform_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,31 @@ func TestValidatePlatform(t *testing.T) {
6363
},
6464
valid: false,
6565
},
66+
{
67+
name: "unsupported GCP disk type",
68+
platform: &gcp.Platform{
69+
Region: "us-east1",
70+
DefaultMachinePlatform: &gcp.MachinePool{
71+
OSDisk: gcp.OSDisk{
72+
DiskType: "pd-standard",
73+
},
74+
},
75+
},
76+
valid: false,
77+
},
78+
79+
{
80+
name: "supported GCP disk type",
81+
platform: &gcp.Platform{
82+
Region: "us-east1",
83+
DefaultMachinePlatform: &gcp.MachinePool{
84+
OSDisk: gcp.OSDisk{
85+
DiskType: "pd-ssd",
86+
},
87+
},
88+
},
89+
valid: true,
90+
},
6691
}
6792
for _, tc := range cases {
6893
t.Run(tc.name, func(t *testing.T) {

pkg/types/validation/machinepools.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
azurevalidation "github.com/openshift/installer/pkg/types/azure/validation"
1313
"github.com/openshift/installer/pkg/types/baremetal"
1414
baremetalvalidation "github.com/openshift/installer/pkg/types/baremetal/validation"
15+
"github.com/openshift/installer/pkg/types/gcp"
16+
gcpvalidation "github.com/openshift/installer/pkg/types/gcp/validation"
1517
"github.com/openshift/installer/pkg/types/libvirt"
1618
libvirtvalidation "github.com/openshift/installer/pkg/types/libvirt/validation"
1719
"github.com/openshift/installer/pkg/types/openstack"
@@ -67,11 +69,11 @@ func ValidateMachinePool(platform *types.Platform, p *types.MachinePool, fldPath
6769
if !validArchitectures[p.Architecture] {
6870
allErrs = append(allErrs, field.NotSupported(fldPath.Child("architecture"), p.Architecture, validArchitectureValues))
6971
}
70-
allErrs = append(allErrs, validateMachinePoolPlatform(platform, &p.Platform, fldPath.Child("platform"))...)
72+
allErrs = append(allErrs, validateMachinePoolPlatform(platform, &p.Platform, p, fldPath.Child("platform"))...)
7173
return allErrs
7274
}
7375

74-
func validateMachinePoolPlatform(platform *types.Platform, p *types.MachinePoolPlatform, fldPath *field.Path) field.ErrorList {
76+
func validateMachinePoolPlatform(platform *types.Platform, p *types.MachinePoolPlatform, pool *types.MachinePool, fldPath *field.Path) field.ErrorList {
7577
allErrs := field.ErrorList{}
7678
platformName := platform.Name()
7779
validate := func(n string, value interface{}, validation func(*field.Path) field.ErrorList) {
@@ -88,6 +90,9 @@ func validateMachinePoolPlatform(platform *types.Platform, p *types.MachinePoolP
8890
if p.Azure != nil {
8991
validate(azure.Name, p.Azure, func(f *field.Path) field.ErrorList { return azurevalidation.ValidateMachinePool(p.Azure, f) })
9092
}
93+
if p.GCP != nil {
94+
validate(gcp.Name, p.GCP, func(f *field.Path) field.ErrorList { return validateGCPMachinePool(platform, p, pool, f) })
95+
}
9196
if p.Libvirt != nil {
9297
validate(libvirt.Name, p.Libvirt, func(f *field.Path) field.ErrorList { return libvirtvalidation.ValidateMachinePool(p.Libvirt, f) })
9398
}
@@ -105,3 +110,12 @@ func validateMachinePoolPlatform(platform *types.Platform, p *types.MachinePoolP
105110
}
106111
return allErrs
107112
}
113+
114+
func validateGCPMachinePool(platform *types.Platform, p *types.MachinePoolPlatform, pool *types.MachinePool, f *field.Path) field.ErrorList {
115+
allErrs := field.ErrorList{}
116+
117+
allErrs = append(allErrs, gcpvalidation.ValidateMachinePool(platform.GCP, p.GCP, f)...)
118+
allErrs = append(allErrs, gcpvalidation.ValidateMasterDiskType(pool, f)...)
119+
120+
return allErrs
121+
}

0 commit comments

Comments
 (0)