Skip to content

Commit

Permalink
Refactor nodegroup validation, check IAM attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper committed Jan 18, 2019
1 parent 3d4f452 commit d449a7f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
33 changes: 33 additions & 0 deletions pkg/apis/eksctl.io/v1alpha3/validation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package v1alpha3

import (
"fmt"
)

func ValidateNodeGroup(i int, ng *NodeGroup) error {
path := fmt.Errorf("nodegroups[%d]", i)
if ng.Name == "" {
return fmt.Errorf("%s.name must be set", path)
}

if ng.IAM.InstanceRoleARN != "" {
p := fmt.Sprintf("%s.iam.instanceRoleARN and %s.iam", path, path)
if ng.IAM.InstanceRoleName != "" {
return fmt.Errorf("%s.instanceRoleName cannot be set at the same time", p)
}
if len(ng.IAM.AttachPolicyARNs) != 0 {
return fmt.Errorf("%s.attachPolicyARNs cannot be set at the same time", p)
}
if ng.IAM.WithAddonPolicies.AutoScaler {
return fmt.Errorf("%s.withAddonPolicies.autoScaler cannot be set at the same time", p)
}
if ng.IAM.WithAddonPolicies.ExternalDNS {
return fmt.Errorf("%s.withAddonPolicies.externalDNS cannot be set at the same time", p)
}
if ng.IAM.WithAddonPolicies.ImageBuilder {
return fmt.Errorf("%s.imageBuilder cannot be set at the same time", p)
}
}

return nil
}
7 changes: 5 additions & 2 deletions pkg/ctl/create/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,11 @@ func doCreateCluster(p *api.ProviderConfig, cfg *api.ClusterConfig, nameArg stri
}

err := checkEachNodeGroup(cfg, func(i int, ng *api.NodeGroup) error {
if ng.Name == "" {
return fmt.Errorf("nodegroups[%d].name must be set", i)
if err := api.ValidateNodeGroup(i, ng); err != nil {
return err
}

// apply defaults
if ng.InstanceType == "" {
ng.InstanceType = api.DefaultNodeType
}
Expand All @@ -218,6 +220,7 @@ func doCreateCluster(p *api.ProviderConfig, cfg *api.ClusterConfig, nameArg stri
ng.VolumeType = api.DefaultNodeVolumeType
}
}

return nil
})
if err != nil {
Expand Down

0 comments on commit d449a7f

Please sign in to comment.