Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pkg/webhooks/machine_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,29 @@ func validateAWS(m *machinev1beta1.Machine, config *admissionConfig) (bool, []st

// TODO(alberto): Validate providerSpec.BlockDevices.
// https://github.com/openshift/cluster-api-provider-aws/pull/299#discussion_r433920532
for i, blockDevice := range providerSpec.BlockDevices {
if blockDevice.EBS == nil || blockDevice.EBS.VolumeType == nil || blockDevice.EBS.ThroughputMib == nil {
continue
} else if *blockDevice.EBS.VolumeType != "gp3" {
errs = append(
errs,
field.Invalid(
field.NewPath("providerSpec", "blockDevices", "ebs", "throughputMib"),
*providerSpec.BlockDevices[i].EBS.ThroughputMib,
fmt.Sprintf("providerSpec.blockDevices[%d].ebs.throughputMib is only valid for gp3 volumes", i),
),
)
} else if *blockDevice.EBS.ThroughputMib < 125 || *blockDevice.EBS.ThroughputMib > 2000 {
errs = append(
errs,
field.Invalid(
field.NewPath("providerSpec", "blockDevices", "ebs", "throughputMib"),
*providerSpec.BlockDevices[i].EBS.ThroughputMib,
fmt.Sprintf("providerSpec.blockDevices[%d].ebs.throughputMib must be a value between 125 and 2000", i),
),
)
}
}

switch providerSpec.Placement.Tenancy {
case "", machinev1beta1.DefaultTenancy, machinev1beta1.DedicatedTenancy, machinev1beta1.HostTenancy:
Expand Down
104 changes: 104 additions & 0 deletions pkg/webhooks/machine_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,110 @@ func TestMachineCreation(t *testing.T) {
},
expectedError: "",
},
{
name: "with VolumeType set to gp3 and Throughput not set",
platformType: osconfigv1.AWSPlatformType,
clusterID: "aws-cluster",
providerSpecValue: &kruntime.RawExtension{
Object: &machinev1beta1.AWSMachineProviderConfig{
AMI: machinev1beta1.AWSResourceReference{
ID: ptr.To[string]("ami"),
},
BlockDevices: []machinev1beta1.BlockDeviceMappingSpec{
{
EBS: &machinev1beta1.EBSBlockDeviceSpec{
VolumeType: ptr.To[string]("gp3"),
},
},
},
},
},
expectedError: "",
},
{
name: "with VolumeType set to gp3 and Throughput set under minium value",
platformType: osconfigv1.AWSPlatformType,
clusterID: "aws-cluster",
providerSpecValue: &kruntime.RawExtension{
Object: &machinev1beta1.AWSMachineProviderConfig{
AMI: machinev1beta1.AWSResourceReference{
ID: ptr.To[string]("ami"),
},
BlockDevices: []machinev1beta1.BlockDeviceMappingSpec{
{
EBS: &machinev1beta1.EBSBlockDeviceSpec{
VolumeType: ptr.To[string]("gp3"),
ThroughputMib: ptr.To[int32](124),
},
},
},
},
},
expectedError: "providerSpec.blockDevices[0].ebs.throughputMib must be a value between 125 and 2000",
},
{
name: "with VolumeType set to gp3 and Throughput set over maxium value",
platformType: osconfigv1.AWSPlatformType,
clusterID: "aws-cluster",
providerSpecValue: &kruntime.RawExtension{
Object: &machinev1beta1.AWSMachineProviderConfig{
AMI: machinev1beta1.AWSResourceReference{
ID: ptr.To[string]("ami"),
},
BlockDevices: []machinev1beta1.BlockDeviceMappingSpec{
{
EBS: &machinev1beta1.EBSBlockDeviceSpec{
VolumeType: ptr.To[string]("gp3"),
ThroughputMib: ptr.To[int32](2001),
},
},
},
},
},
expectedError: "providerSpec.blockDevices[0].ebs.throughputMib must be a value between 125 and 2000",
},
{
name: "with VolumeType set to gp3 and Throughput set within range",
platformType: osconfigv1.AWSPlatformType,
clusterID: "aws-cluster",
providerSpecValue: &kruntime.RawExtension{
Object: &machinev1beta1.AWSMachineProviderConfig{
AMI: machinev1beta1.AWSResourceReference{
ID: ptr.To[string]("ami"),
},
BlockDevices: []machinev1beta1.BlockDeviceMappingSpec{
{
EBS: &machinev1beta1.EBSBlockDeviceSpec{
VolumeType: ptr.To[string]("gp3"),
ThroughputMib: ptr.To[int32](1000),
},
},
},
},
},
expectedError: "",
},
{
name: "with Throughput set on non gp3 volume",
platformType: osconfigv1.AWSPlatformType,
clusterID: "aws-cluster",
providerSpecValue: &kruntime.RawExtension{
Object: &machinev1beta1.AWSMachineProviderConfig{
AMI: machinev1beta1.AWSResourceReference{
ID: ptr.To[string]("ami"),
},
BlockDevices: []machinev1beta1.BlockDeviceMappingSpec{
{
EBS: &machinev1beta1.EBSBlockDeviceSpec{
VolumeType: ptr.To[string]("io1"),
ThroughputMib: ptr.To[int32](124),
},
},
},
},
},
expectedError: "providerSpec.blockDevices[0].ebs.throughputMib is only valid for gp3 volumes",
},
{
name: "with Azure and a nil provider spec value",
platformType: osconfigv1.AzurePlatformType,
Expand Down