Skip to content

Commit

Permalink
Use new loader in eksctl create ng
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper committed Mar 28, 2019
1 parent fe705ad commit bec8ad3
Showing 1 changed file with 9 additions and 84 deletions.
93 changes: 9 additions & 84 deletions pkg/ctl/create/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ func createNodeGroupCmd(g *cmdutils.Grouping) *cobra.Command {

group := g.New(cmd)

exampleNodeGroupName := NodeGroupName("", "")
exampleNodeGroupName := cmdutils.NodeGroupName("", "")

group.InFlagSet("General", func(fs *pflag.FlagSet) {
fs.StringVar(&cfg.Metadata.Name, "cluster", "", "name of the EKS cluster to add the nodegroup to")
cmdutils.AddRegionFlag(fs, p)
cmdutils.AddVersionFlag(fs, cfg.Metadata, `for nodegroups "auto" and "latest" can be used to automatically inherit version from the control plane or force latest`)
fs.StringVarP(&clusterConfigFile, "config-file", "f", "", "load configuration from a file")
cmdutils.AddConfigFileFlag(&clusterConfigFile, fs)

fs.StringSliceVar(&nodeGroupOnlyFilters, "only", nil,
"select a subset of nodegroups via comma-separted list of globs, e.g.: 'ng-*,nodegroup?,N*group'")
Expand All @@ -74,94 +74,19 @@ func createNodeGroupCmd(g *cmdutils.Grouping) *cobra.Command {
}

func doCreateNodeGroups(p *api.ProviderConfig, cfg *api.ClusterConfig, nameArg string, cmd *cobra.Command) error {
meta := cfg.Metadata

printer := printers.NewJSONPrinter()
ngFilter := cmdutils.NewNodeGroupFilter()
ngFilter.SkipAll = withoutNodeGroup

if err := api.Register(); err != nil {
if err := cmdutils.NewCreateNodeGroupLoader(p, cfg, clusterConfigFile, nameArg, cmd, ngFilter, nodeGroupOnlyFilters).Load(); err != nil {
return err
}

ngFilter := cmdutils.NewNodeGroupFilter()

if clusterConfigFile != "" {
if err := eks.LoadConfigFromFile(clusterConfigFile, cfg); err != nil {
return err
}
meta = cfg.Metadata

if meta.Name == "" {
return fmt.Errorf("metadata.name must be set")
}

if meta.Region == "" {
return fmt.Errorf("metadata.region must be set")
}

p.Region = meta.Region

incompatibleFlags := []string{
"name",
"cluster",
"version",
"region",
"nodes",
"nodes-min",
"nodes-max",
"node-type",
"node-volume-size",
"node-volume-type",
"max-pods-per-node",
"node-ami",
"node-ami-family",
"ssh-access",
"ssh-public-key",
"node-private-networking",
"node-security-groups",
"node-labels",
"node-zones",
"asg-access",
"external-dns-access",
"full-ecr-access",
}

for _, f := range incompatibleFlags {
if cmd.Flag(f).Changed {
return fmt.Errorf("cannot use --%s when --config-file/-f is set", f)
}
}

if err := ngFilter.ApplyOnlyFilter(nodeGroupOnlyFilters, cfg); err != nil {
return err
}

if err := ngFilter.CheckEachNodeGroup(cfg.NodeGroups, NewNodeGroupChecker); err != nil {
return err
}
} else {
// validation and defaulting specific to when --config-file is unused

if cfg.Metadata.Name == "" {
return errors.New("--cluster must be set")
}

incompatibleFlags := []string{
"only",
}

for _, f := range incompatibleFlags {
if cmd.Flag(f).Changed {
return fmt.Errorf("cannot use --%s unless a config file is specified via --config-file/-f", f)
}
return nil
}

if err := configureNodeGroups(ngFilter, cfg.NodeGroups, cmd); err != nil {
return err
}

if err := ngFilter.ValidateNodeGroupsAndSetDefaults(cfg.NodeGroups); err != nil {
return err
}

meta := cfg.Metadata
printer := printers.NewJSONPrinter()
ctl := eks.New(p, cfg)

if !ctl.IsSupportedRegion() {
Expand Down

0 comments on commit bec8ad3

Please sign in to comment.