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

ng alias for nodegroup resource #494

Merged
merged 2 commits into from
Jan 31, 2019
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
19 changes: 7 additions & 12 deletions pkg/ctl/cmdutils/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,21 @@ const (

// AddCommonCreateNodeGroupFlags adds common flags for creating a node group
func AddCommonCreateNodeGroupFlags(cmd *cobra.Command, fs *pflag.FlagSet, p *api.ProviderConfig, cfg *api.ClusterConfig, ng *api.NodeGroup) {
var desiredCapacity int
var minSize int
var maxSize int

fs.StringVarP(&ng.InstanceType, "node-type", "t", defaultNodeType, "node instance type")
fs.IntVarP(&desiredCapacity, "nodes", "N", api.DefaultNodeCount, "total number of nodes (for a static ASG)")

// TODO: https://github.com/weaveworks/eksctl/issues/28
fs.IntVarP(&minSize, "nodes-min", "m", api.DefaultNodeCount, "minimum nodes in ASG")
fs.IntVarP(&maxSize, "nodes-max", "M", api.DefaultNodeCount, "maximum nodes in ASG")
desiredCapacity := fs.IntP("nodes", "N", api.DefaultNodeCount, "total number of nodes (for a static ASG)")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mumoshu just FYI. I figured this was a little nicer without having to have the var block.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat! Thanks for sharing, and your work.

minSize := fs.IntP("nodes-min", "m", api.DefaultNodeCount, "minimum nodes in ASG")
maxSize := fs.IntP("nodes-max", "M", api.DefaultNodeCount, "maximum nodes in ASG")

cmd.PreRun = func(cmd *cobra.Command, args[] string) {
cmd.PreRun = func(cmd *cobra.Command, args []string) {
if f := cmd.Flag("nodes"); f.Changed {
ng.DesiredCapacity = &desiredCapacity
ng.DesiredCapacity = desiredCapacity
}
if f := cmd.Flag("nodes-min"); f.Changed {
ng.MinSize= &minSize
ng.MinSize = minSize
}
if f := cmd.Flag("nodes-max"); f.Changed {
ng.MaxSize= &maxSize
ng.MaxSize = maxSize
}
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/ctl/create/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ func createNodeGroupCmd(g *cmdutils.Grouping) *cobra.Command {
ng := cfg.NewNodeGroup()

cmd := &cobra.Command{
Use: "nodegroup",
Short: "Create a nodegroup",
Use: "nodegroup",
Short: "Create a nodegroup",
Aliases: []string{"ng"},
Run: func(_ *cobra.Command, args []string) {
if err := doCreateNodeGroup(p, cfg, ng, cmdutils.GetNameArg(args)); err != nil {
logger.Critical("%s\n", err.Error())
Expand Down
5 changes: 3 additions & 2 deletions pkg/ctl/delete/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ func deleteNodeGroupCmd(g *cmdutils.Grouping) *cobra.Command {
ng := cfg.NewNodeGroup()

cmd := &cobra.Command{
Use: "nodegroup",
Short: "Delete a nodegroup",
Use: "nodegroup",
Short: "Delete a nodegroup",
Aliases: []string{"ng"},
Run: func(_ *cobra.Command, args []string) {
if err := doDeleteNodeGroup(p, cfg, ng, cmdutils.GetNameArg(args)); err != nil {
logger.Critical("%s\n", err.Error())
Expand Down
2 changes: 1 addition & 1 deletion pkg/ctl/get/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func getNodegroupCmd(g *cmdutils.Grouping) *cobra.Command {
cmd := &cobra.Command{
Use: "nodegroup",
Short: "Get nodegroups(s)",
Aliases: []string{"nodegroups"},
Aliases: []string{"ng"},
Run: func(_ *cobra.Command, args []string) {
if err := doGetNodegroups(p, cfg, ng, cmdutils.GetNameArg(args)); err != nil {
logger.Critical("%s\n", err.Error())
Expand Down
12 changes: 6 additions & 6 deletions pkg/ctl/scale/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ func scaleNodeGroupCmd(g *cmdutils.Grouping) *cobra.Command {
ng := cfg.NewNodeGroup()

cmd := &cobra.Command{
Use: "nodegroup",
Short: "Scale a nodegroup",
Use: "nodegroup",
Short: "Scale a nodegroup",
Aliases: []string{"ng"},
Run: func(_ *cobra.Command, args []string) {
if err := doScaleNodeGroup(p, cfg, ng, cmdutils.GetNameArg(args)); err != nil {
logger.Critical("%s\n", err.Error())
Expand All @@ -35,11 +36,10 @@ func scaleNodeGroupCmd(g *cmdutils.Grouping) *cobra.Command {
fs.StringVar(&cfg.Metadata.Name, "cluster", "", "EKS cluster name")
fs.StringVarP(&ng.Name, "name", "n", "", "Name of the nodegroup to scale")

var desiredCapacity int
fs.IntVarP(&desiredCapacity, "nodes", "N", -1, "total number of nodes (scale to this number)")
cmd.PreRun = func(cmd *cobra.Command, args[] string) {
desiredCapacity := fs.IntP("nodes", "N", -1, "total number of nodes (scale to this number)")
cmd.PreRun = func(cmd *cobra.Command, args []string) {
if f := cmd.Flag("nodes"); f.Changed {
ng.DesiredCapacity = &desiredCapacity
ng.DesiredCapacity = desiredCapacity
}
}

Expand Down
7 changes: 3 additions & 4 deletions pkg/ctl/utils/wait_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ func waitNodesCmd(g *cmdutils.Grouping) *cobra.Command {

group.InFlagSet("General", func(fs *pflag.FlagSet) {
fs.StringVar(&waitNodesKubeconfigPath, "kubeconfig", "kubeconfig", "path to read kubeconfig")
var minSize int
fs.IntVarP(&minSize, "nodes-min", "m", api.DefaultNodeCount, "minimum number of nodes to wait for")
cmd.PreRun = func(cmd *cobra.Command, args[] string) {
minSize := fs.IntP("nodes-min", "m", api.DefaultNodeCount, "minimum number of nodes to wait for")
cmd.PreRun = func(cmd *cobra.Command, args []string) {
if f := cmd.Flag("nodes-min"); f.Changed {
ng.MinSize = &minSize
ng.MinSize = minSize
}
}
fs.DurationVar(&p.WaitTimeout, "timeout", api.DefaultWaitTimeout, "how long to wait")
Expand Down
2 changes: 0 additions & 2 deletions pkg/eks/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ func (c *ClusterProvider) CheckAuth() error {

// EnsureAMI ensures that the node AMI is set and is available
func (c *ClusterProvider) EnsureAMI(version string, ng *api.NodeGroup) error {
// TODO: https://github.com/weaveworks/eksctl/issues/28
// - improve validation of parameter set overall, probably in another package
if ng.AMI == ami.ResolverAuto {
ami.DefaultResolvers = []ami.Resolver{ami.NewAutoResolver(c.Provider.EC2())}
}
Expand Down