Skip to content

Commit

Permalink
Validation around IOPS fields
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeylanzman committed Apr 2, 2018
1 parent 3d1e9bd commit dc4a1a3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pkg/apis/kops/validation/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ func validateEtcdMemberUpdate(fp *field.Path, obj *kops.EtcdMemberSpec, status *
allErrs = append(allErrs, field.Forbidden(fp.Child("VolumeType"), "VolumeType cannot be changed"))
}

if fi.Int32Value(obj.VolumeIops) != fi.Int32Value(old.VolumeIops) {
allErrs = append(allErrs, field.Forbidden(fp.Child("VolumeIops"), "VolumeIops cannot be changed"))
}

if fi.Int32Value(obj.VolumeSize) != fi.Int32Value(old.VolumeSize) {
allErrs = append(allErrs, field.Forbidden(fp.Child("VolumeSize"), "VolumeSize cannot be changed"))
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/kops/validation/instancegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/pkg/apis/kops/util"
"k8s.io/kops/upup/pkg/fi"
)

func ValidateInstanceGroup(g *kops.InstanceGroup) error {
Expand All @@ -45,6 +46,10 @@ func ValidateInstanceGroup(g *kops.InstanceGroup) error {
}
}

if fi.Int32Value(g.Spec.RootVolumeIops) < 0 {
return field.Invalid(field.NewPath("RootVolumeIops"), g.Spec.RootVolumeIops, "RootVolumeIops must be greater than 0")
}

switch g.Spec.Role {
case kops.InstanceGroupRoleMaster:
case kops.InstanceGroupRoleNode:
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/awsmodel/autoscalinggroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (b *AutoscalingGroupModelBuilder) Build(c *fi.ModelBuilderContext) error {
}

volumeIops := fi.Int32Value(ig.Spec.RootVolumeIops)
if volumeIops == 0 {
if volumeIops <= 0 {
volumeIops = DefaultVolumeIops
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/model/master_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (b *MasterVolumeBuilder) addAWSVolume(c *fi.ModelBuilderContext, name strin
volumeIops := fi.Int32Value(m.VolumeIops)
switch volumeType {
case "io1":
if volumeIops == 0 {
if volumeIops <= 0 {
volumeIops = DefaultAWSEtcdVolumeIops
}
default:
Expand Down

0 comments on commit dc4a1a3

Please sign in to comment.