forked from isovalent/aws-delete-vpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodegroups.go
44 lines (41 loc) · 1.05 KB
/
nodegroups.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"context"
"github.com/aws/aws-sdk-go-v2/service/eks"
"github.com/aws/aws-sdk-go-v2/service/eks/types"
)
func deleteClusterNodeGroups(ctx context.Context, client *eks.Client, cluster *types.Cluster) error {
nodeGroups, err := listClusterNodeGroups(ctx, client, cluster)
if err != nil {
return err
}
for _, group := range nodeGroups {
_, err = client.DeleteNodegroup(ctx, &eks.DeleteNodegroupInput{
ClusterName: cluster.Name,
NodegroupName: &group,
})
if err != nil {
return err
}
}
return err
}
func listClusterNodeGroups(ctx context.Context, client *eks.Client, cluster *types.Cluster) ([]string, error) {
var nextToken *string
result := make([]string, 0)
for {
groups, err := client.ListNodegroups(ctx, &eks.ListNodegroupsInput{
ClusterName: cluster.Name,
NextToken: nextToken,
})
if err != nil {
return nil, err
}
result = append(result, groups.Nodegroups...)
if len(groups.Nodegroups) == 0 || groups.NextToken == nil {
break
}
nextToken = groups.NextToken
}
return result, nil
}