Skip to content

Commit

Permalink
Merge pull request #10527 from hakman/automated-cherry-pick-of-#10453…
Browse files Browse the repository at this point in the history
…-upstream-release-1.19

Automated cherry pick of #10453: add gp3 volume default params
  • Loading branch information
k8s-ci-robot authored Jan 4, 2021
2 parents 08b8145 + 3b51ce4 commit 2ccc6f4
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 11 deletions.
4 changes: 4 additions & 0 deletions k8s/crds/kops.k8s.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,10 @@ spec:
description: VolumeSize is the underlying cloud volume size
format: int32
type: integer
volumeThroughput:
description: Parameter for disks that support provisioned throughput
format: int32
type: integer
volumeType:
description: VolumeType is the underlying cloud storage class
type: string
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/kops/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ type EtcdMemberSpec struct {
VolumeType *string `json:"volumeType,omitempty"`
// If volume type is io1, then we need to specify the number of Iops.
VolumeIops *int32 `json:"volumeIops,omitempty"`
// Parameter for disks that support provisioned throughput
VolumeThroughput *int32 `json:"volumeThroughput,omitempty"`
// VolumeSize is the underlying cloud volume size
VolumeSize *int32 `json:"volumeSize,omitempty"`
// KmsKeyId is a AWS KMS ID used to encrypt the volume
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/kops/v1alpha2/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,8 @@ type EtcdMemberSpec struct {
VolumeType *string `json:"volumeType,omitempty"`
// If volume type is io1, then we need to specify the number of Iops.
VolumeIops *int32 `json:"volumeIops,omitempty"`
// Parameter for disks that support provisioned throughput
VolumeThroughput *int32 `json:"volumeThroughput,omitempty"`
// VolumeSize is the underlying cloud volume size
VolumeSize *int32 `json:"volumeSize,omitempty"`
// KmsKeyId is a AWS KMS ID used to encrypt the volume
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/kops/v1alpha2/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/apis/kops/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/apis/kops/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 36 additions & 11 deletions pkg/model/master_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ import (
)

const (
DefaultEtcdVolumeSize = 20
DefaultAWSEtcdVolumeType = "gp2"
DefaultAWSEtcdVolumeIops = 100
DefaultGCEEtcdVolumeType = "pd-ssd"
DefaultALIEtcdVolumeType = "cloud_ssd"
DefaultEtcdVolumeSize = 20
DefaultAWSEtcdVolumeType = "gp2"
DefaultAWSEtcdVolumeIops = 100
DefaultAWSEtcdVolumeGp3Iops = 3000
DefaultAWSEtcdVolumeGp3Throughput = 125
DefaultGCEEtcdVolumeType = "pd-ssd"
DefaultALIEtcdVolumeType = "cloud_ssd"
)

// MasterVolumeBuilder builds master EBS volumes
Expand Down Expand Up @@ -118,11 +120,23 @@ func (b *MasterVolumeBuilder) Build(c *fi.ModelBuilderContext) error {
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)
volumeThroughput := fi.Int32Value(m.VolumeThroughput)
switch volumeType {
case "io1":
if volumeIops <= 0 {
if volumeIops <= 100 {
volumeIops = DefaultAWSEtcdVolumeIops
}
case "io2":
if volumeIops < 100 {
volumeIops = DefaultAWSEtcdVolumeIops
}
case "gp3":
if volumeIops < 3000 {
volumeIops = DefaultAWSEtcdVolumeGp3Iops
}
if volumeThroughput < 125 {
volumeThroughput = DefaultAWSEtcdVolumeGp3Throughput
}
default:
volumeType = DefaultAWSEtcdVolumeType
}
Expand Down Expand Up @@ -157,12 +171,23 @@ func (b *MasterVolumeBuilder) addAWSVolume(c *fi.ModelBuilderContext, name strin
Encrypted: fi.Bool(encrypted),
Tags: tags,
}
if volumeType == "io1" {
t.VolumeIops = i64(int64(volumeIops))

if strings.Contains(volumeType, "io") || volumeType == "gp3" {
// 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))
t.VolumeIops = i64(int64(volumeIops))
if volumeType == "io1" {
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))
}
} else {
if float64(*t.VolumeIops)/float64(*t.SizeGB) > 500.0 {
return fmt.Errorf("volumeIops to volumeSize ratio must be lower than 500. For %s ratio is %f", *t.Name, float64(*t.VolumeIops)/float64(*t.SizeGB))
}
}
if volumeType == "gp3" {
t.VolumeThroughput = i64(int64(volumeThroughput))
if float64(*t.VolumeThroughput)/float64(*t.VolumeIops) > 0.25 {
return fmt.Errorf("volumeThroughput to volumeIops ratio must be lower than 0.25. For %s ratio is %f", *t.Name, float64(*t.VolumeThroughput)/float64(*t.VolumeIops))
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions upup/pkg/fi/cloudup/awstasks/ebsvolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type EBSVolume struct {
SizeGB *int64
Tags map[string]string
VolumeIops *int64
VolumeThroughput *int64
VolumeType *string
}

Expand Down Expand Up @@ -105,6 +106,7 @@ func (e *EBSVolume) find(cloud awsup.AWSCloud) (*EBSVolume, error) {
Encrypted: v.Encrypted,
Name: e.Name,
VolumeIops: v.Iops,
VolumeThroughput: v.Throughput,
}

actual.Tags = mapEC2TagsToMap(v.Tags)
Expand Down Expand Up @@ -145,6 +147,7 @@ func (_ *EBSVolume) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *EBSVolume) e
KmsKeyId: e.KmsKeyId,
Encrypted: e.Encrypted,
Iops: e.VolumeIops,
Throughput: e.VolumeThroughput,
TagSpecifications: awsup.EC2TagSpecification(ec2.ResourceTypeVolume, e.Tags),
}

Expand Down Expand Up @@ -188,6 +191,7 @@ type terraformVolume struct {
Size *int64 `json:"size,omitempty" cty:"size"`
Type *string `json:"type,omitempty" cty:"type"`
Iops *int64 `json:"iops,omitempty" cty:"iops"`
Throughput *int64 `json:"throughput,omitempty" cty:"throughput"`
KmsKeyId *string `json:"kms_key_id,omitempty" cty:"kms_key_id"`
Encrypted *bool `json:"encrypted,omitempty" cty:"encrypted"`
Tags map[string]string `json:"tags,omitempty" cty:"tags"`
Expand All @@ -199,6 +203,7 @@ func (_ *EBSVolume) RenderTerraform(t *terraform.TerraformTarget, a, e, changes
Size: e.SizeGB,
Type: e.VolumeType,
Iops: e.VolumeIops,
Throughput: e.VolumeThroughput,
KmsKeyId: e.KmsKeyId,
Encrypted: e.Encrypted,
Tags: e.Tags,
Expand All @@ -216,6 +221,7 @@ type cloudformationVolume struct {
Size *int64 `json:"Size,omitempty"`
Type *string `json:"VolumeType,omitempty"`
Iops *int64 `json:"Iops,omitempty"`
Throughput *int64 `json:"Throughput,omitempty"`
KmsKeyId *string `json:"KmsKeyId,omitempty"`
Encrypted *bool `json:"Encrypted,omitempty"`
Tags []cloudformationTag `json:"Tags,omitempty"`
Expand All @@ -227,6 +233,7 @@ func (_ *EBSVolume) RenderCloudformation(t *cloudformation.CloudformationTarget,
Size: e.SizeGB,
Type: e.VolumeType,
Iops: e.VolumeIops,
Throughput: e.VolumeThroughput,
KmsKeyId: e.KmsKeyId,
Encrypted: e.Encrypted,
Tags: buildCloudformationTags(e.Tags),
Expand Down

0 comments on commit 2ccc6f4

Please sign in to comment.