Skip to content

Commit

Permalink
Delete beta EKS clusters created by Github Actions (#1167)
Browse files Browse the repository at this point in the history
  • Loading branch information
movence authored May 13, 2024
1 parent 7c9e0c2 commit 77d71a5
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion tool/clean/clean_eks/clean_eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import (
"github.com/aws/amazon-cloudwatch-agent/tool/clean"
)

// make this configurable or construct based on some configs?
const betaEksEndpoint = "https://api.beta.us-west-2.wesley.amazonaws.com"

var (
ClustersToClean = []string{
"cwagent-eks-integ-",
Expand All @@ -40,11 +43,30 @@ func cleanCluster() error {
return err
}
eksClient := eks.NewFromConfig(defaultConfig)

terminateClusters(ctx, eksClient)

// delete beta clusters
betaConfig, err := config.LoadDefaultConfig(ctx, config.WithEndpointResolverWithOptions(eksBetaEndpointResolver()))
if err != nil {
return err
}
betaClient := eks.NewFromConfig(betaConfig)
terminateClusters(ctx, betaClient)

return nil
}

func eksBetaEndpointResolver() aws.EndpointResolverWithOptionsFunc {
return func(service, region string, options ...interface{}) (aws.Endpoint, error) {
endpoint, err := eks.NewDefaultEndpointResolver().ResolveEndpoint(region, eks.EndpointResolverOptions{})
if err != nil {
return aws.Endpoint{}, err
}
endpoint.URL = betaEksEndpoint
return endpoint, nil
}
}

func clusterNameMatchesClustersToClean(clusterName string, clustersToClean []string) bool {
for _, clusterToClean := range clustersToClean {
if strings.HasPrefix(clusterName, clusterToClean) {
Expand All @@ -57,6 +79,7 @@ func clusterNameMatchesClustersToClean(clusterName string, clustersToClean []str
func terminateClusters(ctx context.Context, client *eks.Client) {
listClusterInput := eks.ListClustersInput{}
expirationDateCluster := time.Now().UTC().Add(clean.KeepDurationFourDays)

clusters, err := client.ListClusters(ctx, &listClusterInput)
if err != nil {
log.Fatalf("could not get cluster list")
Expand Down

0 comments on commit 77d71a5

Please sign in to comment.