Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #14848: Validate control-plane IG size #14849

Merged
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
6 changes: 6 additions & 0 deletions pkg/apis/kops/validation/instancegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ func ValidateInstanceGroup(g *kops.InstanceGroup, cloud fi.Cloud, strict bool) f
if len(g.Spec.Subnets) == 0 {
allErrs = append(allErrs, field.Required(field.NewPath("spec", "subnets"), "master InstanceGroup must specify at least one Subnet"))
}
if fi.ValueOf(g.Spec.MinSize) > 1 {
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "minSize"), fi.ValueOf(g.Spec.MinSize), "master InstanceGroup must have minSize set to 1"))
}
if fi.ValueOf(g.Spec.MaxSize) > 1 {
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "maxSize"), fi.ValueOf(g.Spec.MaxSize), "master InstanceGroup must have maxSize set to 1, add more InstanceGroups instead"))
}
case kops.InstanceGroupRoleNode:
case kops.InstanceGroupRoleBastion:
case kops.InstanceGroupRoleAPIServer:
Expand Down
21 changes: 20 additions & 1 deletion pkg/apis/kops/validation/instancegroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func TestValidInstanceGroup(t *testing.T) {
},
},
ExpectedErrors: []string{},
Description: "Valid master instance group failed to validate",
Description: "Valid control-plane instance group failed to validate",
},
{
IG: &kops.InstanceGroup{
Expand Down Expand Up @@ -467,6 +467,25 @@ func TestValidInstanceGroup(t *testing.T) {
ExpectedErrors: []string{"Forbidden::spec.image"},
Description: "Valid instance group must have image set",
},
{
IG: &kops.InstanceGroup{
ObjectMeta: v1.ObjectMeta{
Name: "eu-central-1a",
},
Spec: kops.InstanceGroupSpec{
Role: kops.InstanceGroupRoleMaster,
Subnets: []string{"eu-central-1a"},
MaxSize: fi.PtrTo(int32(2)),
MinSize: fi.PtrTo(int32(2)),
Image: "my-image",
},
},
ExpectedErrors: []string{
"Invalid value::spec.minSize",
"Invalid value::spec.maxSize",
},
Description: "Invalid master instance group sizes",
},
}
for _, g := range grid {
errList := ValidateInstanceGroup(g.IG, nil, true)
Expand Down