mirror of
https://github.com/openshift/installer.git
synced 2026-02-05 15:47:14 +01:00
Merge pull request #8920 from barbacbd/OCPBUGS-39206
OCPBUGS-39206: Update GCP Disk Types 4.16
This commit is contained in:
@@ -507,11 +507,13 @@ spec:
|
||||
type: integer
|
||||
diskType:
|
||||
description: DiskType defines the type of disk. For
|
||||
control plane nodes, the valid value is pd-ssd.
|
||||
control plane nodes, the valid values are pd-balanced,
|
||||
pd-ssd, and hyperdisk-balanced.
|
||||
enum:
|
||||
- pd-balanced
|
||||
- pd-ssd
|
||||
- pd-standard
|
||||
- hyperdisk-balanced
|
||||
type: string
|
||||
encryptionKey:
|
||||
description: EncryptionKey defines the KMS key to be
|
||||
@@ -1415,11 +1417,13 @@ spec:
|
||||
type: integer
|
||||
diskType:
|
||||
description: DiskType defines the type of disk. For control
|
||||
plane nodes, the valid value is pd-ssd.
|
||||
plane nodes, the valid values are pd-balanced, pd-ssd,
|
||||
and hyperdisk-balanced.
|
||||
enum:
|
||||
- pd-balanced
|
||||
- pd-ssd
|
||||
- pd-standard
|
||||
- hyperdisk-balanced
|
||||
type: string
|
||||
encryptionKey:
|
||||
description: EncryptionKey defines the KMS key to be used
|
||||
@@ -3047,11 +3051,13 @@ spec:
|
||||
type: integer
|
||||
diskType:
|
||||
description: DiskType defines the type of disk. For control
|
||||
plane nodes, the valid value is pd-ssd.
|
||||
plane nodes, the valid values are pd-balanced, pd-ssd,
|
||||
and hyperdisk-balanced.
|
||||
enum:
|
||||
- pd-balanced
|
||||
- pd-ssd
|
||||
- pd-standard
|
||||
- hyperdisk-balanced
|
||||
type: string
|
||||
encryptionKey:
|
||||
description: EncryptionKey defines the KMS key to be used
|
||||
|
||||
@@ -74,7 +74,7 @@ func Validate(client API, ic *types.InstallConfig) error {
|
||||
}
|
||||
|
||||
// ValidateInstanceType ensures the instance type has sufficient Vcpu and Memory.
|
||||
func ValidateInstanceType(client API, fieldPath *field.Path, project, region string, zones []string, instanceType string, req resourceRequirements, arch string) field.ErrorList {
|
||||
func ValidateInstanceType(client API, fieldPath *field.Path, project, region string, zones []string, diskType string, instanceType string, req resourceRequirements, arch string) field.ErrorList {
|
||||
allErrs := field.ErrorList{}
|
||||
|
||||
typeMeta, typeZones, err := client.GetMachineTypeWithZones(context.TODO(), project, region, instanceType)
|
||||
@@ -85,6 +85,14 @@ func ValidateInstanceType(client API, fieldPath *field.Path, project, region str
|
||||
return append(allErrs, field.InternalError(nil, err))
|
||||
}
|
||||
|
||||
if diskType == "hyperdisk-balanced" {
|
||||
family, _, _ := strings.Cut(instanceType, "-")
|
||||
families := sets.NewString("c3", "c3d", "m1", "n4")
|
||||
if !families.Has(family) {
|
||||
allErrs = append(allErrs, field.NotSupported(fieldPath.Child("diskType"), family, families.List()))
|
||||
}
|
||||
}
|
||||
|
||||
userZones := sets.New(zones...)
|
||||
if len(userZones) == 0 {
|
||||
userZones = typeZones
|
||||
@@ -153,6 +161,7 @@ func validateInstanceTypes(client API, ic *types.InstallConfig) field.ErrorList
|
||||
if ic.GCP.DefaultMachinePlatform != nil {
|
||||
defaultZones = ic.GCP.DefaultMachinePlatform.Zones
|
||||
defaultInstanceType = ic.GCP.DefaultMachinePlatform.InstanceType
|
||||
|
||||
if ic.GCP.DefaultMachinePlatform.InstanceType != "" {
|
||||
allErrs = append(allErrs,
|
||||
ValidateInstanceType(
|
||||
@@ -161,6 +170,7 @@ func validateInstanceTypes(client API, ic *types.InstallConfig) field.ErrorList
|
||||
ic.GCP.ProjectID,
|
||||
ic.GCP.Region,
|
||||
ic.GCP.DefaultMachinePlatform.Zones,
|
||||
ic.GCP.DefaultMachinePlatform.DiskType,
|
||||
ic.GCP.DefaultMachinePlatform.InstanceType,
|
||||
defaultInstanceReq,
|
||||
unknownArchitecture,
|
||||
@@ -171,6 +181,7 @@ func validateInstanceTypes(client API, ic *types.InstallConfig) field.ErrorList
|
||||
zones := defaultZones
|
||||
instanceType := defaultInstanceType
|
||||
arch := types.ArchitectureAMD64
|
||||
cpDiskType := ""
|
||||
if ic.ControlPlane != nil {
|
||||
arch = string(ic.ControlPlane.Architecture)
|
||||
if instanceType == "" {
|
||||
@@ -183,6 +194,7 @@ func validateInstanceTypes(client API, ic *types.InstallConfig) field.ErrorList
|
||||
if len(ic.ControlPlane.Platform.GCP.Zones) > 0 {
|
||||
zones = ic.ControlPlane.Platform.GCP.Zones
|
||||
}
|
||||
cpDiskType = ic.ControlPlane.Platform.GCP.DiskType
|
||||
}
|
||||
}
|
||||
allErrs = append(allErrs,
|
||||
@@ -192,6 +204,7 @@ func validateInstanceTypes(client API, ic *types.InstallConfig) field.ErrorList
|
||||
ic.GCP.ProjectID,
|
||||
ic.GCP.Region,
|
||||
zones,
|
||||
cpDiskType,
|
||||
instanceType,
|
||||
controlPlaneReq,
|
||||
arch,
|
||||
@@ -213,6 +226,12 @@ func validateInstanceTypes(client API, ic *types.InstallConfig) field.ErrorList
|
||||
zones = compute.Platform.GCP.Zones
|
||||
}
|
||||
}
|
||||
|
||||
diskType := ""
|
||||
if compute.Platform.GCP != nil && compute.Platform.GCP.DiskType != "" {
|
||||
diskType = compute.Platform.GCP.DiskType
|
||||
}
|
||||
|
||||
allErrs = append(allErrs,
|
||||
ValidateInstanceType(
|
||||
client,
|
||||
@@ -220,6 +239,7 @@ func validateInstanceTypes(client API, ic *types.InstallConfig) field.ErrorList
|
||||
ic.GCP.ProjectID,
|
||||
ic.GCP.Region,
|
||||
zones,
|
||||
diskType,
|
||||
instanceType,
|
||||
computeReq,
|
||||
string(arch),
|
||||
|
||||
@@ -113,6 +113,7 @@ var (
|
||||
"n2-standard-1": {GuestCpus: 1, MemoryMb: 8192},
|
||||
"n2-standard-2": {GuestCpus: 2, MemoryMb: 16384},
|
||||
"n2-standard-4": {GuestCpus: 4, MemoryMb: 32768},
|
||||
"n4-standard-4": {GuestCpus: 4, MemoryMb: 32768},
|
||||
"t2a-standard-4": {GuestCpus: 4, MemoryMb: 16384},
|
||||
}
|
||||
|
||||
@@ -749,6 +750,7 @@ func TestValidateInstanceType(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
zones []string
|
||||
diskType string
|
||||
instanceType string
|
||||
arch string
|
||||
expectedError bool
|
||||
@@ -758,6 +760,7 @@ func TestValidateInstanceType(t *testing.T) {
|
||||
name: "Valid instance type with min requirements and no zones specified",
|
||||
zones: []string{},
|
||||
instanceType: "n1-standard-4",
|
||||
diskType: "pd-ssd",
|
||||
expectedError: false,
|
||||
expectedErrMsg: "",
|
||||
},
|
||||
@@ -765,6 +768,7 @@ func TestValidateInstanceType(t *testing.T) {
|
||||
name: "Valid instance type with min requirements and valid zones specified",
|
||||
zones: []string{"a", "b"},
|
||||
instanceType: "n1-standard-4",
|
||||
diskType: "pd-ssd",
|
||||
arch: "amd64",
|
||||
expectedError: false,
|
||||
expectedErrMsg: "",
|
||||
@@ -773,6 +777,7 @@ func TestValidateInstanceType(t *testing.T) {
|
||||
name: "Valid instance type with min requirements and invalid zones specified",
|
||||
zones: []string{"a", "b", "d", "x", "y"},
|
||||
instanceType: "n1-standard-4",
|
||||
diskType: "pd-ssd",
|
||||
expectedError: true,
|
||||
expectedErrMsg: `\[instance.type: Invalid value: "n1\-standard\-4": instance type not available in zones: \[x y\]\]$`,
|
||||
},
|
||||
@@ -780,6 +785,7 @@ func TestValidateInstanceType(t *testing.T) {
|
||||
name: "Valid instance fails min requirements and no zones specified",
|
||||
zones: []string{},
|
||||
instanceType: "n1-standard-2",
|
||||
diskType: "pd-ssd",
|
||||
expectedError: true,
|
||||
expectedErrMsg: `^\[instance.type: Invalid value: "n1\-standard\-2": instance type does not meet minimum resource requirements of 4 vCPUs instance.type: Invalid value: "n1\-standard\-2": instance type does not meet minimum resource requirements of 15360 MB Memory\]$`,
|
||||
},
|
||||
@@ -787,12 +793,14 @@ func TestValidateInstanceType(t *testing.T) {
|
||||
name: "Valid instance fails min requirements and valid zones specified",
|
||||
zones: []string{"a", "b"},
|
||||
instanceType: "n1-standard-1",
|
||||
diskType: "pd-ssd",
|
||||
expectedError: true,
|
||||
expectedErrMsg: ``,
|
||||
},
|
||||
{
|
||||
name: "Valid instance fails min requirements and invalid zones specified",
|
||||
zones: []string{"a", "x", "y"},
|
||||
diskType: "pd-ssd",
|
||||
expectedError: true,
|
||||
expectedErrMsg: ``,
|
||||
},
|
||||
@@ -800,6 +808,7 @@ func TestValidateInstanceType(t *testing.T) {
|
||||
name: "Invalid instance and no zones specified",
|
||||
zones: []string{},
|
||||
instanceType: "invalid-instance-1",
|
||||
diskType: "pd-ssd",
|
||||
expectedError: true,
|
||||
expectedErrMsg: `^\[<nil>: Internal error: 404\]$`,
|
||||
},
|
||||
@@ -807,6 +816,7 @@ func TestValidateInstanceType(t *testing.T) {
|
||||
name: "Invalid instance and valid zones specified",
|
||||
zones: []string{"a", "b"},
|
||||
instanceType: "invalid-instance-1",
|
||||
diskType: "pd-ssd",
|
||||
expectedError: true,
|
||||
expectedErrMsg: `^\[<nil>: Internal error: 404\]$`,
|
||||
},
|
||||
@@ -814,6 +824,7 @@ func TestValidateInstanceType(t *testing.T) {
|
||||
name: "Invalid instance and invalid zones specified",
|
||||
zones: []string{"a", "x", "y", "z"},
|
||||
instanceType: "invalid-instance-1",
|
||||
diskType: "pd-ssd",
|
||||
expectedError: true,
|
||||
expectedErrMsg: `^\[<nil>: Internal error: 404\]$`,
|
||||
},
|
||||
@@ -821,10 +832,27 @@ func TestValidateInstanceType(t *testing.T) {
|
||||
name: "Invalid instance architecture",
|
||||
zones: []string{"a", "b"},
|
||||
instanceType: "t2a-standard-4",
|
||||
diskType: "pd-ssd",
|
||||
arch: "amd64",
|
||||
expectedError: true,
|
||||
expectedErrMsg: `^\[instance.type: Invalid value: "t2a\-standard\-4": instance type architecture arm64 does not match specified architecture amd64\]$`,
|
||||
},
|
||||
{
|
||||
name: "Valid special instance type with min requirements",
|
||||
zones: []string{"a"},
|
||||
instanceType: "n4-standard-4",
|
||||
diskType: "hyperdisk-balanced",
|
||||
expectedError: false,
|
||||
expectedErrMsg: "",
|
||||
},
|
||||
{
|
||||
name: "Invalid special instance type with min requirements",
|
||||
zones: []string{"a"},
|
||||
instanceType: "n2-standard-4",
|
||||
diskType: "hyperdisk-balanced",
|
||||
expectedError: true,
|
||||
expectedErrMsg: `^\[instance.diskType: Unsupported value: \"n2\": supported values: \"c3\", \"c3d\", \"m1\", \"n4\"\]$`,
|
||||
},
|
||||
}
|
||||
|
||||
mockCtrl := gomock.NewController(t)
|
||||
@@ -840,7 +868,7 @@ func TestValidateInstanceType(t *testing.T) {
|
||||
|
||||
for _, test := range cases {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
errs := ValidateInstanceType(gcpClient, field.NewPath("instance"), "project-id", "region", test.zones, test.instanceType, controlPlaneReq, test.arch)
|
||||
errs := ValidateInstanceType(gcpClient, field.NewPath("instance"), "project-id", "region", test.zones, test.diskType, test.instanceType, controlPlaneReq, test.arch)
|
||||
if test.expectedError {
|
||||
assert.Regexp(t, test.expectedErrMsg, errs)
|
||||
} else {
|
||||
|
||||
@@ -233,7 +233,7 @@ func getRegionFromZone(zoneName string) string {
|
||||
// projects/project/zones/zone/diskTypes/pd-standard -> "ssd_total_storage"
|
||||
func getDiskLimit(typeURL string) string {
|
||||
switch getNameFromURL("diskTypes", typeURL) {
|
||||
case "pd-balanced", "pd-ssd":
|
||||
case "pd-balanced", "pd-ssd", "hyperdisk-balanced":
|
||||
return "ssd_total_storage"
|
||||
case "pd-standard":
|
||||
return "disks_total_storage"
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package gcp
|
||||
|
||||
import "k8s.io/apimachinery/pkg/util/sets"
|
||||
|
||||
// FeatureSwitch indicates whether the feature is enabled or disabled.
|
||||
type FeatureSwitch string
|
||||
|
||||
@@ -7,6 +9,14 @@ type FeatureSwitch string
|
||||
// applicable when ConfidentialCompute is Enabled.
|
||||
type OnHostMaintenanceType string
|
||||
|
||||
var (
|
||||
// ControlPlaneSupportedDisks contains the supported disk types for control plane nodes.
|
||||
ControlPlaneSupportedDisks = sets.New("hyperdisk-balanced", "pd-balanced", "pd-ssd")
|
||||
|
||||
// ComputeSupportedDisks contains the supported disk types for control plane nodes.
|
||||
ComputeSupportedDisks = sets.New("hyperdisk-balanced", "pd-balanced", "pd-ssd", "pd-standard")
|
||||
)
|
||||
|
||||
const (
|
||||
// EnabledFeature indicates that the feature is configured as enabled.
|
||||
EnabledFeature FeatureSwitch = "Enabled"
|
||||
@@ -86,9 +96,9 @@ type MachinePool struct {
|
||||
// OSDisk defines the disk for machines on GCP.
|
||||
type OSDisk struct {
|
||||
// DiskType defines the type of disk.
|
||||
// For control plane nodes, the valid value is pd-ssd.
|
||||
// For control plane nodes, the valid values are pd-balanced, pd-ssd, and hyperdisk-balanced.
|
||||
// +optional
|
||||
// +kubebuilder:validation:Enum=pd-balanced;pd-ssd;pd-standard
|
||||
// +kubebuilder:validation:Enum=pd-balanced;pd-ssd;pd-standard;hyperdisk-balanced
|
||||
DiskType string `json:"diskType"`
|
||||
|
||||
// DiskSizeGB defines the size of disk in GB.
|
||||
|
||||
@@ -29,11 +29,8 @@ func ValidateMachinePool(platform *gcp.Platform, p *gcp.MachinePool, fldPath *fi
|
||||
}
|
||||
}
|
||||
|
||||
if p.OSDisk.DiskType != "" {
|
||||
diskTypes := sets.NewString("pd-balanced", "pd-ssd", "pd-standard")
|
||||
if !diskTypes.Has(p.OSDisk.DiskType) {
|
||||
allErrs = append(allErrs, field.NotSupported(fldPath.Child("diskType"), p.OSDisk.DiskType, diskTypes.List()))
|
||||
}
|
||||
if diskType := p.OSDisk.DiskType; diskType != "" && !gcp.ComputeSupportedDisks.Has(diskType) {
|
||||
allErrs = append(allErrs, field.NotSupported(fldPath.Child("diskType"), diskType, sets.List(gcp.ComputeSupportedDisks)))
|
||||
}
|
||||
|
||||
if p.ConfidentialCompute == string(gcp.EnabledFeature) && p.OnHostMaintenance != string(gcp.OnHostMaintenanceTerminate) {
|
||||
@@ -74,9 +71,8 @@ func ValidateServiceAccount(platform *gcp.Platform, p *types.MachinePool, fldPat
|
||||
func ValidateMasterDiskType(p *types.MachinePool, fldPath *field.Path) field.ErrorList {
|
||||
allErrs := field.ErrorList{}
|
||||
if p.Name == "master" && p.Platform.GCP.OSDisk.DiskType != "" {
|
||||
diskTypes := sets.NewString("pd-ssd")
|
||||
if !diskTypes.Has(p.Platform.GCP.OSDisk.DiskType) {
|
||||
allErrs = append(allErrs, field.NotSupported(fldPath.Child("diskType"), p.Platform.GCP.OSDisk.DiskType, diskTypes.List()))
|
||||
if !gcp.ControlPlaneSupportedDisks.Has(p.Platform.GCP.OSDisk.DiskType) {
|
||||
allErrs = append(allErrs, field.NotSupported(fldPath.Child("diskType"), p.Platform.GCP.OSDisk.DiskType, sets.List(gcp.ControlPlaneSupportedDisks)))
|
||||
}
|
||||
}
|
||||
return allErrs
|
||||
@@ -87,10 +83,8 @@ func ValidateDefaultDiskType(p *gcp.MachinePool, fldPath *field.Path) field.Erro
|
||||
allErrs := field.ErrorList{}
|
||||
|
||||
if p != nil && p.OSDisk.DiskType != "" {
|
||||
diskTypes := sets.NewString("pd-ssd")
|
||||
|
||||
if !diskTypes.Has(p.OSDisk.DiskType) {
|
||||
allErrs = append(allErrs, field.NotSupported(fldPath.Child("diskType"), p.OSDisk.DiskType, diskTypes.List()))
|
||||
if !gcp.ControlPlaneSupportedDisks.Has(p.OSDisk.DiskType) {
|
||||
allErrs = append(allErrs, field.NotSupported(fldPath.Child("diskType"), p.OSDisk.DiskType, sets.List(gcp.ControlPlaneSupportedDisks)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ func TestValidateMachinePool(t *testing.T) {
|
||||
DiskType: "pd-",
|
||||
},
|
||||
},
|
||||
expected: `^test-path\.diskType: Unsupported value: "pd-": supported values: "pd-balanced", "pd-ssd", "pd-standard"$`,
|
||||
expected: `^test-path\.diskType: Unsupported value: "pd-": supported values: "hyperdisk-balanced", "pd-balanced", "pd-ssd", "pd-standard"$`,
|
||||
},
|
||||
{
|
||||
name: "valid disk size",
|
||||
|
||||
@@ -178,6 +178,34 @@ func TestValidateMachinePool(t *testing.T) {
|
||||
}(),
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
name: "valid GCP disk type master",
|
||||
platform: &types.Platform{GCP: &gcp.Platform{Region: "us-east-1"}},
|
||||
pool: func() *types.MachinePool {
|
||||
p := validMachinePool("master")
|
||||
p.Platform = types.MachinePoolPlatform{
|
||||
GCP: &gcp.MachinePool{},
|
||||
}
|
||||
p.Platform.GCP.OSDisk.DiskSizeGB = 100
|
||||
p.Platform.GCP.OSDisk.DiskType = "hyperdisk-balanced"
|
||||
return p
|
||||
}(),
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
name: "invalid GCP disk type master",
|
||||
platform: &types.Platform{GCP: &gcp.Platform{Region: "us-east-1"}},
|
||||
pool: func() *types.MachinePool {
|
||||
p := validMachinePool("master")
|
||||
p.Platform = types.MachinePoolPlatform{
|
||||
GCP: &gcp.MachinePool{},
|
||||
}
|
||||
p.Platform.GCP.OSDisk.DiskSizeGB = 100
|
||||
p.Platform.GCP.OSDisk.DiskType = "pd-standard"
|
||||
return p
|
||||
}(),
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
name: "valid GCP service account use",
|
||||
platform: &types.Platform{GCP: &gcp.Platform{Region: "us-east-1", NetworkProjectID: "ExampleNetworkProject"}},
|
||||
|
||||
Reference in New Issue
Block a user