From 098266e8751e0712db652f1f999dbe61e52de317 Mon Sep 17 00:00:00 2001 From: Vlad Ionescu Date: Tue, 6 Nov 2018 13:08:40 +0200 Subject: [PATCH] Fail fast if io2 iops to size ratio is too high In AWS the ratio between volume IOPS and volume size must be at most 50, otherwise volume will fail creating. See https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html, specifically "_The maximum ratio of provisioned IOPS to requested volume size (in GiB) is 50:1. For example, a 100 GiB volume can be provisioned with up to 5,000 IOPS._" This commit adds the option of failing fast when creating a new cluster if the ratio is higher than 50. Previously kops would send the API request to AWS, fail and repeat until the timeout was reached. --- pkg/model/master_volumes.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/model/master_volumes.go b/pkg/model/master_volumes.go index 0fed42efe7..72ced7f2b1 100644 --- a/pkg/model/master_volumes.go +++ b/pkg/model/master_volumes.go @@ -92,7 +92,10 @@ func (b *MasterVolumeBuilder) Build(c *fi.ModelBuilderContext) error { switch kops.CloudProviderID(b.Cluster.Spec.CloudProvider) { case kops.CloudProviderAWS: - b.addAWSVolume(c, name, volumeSize, zone, etcd, m, allMembers) + err = b.addAWSVolume(c, name, volumeSize, zone, etcd, m, allMembers) + if err != nil { + return err + } case kops.CloudProviderDO: b.addDOVolume(c, name, volumeSize, zone, etcd, m, allMembers) case kops.CloudProviderGCE: @@ -116,7 +119,7 @@ func (b *MasterVolumeBuilder) Build(c *fi.ModelBuilderContext) error { return nil } -func (b *MasterVolumeBuilder) addAWSVolume(c *fi.ModelBuilderContext, name string, volumeSize int32, zone string, etcd *kops.EtcdClusterSpec, m *kops.EtcdMemberSpec, allMembers []string) { +func (b *MasterVolumeBuilder) addAWSVolume(c *fi.ModelBuilderContext, name string, volumeSize int32, zone string, etcd *kops.EtcdClusterSpec, m *kops.EtcdMemberSpec, allMembers []string) error { volumeType := fi.StringValue(m.VolumeType) volumeIops := fi.Int32Value(m.VolumeIops) switch volumeType { @@ -160,9 +163,16 @@ func (b *MasterVolumeBuilder) addAWSVolume(c *fi.ModelBuilderContext, name strin } if volumeType == "io1" { t.VolumeIops = i64(int64(volumeIops)) + + // https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html + if float64(*t.VolumeIops)/float64(*t.SizeGB) > 50.0 { + return fmt.Errorf("volumeIops to volumeSize ratio must be lower than 50. For %s ratio is %f", *t.Name, float64(*t.VolumeIops)/float64(*t.SizeGB)) + } } c.AddTask(t) + + return nil } func (b *MasterVolumeBuilder) addDOVolume(c *fi.ModelBuilderContext, name string, volumeSize int32, zone string, etcd *kops.EtcdClusterSpec, m *kops.EtcdMemberSpec, allMembers []string) {