Skip to content

Commit

Permalink
implement PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake committed Mar 10, 2022
1 parent 8305c89 commit 88a7f26
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pkg/ctl/delete/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func deleteNodeGroupWithRunFunc(cmd *cmdutils.Cmd, runFunc func(cmd *cmdutils.Cm
fs.DurationVar(&maxGracePeriod, "max-grace-period", defaultMaxGracePeriod, "Maximum pods termination grace period")
defaultDisableEviction := false
fs.BoolVar(&disableEviction, "disable-eviction", defaultDisableEviction, "Force drain to use delete, even if eviction is supported. This will bypass checking PodDisruptionBudgets, use with caution.")
fs.IntVar(&parallel, "parallel", 5, "Number of nodes to drain in parallel. Max 25")
fs.IntVar(&parallel, "parallel", 1, "Number of nodes to drain in parallel. Max 25")

cmd.Wait = false
cmdutils.AddWaitFlag(fs, &cmd.Wait, "deletion of all resources")
Expand Down
2 changes: 1 addition & 1 deletion pkg/ctl/drain/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func drainNodeGroupWithRunFunc(cmd *cmdutils.Cmd, runFunc func(cmd *cmdutils.Cmd
fs.BoolVar(&disableEviction, "disable-eviction", defaultDisableEviction, "Force drain to use delete, even if eviction is supported. This will bypass checking PodDisruptionBudgets, use with caution.")
cmdutils.AddTimeoutFlag(fs, &cmd.ProviderConfig.WaitTimeout)
fs.DurationVar(&nodeDrainWaitPeriod, "node-drain-wait-period", 0, "Amount of time to wait between draining nodes in a nodegroup")
fs.IntVar(&parallel, "parallel", 5, "Number of nodes to drain in parallel. Max 25")
fs.IntVar(&parallel, "parallel", 1, "Number of nodes to drain in parallel. Max 25")
})

cmdutils.AddCommonFlagsForAWS(cmd.FlagSetGroup, &cmd.ProviderConfig, true)
Expand Down
11 changes: 3 additions & 8 deletions pkg/drain/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,11 @@ func (n *NodeGroupDrainer) Drain() error {
logger.Debug("already drained: %v", mapToList(drainedNodes.Items()))
logger.Debug("will drain: %v", newPendingNodes.List())
for i, node := range newPendingNodes.List() {
// scoped values for concurrency
i := i
node := node

if err := sem.Acquire(ctx, 1); err != nil {
logger.Critical("failed to claim sem: %w", err)
}

go func() {
go func(i int, node string) {
defer sem.Release(1)
logger.Debug("starting drain of node %s", node)
pending, err := n.evictPods(node)
Expand All @@ -167,12 +163,11 @@ func (n *NodeGroupDrainer) Drain() error {
drainedNodes.Set(node, nil)
}

// only wait if we're not on the last node of this iteration
if n.nodeDrainWaitPeriod > 0 && i < newPendingNodes.Len()-1 {
if n.nodeDrainWaitPeriod > 0 {
logger.Debug("waiting for %.0f seconds before draining next node", n.nodeDrainWaitPeriod.Seconds())
time.Sleep(n.nodeDrainWaitPeriod)
}
}()
}(i, node)
}
}
}
Expand Down

0 comments on commit 88a7f26

Please sign in to comment.