Skip to content

Commit

Permalink
Improve command description, add --dry-run
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper committed Jan 17, 2019
1 parent 897ad96 commit 2b52096
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 5 additions & 1 deletion pkg/cfn/manager/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (c *StackCollection) WaitDeleteCluster() error {

// AppendNewClusterStackResource will update cluster
// stack with new resources in append-only way
func (c *StackCollection) AppendNewClusterStackResource() error {
func (c *StackCollection) AppendNewClusterStackResource(dryRun bool) error {
name := c.makeClusterStackName()

// NOTE: currently we can only append new resources to the stack,
Expand Down Expand Up @@ -138,6 +138,10 @@ func (c *StackCollection) AppendNewClusterStackResource() error {
logger.Debug("currentTemplate = %s", currentTemplate)

describeUpdate := fmt.Sprintf("updating stack to add new resources %v and ouputs %v", addResources, addOutputs)
if dryRun {
logger.Info("(dry-run) %s", describeUpdate)
return nil
}
return c.UpdateStack(name, "update-cluster", describeUpdate, []byte(currentTemplate), nil)
}

Expand Down
10 changes: 8 additions & 2 deletions pkg/ctl/utils/update_cluster_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import (
"github.com/weaveworks/eksctl/pkg/eks"
)

var updateClusterStackDryRun = true

func updateClusterStackCmd(g *cmdutils.Grouping) *cobra.Command {
p := &api.ProviderConfig{}
cfg := api.NewClusterConfig()

cmd := &cobra.Command{
Use: "update-cluster-stack",
Short: "Update cluster stack based on latest configuration",
Short: "Update cluster stack based on latest configuration (append-only)",
Run: func(_ *cobra.Command, args []string) {
if err := doUpdateClusterStacksCmd(p, cfg, cmdutils.GetNameArg(args)); err != nil {
logger.Critical("%s\n", err.Error())
Expand All @@ -36,6 +38,7 @@ func updateClusterStackCmd(g *cmdutils.Grouping) *cobra.Command {
fs.StringVarP(&cfg.Metadata.Name, "name", "n", "", "EKS cluster name (required)")
cmdutils.AddRegionFlag(fs, p)
cmdutils.AddVersionFlag(fs, cfg.Metadata)
fs.BoolVar(&updateClusterStackDryRun, "dry-run", updateClusterStackDryRun, "do not apply any change, only show what resources would be added")
})

cmdutils.AddCommonFlagsForAWS(group, p, false)
Expand Down Expand Up @@ -69,13 +72,16 @@ func doUpdateClusterStacksCmd(p *api.ProviderConfig, cfg *api.ClusterConfig, nam

stackManager := ctl.NewStackManager(cfg)

if err := stackManager.AppendNewClusterStackResource(); err != nil {
if err := stackManager.AppendNewClusterStackResource(updateClusterStackDryRun); err != nil {
return err
}

if err := ctl.ValidateExistingNodeGroupsForCompatibility(cfg, stackManager); err != nil {
logger.Critical("failed checking nodegroups", err.Error())
}

if updateClusterStackDryRun {
logger.Warning("no changes were applied, run again with '--dry-run=false' to apply the changes")
}
return nil
}

0 comments on commit 2b52096

Please sign in to comment.