Skip to content

Commit

Permalink
Initial command restructure
Browse files Browse the repository at this point in the history
Prior to adding 'create/get/delete nodegroup' some refactoring
has been done on the commands. We had a single file for all
the commands for that verb so this has been changed to separate
folders/files.

Signed-off-by: Richard Case <richard.case@outlook.com>
  • Loading branch information
richardcase committed Oct 17, 2018
1 parent e229797 commit a02e6a7
Show file tree
Hide file tree
Showing 16 changed files with 432 additions and 362 deletions.
27 changes: 10 additions & 17 deletions cmd/eksctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ package main
import (
"fmt"
"os"
"strings"

"github.com/kubicorn/kubicorn/pkg/logger"
"github.com/spf13/cobra"
"github.com/weaveworks/eksctl/pkg/commands/create"
"github.com/weaveworks/eksctl/pkg/commands/delete"
"github.com/weaveworks/eksctl/pkg/commands/get"
"github.com/weaveworks/eksctl/pkg/commands/scale"
"github.com/weaveworks/eksctl/pkg/commands/utils"
)

var rootCmd = &cobra.Command{
Expand Down Expand Up @@ -36,20 +40,9 @@ func main() {

func addCommands() {
rootCmd.AddCommand(versionCmd())
rootCmd.AddCommand(createCmd())
rootCmd.AddCommand(deleteCmd())
rootCmd.AddCommand(getCmd())
rootCmd.AddCommand(scaleCmd())
rootCmd.AddCommand(utilsCmd())
}

func getNameArg(args []string) string {
if len(args) > 1 {
logger.Critical("only one argument is allowed to be used as a name")
os.Exit(1)
}
if len(args) == 1 {
return (strings.TrimSpace(args[0]))
}
return ""
rootCmd.AddCommand(create.Command())
rootCmd.AddCommand(delete.Command())
rootCmd.AddCommand(get.Command())
rootCmd.AddCommand(scale.Command())
rootCmd.AddCommand(utils.Command())
}
251 changes: 0 additions & 251 deletions cmd/eksctl/utils.go

This file was deleted.

20 changes: 20 additions & 0 deletions pkg/commands/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package commands

import (
"os"
"strings"

"github.com/kubicorn/kubicorn/pkg/logger"
)

// GetNameArg tests to ensure there is only 1 name argument
func GetNameArg(args []string) string {
if len(args) > 1 {
logger.Critical("only one argument is allowed to be used as a name")
os.Exit(1)
}
if len(args) == 1 {
return (strings.TrimSpace(args[0]))
}
return ""
}
29 changes: 5 additions & 24 deletions cmd/eksctl/create.go → pkg/commands/create/cluster.go
Original file line number Diff line number Diff line change
@@ -1,40 +1,21 @@
package main
package create

import (
"fmt"
"os"

"github.com/kubicorn/kubicorn/pkg/logger"
"github.com/pkg/errors"
"github.com/spf13/cobra"

"github.com/kubicorn/kubicorn/pkg/logger"

"github.com/weaveworks/eksctl/pkg/ami"
"github.com/weaveworks/eksctl/pkg/commands"
"github.com/weaveworks/eksctl/pkg/eks"
"github.com/weaveworks/eksctl/pkg/eks/api"
"github.com/weaveworks/eksctl/pkg/utils"
"github.com/weaveworks/eksctl/pkg/utils/kubeconfig"
)

func createCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "create",
Short: "Create resource(s)",
Run: func(c *cobra.Command, _ []string) {
if err := c.Help(); err != nil {
logger.Debug("ignoring error %q", err.Error())
}
},
}

cmd.AddCommand(createClusterCmd())

return cmd
}

const (
// DefaultNodeCount defines the default number of nodes to be created
DefaultNodeCount = 2
defaultNodeType = "m5.large"
defaultSSHPublicKey = "~/.ssh/id_rsa.pub"
)
Expand All @@ -54,7 +35,7 @@ func createClusterCmd() *cobra.Command {
Use: "cluster",
Short: "Create a cluster",
Run: func(_ *cobra.Command, args []string) {
if err := doCreateCluster(cfg, getNameArg(args)); err != nil {
if err := doCreateCluster(cfg, commands.GetNameArg(args)); err != nil {
logger.Critical("%s\n", err.Error())
os.Exit(1)
}
Expand All @@ -72,7 +53,7 @@ func createClusterCmd() *cobra.Command {
fs.StringToStringVarP(&cfg.Tags, "tags", "", map[string]string{}, `A list of KV pairs used to tag the AWS resources (e.g. "Owner=John Doe,Team=Some Team")`)

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

// TODO: https://github.com/weaveworks/eksctl/issues/28
fs.IntVarP(&cfg.MinNodes, "nodes-min", "m", 0, "minimum nodes in ASG")
Expand Down
Loading

0 comments on commit a02e6a7

Please sign in to comment.