Skip to content

Commit

Permalink
More consistent naming and style
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper authored and richardcase committed Oct 16, 2018
1 parent 541df2f commit 32b9558
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 38 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,17 @@ To delete a cluster, run:
eksctl delete cluster --name=<name> [--region=<region>]
```
### Scaling
A node group can be scaled by using the `scale nodegroup` command. For example, to scale to 5 nodes:
A nodegroup can be scaled by using the `scale nodegroup` command. For example, to scale to 5 nodes:

```
eksctl scale nodegroup --name=<clustername> --nodes=5
```

If the desired number of nodes is greater than the current maximum set on the ASG then the max value will be increased to match the number of requested nodes. And likewise for the minimum.

Scaling a node group works by modifying the node group CloudFormation template. The modified template is applied by creating and executing a CloudFormation changeset.
Scaling a nodegroup works by modifying the nodegroup CloudFormation template. The modified template is applied by creating and executing a CloudFormation changeset.

> Scaling a node group down/in (i.e. reducing the number of nodes) may result in errors as we rely purely on changes to the ASG. This means that the node(s) being removed/terminated aren't explicitly drained. This may be an area for improvement in the future.
> Scaling a nodegroup down/in (i.e. reducing the number of nodes) may result in errors as we rely purely on changes to the ASG. This means that the node(s) being removed/terminated aren't explicitly drained. This may be an area for improvement in the future.
### GPU Support

Expand Down
78 changes: 45 additions & 33 deletions pkg/cfn/manager/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ const (
NodeGroupIDTag = "eksctl.cluster.k8s.io/v1alpha1/nodegroup-id"
)

var (
stackCapabilitiesIAM = aws.StringSlice([]string{cloudformation.CapabilityCapabilityIam})
)

// Stack represents the CloudFormation stack
type Stack = cloudformation.Stack

// ChangeSet represents a Cloudformation changeset
// ChangeSet represents a Cloudformation changeSet
type ChangeSet = cloudformation.DescribeChangeSetOutput

// StackCollection stores the CloudFormation stack information
Expand Down Expand Up @@ -66,7 +70,7 @@ func (c *StackCollection) doCreateStackRequest(i *Stack, templateBody []byte, pa
input.SetTemplateBody(string(templateBody))

if withIAM {
input.SetCapabilities(aws.StringSlice([]string{cloudformation.CapabilityCapabilityIam}))
input.SetCapabilities(stackCapabilitiesIAM)
}

for k, v := range parameters {
Expand Down Expand Up @@ -108,26 +112,26 @@ func (c *StackCollection) CreateStack(name string, stack builder.ResourceSet, pa
return nil
}

// UpdateStack will update a cloudformation stack. It uses changesets and if in debug it will log the changes.
// UpdateStack will update a cloudformation stack. It uses changeSets and if in debug it will log the changes.
// This is used bu things like nodegroup scaling
func (c *StackCollection) UpdateStack(stackName string, action string, description string, template []byte, parameters map[string]string) error {
logger.Info(description)
i := &Stack{StackName: &stackName}
changesetName, err := c.doCreateChangesetRequest(i, action, description, template, parameters, true)
changeSetName, err := c.doCreateChangeSetRequest(i, action, description, template, parameters, true)
if err != nil {
return err
}
err = c.doWaitUntilChangeSetIsCreated(i, &changesetName)
err = c.doWaitUntilChangeSetIsCreated(i, &changeSetName)
if err != nil {
return err
}
changeset, err := c.describeStackChangeset(i, &changesetName)
changeSet, err := c.describeStackChangeSet(i, &changeSetName)
if err != nil {
return err
}
logger.Debug("changes = %#v", changeset.Changes)
if err := c.doExecuteChangeset(stackName, changesetName); err != nil {
logger.Warning("error executing Cloudformation changeset %s in stack %s. Check the Cloudformation console for further details", changesetName, stackName)
logger.Debug("changes = %#v", changeSet.Changes)
if err := c.doExecuteChangeSet(stackName, changeSetName); err != nil {
logger.Warning("error executing Cloudformation changeSet %s in stack %s. Check the Cloudformation console for further details", changeSetName, stackName)
return err
}
return c.doWaitUntilStackIsUpdated(i)
Expand Down Expand Up @@ -250,60 +254,68 @@ func (c *StackCollection) DescribeStackEvents(i *Stack) ([]*cloudformation.Stack
return resp.StackEvents, nil
}

func (c *StackCollection) doCreateChangesetRequest(i *Stack, action string, description string, templateBody []byte,
func (c *StackCollection) doCreateChangeSetRequest(i *Stack, action string, description string, templateBody []byte,
parameters map[string]string, withIAM bool) (string, error) {

changesetName := fmt.Sprintf("eksctl-%s-%d", action, time.Now().Unix())
changeSetName := fmt.Sprintf("eksctl-%s-%d", action, time.Now().Unix())

input := &cloudformation.CreateChangeSetInput{
StackName: i.StackName,
ChangeSetName: &changeSetName,
Description: &description,
}

input.SetChangeSetType(cloudformation.ChangeSetTypeUpdate)

input := &cloudformation.CreateChangeSetInput{}
input.SetChangeSetName(changesetName)
input.SetChangeSetType("UPDATE")
input.SetDescription(description)
input.SetStackName(*i.StackName)
input.SetTags(c.tags)
input.SetTemplateBody(string(templateBody))

if withIAM {
input.SetCapabilities(aws.StringSlice([]string{cloudformation.CapabilityCapabilityIam}))
input.SetCapabilities(stackCapabilitiesIAM)
}

for k, v := range parameters {
p := &cloudformation.Parameter{
ParameterKey: aws.String(k),
ParameterValue: aws.String(v),
}
input.Parameters = append(input.Parameters, p)
}
logger.Debug("creating changeset, input = %#v", input)

logger.Debug("creating changeSet, input = %#v", input)
s, err := c.cfn.CreateChangeSet(input)
if err != nil {
return "", errors.Wrap(err, fmt.Sprintf("creating changest %q for stack %q", changesetName, *i.StackName))
return "", errors.Wrap(err, fmt.Sprintf("creating ChangeSet %q for stack %q", changeSetName, *i.StackName))
}
logger.Debug("changeset = %#v", s)
return changesetName, nil
logger.Debug("changeSet = %#v", s)
return changeSetName, nil
}
func (c *StackCollection) doExecuteChangeset(stackName string, changesetName string) error {
input := &cloudformation.ExecuteChangeSetInput{}
input.SetChangeSetName(changesetName)
input.SetStackName(stackName)
logger.Debug("executing changeset, input = %#v", input)
output, err := c.cfn.ExecuteChangeSet(input)
if err != nil {
return errors.Wrapf(err, "executing CloudFormation changeset %q for stack %q", changesetName, stackName)

func (c *StackCollection) doExecuteChangeSet(stackName string, changeSetName string) error {
input := &cloudformation.ExecuteChangeSetInput{
ChangeSetName: &changeSetName,
StackName: &stackName,
}

logger.Debug("executing changeSet, input = %#v", input)

if _, err := c.cfn.ExecuteChangeSet(input); err != nil {
return errors.Wrapf(err, "executing CloudFormation ChangeSet %q for stack %q", changeSetName, stackName)
}
logger.Debug("execute changeset = %#v", output)
return nil
}

func (c *StackCollection) describeStackChangeset(i *Stack, changesetName *string) (*ChangeSet, error) {
func (c *StackCollection) describeStackChangeSet(i *Stack, changeSetName *string) (*ChangeSet, error) {
input := &cloudformation.DescribeChangeSetInput{
StackName: i.StackName,
ChangeSetName: changesetName,
ChangeSetName: changeSetName,
}
if i.StackId != nil {
input.StackName = i.StackId
}
resp, err := c.cfn.DescribeChangeSet(input)
if err != nil {
return nil, errors.Wrapf(err, "describing CloudFormation changeset %s for stack %s", *changesetName, *i.StackName)
return nil, errors.Wrapf(err, "describing CloudFormation ChangeSet %s for stack %s", *changeSetName, *i.StackName)
}
return resp, nil
}
4 changes: 2 additions & 2 deletions pkg/cfn/manager/waiters.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ func (c *StackCollection) waitWithAcceptorsChangeSet(i *Stack, changesetName *st
}
logger.Debug("start %s", msg)
if waitErr := w.WaitWithContext(ctx); waitErr != nil {
s, err := c.describeStackChangeset(i, changesetName)
s, err := c.describeStackChangeSet(i, changesetName)
if err != nil {
logger.Debug("describeChangesetErr=%v", err)
logger.Debug("describeChangeSetErr=%v", err)
} else {
logger.Critical("unexpected status %q while %s, reason %s", *s.Status, msg, *s.StatusReason)
}
Expand Down

0 comments on commit 32b9558

Please sign in to comment.