Skip to content

Commit

Permalink
Fix deleting cluster sometimes drain managed nodegroups
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxiang-zhang committed Jan 31, 2024
1 parent 29e0d7e commit a6aa06b
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 14 deletions.
3 changes: 2 additions & 1 deletion pkg/actions/cluster/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,11 @@ func drainAllNodeGroups(ctx context.Context, cfg *api.ClusterConfig, ctl *eks.Cl
}
}

// EKS automatically drains managed nodegroups
logger.Info("will drain %d unmanaged nodegroup(s) in cluster %q", len(cfg.NodeGroups), cfg.Metadata.Name)

drainInput := &nodegroup.DrainInput{
NodeGroups: cmdutils.ToKubeNodeGroups(cfg),
NodeGroups: cmdutils.ToKubeNodeGroups(cfg.NodeGroups, []*api.ManagedNodeGroup{}),
MaxGracePeriod: ctl.AWSProvider.WaitTimeout(),
DisableEviction: disableEviction,
PodEvictionWaitPeriod: podEvictionWaitPeriod,
Expand Down
6 changes: 3 additions & 3 deletions pkg/actions/cluster/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var _ = Describe("DrainAllNodeGroups", func() {

nodeGroupStacks := []manager.NodeGroupStack{{NodeGroupName: "ng-1"}}
mockedDrainInput := &nodegroup.DrainInput{
NodeGroups: cmdutils.ToKubeNodeGroups(cfg),
NodeGroups: cmdutils.ToKubeNodeGroups(cfg.NodeGroups, cfg.ManagedNodeGroups),
MaxGracePeriod: ctl.AWSProvider.WaitTimeout(),
Parallel: 1,
}
Expand Down Expand Up @@ -87,7 +87,7 @@ var _ = Describe("DrainAllNodeGroups", func() {

nodeGroupStacks := []manager.NodeGroupStack{{NodeGroupName: "ng-1"}}
mockedDrainInput := &nodegroup.DrainInput{
NodeGroups: cmdutils.ToKubeNodeGroups(cfg),
NodeGroups: cmdutils.ToKubeNodeGroups(cfg.NodeGroups, cfg.ManagedNodeGroups),
MaxGracePeriod: ctl.AWSProvider.WaitTimeout(),
DisableEviction: true,
Parallel: 1,
Expand Down Expand Up @@ -116,7 +116,7 @@ var _ = Describe("DrainAllNodeGroups", func() {

var nodeGroupStacks []manager.NodeGroupStack
mockedDrainInput := &nodegroup.DrainInput{
NodeGroups: cmdutils.ToKubeNodeGroups(cfg),
NodeGroups: cmdutils.ToKubeNodeGroups(cfg.NodeGroups, cfg.ManagedNodeGroups),
MaxGracePeriod: ctl.AWSProvider.WaitTimeout(),
Parallel: 1,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/actions/cluster/owned_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ var _ = Describe("Delete", func() {
})

mockedDrainInput := &nodegroup.DrainInput{
NodeGroups: cmdutils.ToKubeNodeGroups(cfg),
NodeGroups: cmdutils.ToKubeNodeGroups(cfg.NodeGroups, cfg.ManagedNodeGroups),
MaxGracePeriod: ctl.AWSProvider.WaitTimeout(),
Parallel: 1,
}
Expand Down Expand Up @@ -253,7 +253,7 @@ var _ = Describe("Delete", func() {
})

mockedDrainInput := &nodegroup.DrainInput{
NodeGroups: cmdutils.ToKubeNodeGroups(cfg),
NodeGroups: cmdutils.ToKubeNodeGroups(cfg.NodeGroups, cfg.ManagedNodeGroups),
MaxGracePeriod: ctl.AWSProvider.WaitTimeout(),
Parallel: 1,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/actions/cluster/unowned_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ var _ = Describe("Delete", func() {
})

mockedDrainInput := &nodegroup.DrainInput{
NodeGroups: cmdutils.ToKubeNodeGroups(cfg),
NodeGroups: cmdutils.ToKubeNodeGroups(cfg.NodeGroups, cfg.ManagedNodeGroups),
MaxGracePeriod: ctl.AWSProvider.WaitTimeout(),
Parallel: 1,
}
Expand Down Expand Up @@ -348,7 +348,7 @@ var _ = Describe("Delete", func() {
},
}
mockedDrainInput := &nodegroup.DrainInput{
NodeGroups: cmdutils.ToKubeNodeGroups(cfg),
NodeGroups: cmdutils.ToKubeNodeGroups(cfg.NodeGroups, cfg.ManagedNodeGroups),
MaxGracePeriod: ctl.AWSProvider.WaitTimeout(),
Parallel: 1,
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/ctl/cmdutils/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ func ApplyFilter(clusterConfig *api.ClusterConfig, ngFilter filter.NodegroupFilt

// ToKubeNodeGroups combines managed and unmanaged nodegroups and returns a slice of eks.KubeNodeGroup containing
// both types of nodegroups
func ToKubeNodeGroups(clusterConfig *api.ClusterConfig) []eks.KubeNodeGroup {
func ToKubeNodeGroups(unmanagedNodeGroups []*api.NodeGroup, managedNodeGroups []*api.ManagedNodeGroup) []eks.KubeNodeGroup {
var kubeNodeGroups []eks.KubeNodeGroup
for _, ng := range clusterConfig.NodeGroups {
for _, ng := range unmanagedNodeGroups {
kubeNodeGroups = append(kubeNodeGroups, ng)
}
for _, ng := range clusterConfig.ManagedNodeGroups {
for _, ng := range managedNodeGroups {
kubeNodeGroups = append(kubeNodeGroups, ng)
}
return kubeNodeGroups
Expand Down
2 changes: 1 addition & 1 deletion pkg/ctl/create/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func doCreateCluster(cmd *cmdutils.Cmd, ngFilter *filter.NodeGroupFilter, params
}
}
logFiltered := cmdutils.ApplyFilter(cfg, ngFilter)
kubeNodeGroups := cmdutils.ToKubeNodeGroups(cfg)
kubeNodeGroups := cmdutils.ToKubeNodeGroups(cfg.NodeGroups, cfg.ManagedNodeGroups)

// Check if flux binary exists early in the process, so it doesn't fail at the end when the cluster
// has already been created with a missing flux binary error which should have been caught earlier.
Expand Down
2 changes: 1 addition & 1 deletion pkg/ctl/delete/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func doDeleteNodeGroup(cmd *cmdutils.Cmd, ng *api.NodeGroup, options deleteNodeG
}
}
}
allNodeGroups := cmdutils.ToKubeNodeGroups(cfg)
allNodeGroups := cmdutils.ToKubeNodeGroups(cfg.NodeGroups, cfg.ManagedNodeGroups)

if options.deleteNodeGroupDrain {
cmdutils.LogIntendedAction(cmd.Plan, "drain %d nodegroup(s) in cluster %q", len(allNodeGroups), cfg.Metadata.Name)
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 @@ -127,7 +127,7 @@ func doDrainNodeGroup(cmd *cmdutils.Cmd, ng *api.NodeGroup, undo, onlyMissing bo
if cmd.Plan {
return nil
}
allNodeGroups := cmdutils.ToKubeNodeGroups(cfg)
allNodeGroups := cmdutils.ToKubeNodeGroups(cfg.NodeGroups, cfg.ManagedNodeGroups)

drainInput := &nodegroup.DrainInput{
NodeGroups: allNodeGroups,
Expand Down

0 comments on commit a6aa06b

Please sign in to comment.