Skip to content

Commit

Permalink
instancepool: prevent deletion if still referenced (#310)
Browse files Browse the repository at this point in the history
This change improves the `exo instancepool delete` command by checking
if the specified Instance Pools is not currently referenced by a NLB
service before attempting to delete it.
  • Loading branch information
falzm authored Jan 29, 2021
1 parent 54c99a1 commit 8fe9405
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cmd/instance_pool_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ var instancePoolDeleteCmd = &cobra.Command{
return err
}

// Ensure the Instance Pool is not attached to a NLB service.
nlbs, err := cs.ListNetworkLoadBalancers(gContext, zone.Name)
if err != nil {
return fmt.Errorf("unable to list Network Load Balancers: %v", err)
}

tasks := make([]task, 0, len(args))
for _, arg := range args {
if !force {
Expand All @@ -49,6 +55,15 @@ var instancePoolDeleteCmd = &cobra.Command{
return err
}

for _, nlb := range nlbs {
for _, svc := range nlb.Services {
if svc.InstancePoolID == i.ID.String() {
return fmt.Errorf("instance pool %q is still referenced by NLB service %s/%s",
i.Name, nlb.Name, svc.Name)
}
}
}

tasks = append(tasks, task{
egoscale.DestroyInstancePool{
ID: i.ID,
Expand Down

0 comments on commit 8fe9405

Please sign in to comment.