Skip to content

Commit 1b5ef8e

Browse files
committed
Update validation to allow role=apiserver on GCE
1 parent 75f5922 commit 1b5ef8e

2 files changed

Lines changed: 68 additions & 2 deletions

File tree

pkg/apis/kops/validation/instancegroup.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ func CrossValidateInstanceGroup(g *kops.InstanceGroup, cluster *kops.Cluster, cl
239239
}
240240

241241
if g.Spec.Role == kops.InstanceGroupRoleAPIServer {
242-
if cluster.GetCloudProvider() != kops.CloudProviderAWS {
243-
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "role"), "APIServer role only supported on AWS"))
242+
if cluster.GetCloudProvider() != kops.CloudProviderAWS && cluster.GetCloudProvider() != kops.CloudProviderGCE {
243+
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "role"), "APIServer role only supported on AWS and GCE"))
244244
}
245245
if cluster.UsesNoneDNS() {
246246
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "role"), "APIServer cannot be used with topology.dns.type=None"))

pkg/apis/kops/validation/instancegroup_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,3 +510,69 @@ func createMinimalInstanceGroup() *kops.InstanceGroup {
510510
}
511511
return ig
512512
}
513+
514+
func TestCrossValidateAPIServerRole(t *testing.T) {
515+
grid := []struct {
516+
Description string
517+
Cluster *kops.Cluster
518+
ExpectedErrors int
519+
}{
520+
{
521+
Description: "APIServer role allowed on AWS",
522+
Cluster: &kops.Cluster{
523+
Spec: kops.ClusterSpec{
524+
CloudProvider: kops.CloudProviderSpec{
525+
AWS: &kops.AWSSpec{},
526+
},
527+
},
528+
},
529+
ExpectedErrors: 0,
530+
},
531+
{
532+
Description: "APIServer role allowed on GCE",
533+
Cluster: &kops.Cluster{
534+
Spec: kops.ClusterSpec{
535+
CloudProvider: kops.CloudProviderSpec{
536+
GCE: &kops.GCESpec{},
537+
},
538+
},
539+
},
540+
ExpectedErrors: 0,
541+
},
542+
{
543+
Description: "APIServer role forbidden on DO",
544+
Cluster: &kops.Cluster{
545+
Spec: kops.ClusterSpec{
546+
CloudProvider: kops.CloudProviderSpec{
547+
DO: &kops.DOSpec{},
548+
},
549+
},
550+
},
551+
ExpectedErrors: 1,
552+
},
553+
}
554+
555+
for _, g := range grid {
556+
t.Run(g.Description, func(t *testing.T) {
557+
ig := &kops.InstanceGroup{
558+
ObjectMeta: v1.ObjectMeta{
559+
Name: "apiserver",
560+
},
561+
Spec: kops.InstanceGroupSpec{
562+
Role: kops.InstanceGroupRoleAPIServer,
563+
Subnets: []string{"eu-central-1a"},
564+
MaxSize: fi.PtrTo(int32(1)),
565+
MinSize: fi.PtrTo(int32(1)),
566+
Image: "my-image",
567+
},
568+
}
569+
g.Cluster.Spec.Networking.Subnets = []kops.ClusterSubnetSpec{
570+
{Name: "eu-central-1a", Region: "eu-central-1"},
571+
}
572+
errs := CrossValidateInstanceGroup(ig, g.Cluster, nil, true)
573+
if len(errs) != g.ExpectedErrors {
574+
t.Errorf("expected %d errors, got %d: %v", g.ExpectedErrors, len(errs), errs)
575+
}
576+
})
577+
}
578+
}

0 commit comments

Comments
 (0)