Skip to content

Commit

Permalink
starting to work on create
Browse files Browse the repository at this point in the history
  • Loading branch information
richardcase committed Oct 25, 2018
1 parent 022a5b5 commit a677a82
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
33 changes: 33 additions & 0 deletions pkg/cfn/manager/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ func (c *StackCollection) CreateInitialNodeGroup(errs chan error) error {
return c.CreateNodeGroup(0, errs)
}

// CreateNextNodeGroup creates a node group with the next sequence number
func (c *StackCollection) CreateNextNodeGroup(errs chan error) error {
currentSeq, err := c.GetMaxNodeGroupSeq()
if err != nil {
return errors.Wrap(err, "getting current node group sequence")
}
logger.Debug("max node group sequence: %d", currentSeq)

newSeq := currentSeq + 1
logger.Info("new node group sequence number: %d", newSeq)

return c.CreateNodeGroup(newSeq, errs)
}

// CreateNodeGroup creates the node group
func (c *StackCollection) CreateNodeGroup(seq int, errs chan error) error {
name := c.makeNodeGroupStackName(seq)
Expand Down Expand Up @@ -130,6 +144,24 @@ func (c *StackCollection) ScaleNodeGroup(sequence int) error {
return c.UpdateStack(name, "scale-nodegroup", descriptionBuffer.String(), []byte(template), nil)
}

// GetMaxNodeGroupSeq returns the sequence number og the highest node group
func (c *StackCollection) GetMaxNodeGroupSeq() (int, error) {
stacks, err := c.ListStacks(fmt.Sprintf("^(eksctl|EKS)-%s-nodegroup-\\d+$", c.spec.ClusterName))
if err != nil {
return -1, errors.Wrap(err, "getting nodegroup stacks")
}

seq := -1
for _, stack := range stacks {
stackSeq := getNodeGroupID(stack.Tags)
if stackSeq > seq {
seq = stackSeq
}
}

return seq, nil
}

// GetNodeGroupSummaries returns a list of summaries for the nodegroups of a cluster
func (c *StackCollection) GetNodeGroupSummaries() ([]*NodeGroupSummary, error) {
stacks, err := c.ListStacks(fmt.Sprintf("^(eksctl|EKS)-%s-nodegroup-\\d+$", c.spec.ClusterName), cloudformation.StackStatusCreateComplete)
Expand All @@ -147,6 +179,7 @@ func (c *StackCollection) GetNodeGroupSummaries() ([]*NodeGroupSummary, error) {
return nil, errors.Wrapf(err, "error getting Cloudformation template for stack %s", *stack.StackName)
}

//TODO: create a map function
seq := getNodeGroupID(stack.Tags)
maxSize := gjson.Get(template, maxSizePath)
minSize := gjson.Get(template, minSizePath)
Expand Down
15 changes: 13 additions & 2 deletions pkg/ctl/create/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"os"

"github.com/weaveworks/eksctl/pkg/cfn/manager"

"github.com/kubicorn/kubicorn/pkg/logger"
"github.com/spf13/cobra"
"github.com/weaveworks/eksctl/pkg/ctl"
Expand Down Expand Up @@ -71,6 +73,7 @@ func doAddNodeGroup(cfg *api.ClusterConfig, name string) error {

logger.Debug("cfg = %#v", cfg)

// Check the cluster exists and is active
eksCluster, err := ctl.DescribeControlPlane()
if err != nil {
return err
Expand All @@ -81,9 +84,17 @@ func doAddNodeGroup(cfg *api.ClusterConfig, name string) error {
logger.Info("found cluster %s", eksCluster.Name)
logger.Debug("cluster = %#v", eksCluster)

//TODO: get the next nodegroup sequnce number
errs := []error{}
appendErr := func(err error) {
errs = append(errs, err)
}

stackManager := ctl.NewStackManager()
if manager.Run(appendErr, stackManager.CreateNextNodeGroup); len(errs) > 0 {
//TODO: how to handle this????
//return errs
}

//TODO: finish
return nil

}

0 comments on commit a677a82

Please sign in to comment.