Skip to content

Commit

Permalink
Add simple capability for filtering existing nodegroups
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper committed Mar 25, 2019
1 parent f4737a5 commit 4ddb027
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
23 changes: 20 additions & 3 deletions pkg/cfn/manager/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package manager
import (
"sync"

"k8s.io/apimachinery/pkg/util/sets"

"github.com/kris-nova/logger"

api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha4"
Expand Down Expand Up @@ -65,23 +67,38 @@ func (c *StackCollection) CreateClusterWithNodeGroups() []error {
return errs
}

return c.CreateAllNodeGroups()
return c.CreateAllNodeGroups(false)
}

// CreateAllNodeGroups runs all tasks required to create the node groups;
// any errors will be returned as a slice as soon as one of the tasks
// or group of tasks is completed
func (c *StackCollection) CreateAllNodeGroups() []error {
func (c *StackCollection) CreateAllNodeGroups(ignoreExisting bool) []error {
errs := []error{}
appendErr := func(err error) {
errs = append(errs, err)
}

existing := sets.NewString()

if ignoreExisting {
existingStacks, err := c.DescribeNodeGroupStacks()
if err != nil {
return []error{err}
}
for _, s := range existingStacks {
existing.Insert(getNodeGroupName(s))
}
}
createAllNodeGroups := []Task{}
for i := range c.spec.NodeGroups {
ng := c.spec.NodeGroups[i]
t := Task{
Call: c.CreateNodeGroup,
Data: c.spec.NodeGroups[i],
Data: ng,
}
if existing.Has(ng.Name) {
continue
}
createAllNodeGroups = append(createAllNodeGroups, t)
}
Expand Down
8 changes: 5 additions & 3 deletions pkg/ctl/create/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import (
)

var (
updateAuthConfigMap bool
nodeGroupFilter = ""
updateAuthConfigMap bool
nodeGroupFilter = ""
nodeGroupIgnoreExisting bool
)

func createNodeGroupCmd(g *cmdutils.Grouping) *cobra.Command {
Expand Down Expand Up @@ -54,6 +55,7 @@ func createNodeGroupCmd(g *cmdutils.Grouping) *cobra.Command {
fs.StringVarP(&clusterConfigFile, "config-file", "f", "", "load configuration from a file")
fs.StringVarP(&nodeGroupFilter, "only", "", "",
"select a subset of nodegroups via comma-separted list of globs, e.g.: 'ng-*,nodegroup?,N*group'")
fs.BoolVar(&nodeGroupIgnoreExisting, "ignore-existing", false, "ignore all existing nodegroups")
cmdutils.AddUpdateAuthConfigMap(&updateAuthConfigMap, fs, "Remove nodegroup IAM role from aws-auth configmap")
})

Expand Down Expand Up @@ -290,7 +292,7 @@ func doCreateNodeGroups(p *api.ProviderConfig, cfg *api.ClusterConfig, nameArg s

{
logger.Info("will create a CloudFormation stack for each of %d nodegroups in cluster %q", len(cfg.NodeGroups), cfg.Metadata.Name)
errs := stackManager.CreateAllNodeGroups()
errs := stackManager.CreateAllNodeGroups(nodeGroupIgnoreExisting)
if len(errs) > 0 {
logger.Info("%d error(s) occurred and nodegroups haven't been created properly, you may wish to check CloudFormation console", len(errs))
logger.Info("to cleanup resources, run 'eksctl delete nodegroup --region=%s --cluster=%s --name=<name>' for each of the failed nodegroup", cfg.Metadata.Region, cfg.Metadata.Name)
Expand Down

0 comments on commit 4ddb027

Please sign in to comment.