Skip to content

Commit

Permalink
Refactor draining all nodegroups
Browse files Browse the repository at this point in the history
  • Loading branch information
nikimanoledaki committed Sep 14, 2021
1 parent 4643e74 commit 07146bf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
3 changes: 2 additions & 1 deletion pkg/actions/cluster/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,14 @@ func drainAllNodegroups(cfg *api.ClusterConfig, ctl *eks.ClusterProvider, stackM
}

for _, s := range allStacks {
if s.Type != api.NodeGroupTypeManaged {
if s.Type == api.NodeGroupTypeUnmanaged {
if err := cmdutils.PopulateNodegroupFromStack(s.Type, s.NodeGroupName, cfg); err != nil {
return err
}
}
}

logger.Info("will drain %d unmanaged nodegroup(s) in cluster %q", len(cfg.NodeGroups), cfg.Metadata.Name)
nodeGroupManager := nodegroup.New(cfg, ctl, clientSet)
plan, disableEviction := false, false
if err := nodeGroupManager.Drain(cmdutils.ToKubeNodeGroups(cfg), plan, ctl.Provider.WaitTimeout(), disableEviction); err != nil {
Expand Down
3 changes: 0 additions & 3 deletions pkg/actions/nodegroup/drain.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import (

"github.com/weaveworks/eksctl/pkg/eks"

"github.com/weaveworks/eksctl/pkg/ctl/cmdutils"
"github.com/weaveworks/eksctl/pkg/drain"
)

func (m *Manager) Drain(nodeGroups []eks.KubeNodeGroup, plan bool, maxGracePeriod time.Duration, disableEviction bool) error {
cmdutils.LogIntendedAction(plan, "drain %d nodegroup(s) in cluster %q", len(nodeGroups), m.cfg.Metadata.Name)

if !plan {
for _, n := range nodeGroups {
nodeGroupDrainer := drain.NewNodeGroupDrainer(m.clientSet, n, m.ctl.Provider.WaitTimeout(), maxGracePeriod, false, disableEviction)
Expand Down
32 changes: 13 additions & 19 deletions pkg/ctl/cmdutils/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,24 @@ func PopulateNodegroup(stackManager manager.StackManager, name string, cfg *api.
func PopulateNodegroupFromStack(nodeGroupType api.NodeGroupType, nodeGroupName string, cfg *api.ClusterConfig) error {
switch nodeGroupType {
case api.NodeGroupTypeUnmanaged:
cfg.NodeGroups = []*api.NodeGroup{
{
NodeGroupBase: &api.NodeGroupBase{
Name: nodeGroupName,
},
cfg.NodeGroups = append(cfg.NodeGroups, &api.NodeGroup{
NodeGroupBase: &api.NodeGroupBase{
Name: nodeGroupName,
},
}
})
case api.NodeGroupTypeManaged:
cfg.ManagedNodeGroups = []*api.ManagedNodeGroup{
{
NodeGroupBase: &api.NodeGroupBase{
Name: nodeGroupName,
},
cfg.ManagedNodeGroups = append(cfg.ManagedNodeGroups, &api.ManagedNodeGroup{
NodeGroupBase: &api.NodeGroupBase{
Name: nodeGroupName,
},
}
})
case api.NodeGroupTypeUnowned:
cfg.ManagedNodeGroups = []*api.ManagedNodeGroup{
{
NodeGroupBase: &api.NodeGroupBase{
Name: nodeGroupName,
},
Unowned: true,
cfg.ManagedNodeGroups = append(cfg.ManagedNodeGroups, &api.ManagedNodeGroup{
NodeGroupBase: &api.NodeGroupBase{
Name: nodeGroupName,
},
}
Unowned: true,
})
}
return nil
}
1 change: 1 addition & 0 deletions pkg/ctl/delete/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func doDeleteNodeGroup(cmd *cmdutils.Cmd, ng *api.NodeGroup, updateAuthConfigMap

nodeGroupManager := nodegroup.New(cfg, ctl, clientSet)
if deleteNodeGroupDrain {
cmdutils.LogIntendedAction(cmd.Plan, "drain %d nodegroup(s) in cluster %q", len(allNodeGroups), cfg.Metadata.Name)
err := nodeGroupManager.Drain(allNodeGroups, cmd.Plan, maxGracePeriod, disableEviction)
if err != nil {
logger.Warning("error occurred during drain, to skip drain use '--drain=false' flag")
Expand Down

0 comments on commit 07146bf

Please sign in to comment.