Skip to content

Commit

Permalink
Clean Test Hosts In China
Browse files Browse the repository at this point in the history
  • Loading branch information
sethAmazon committed May 8, 2024
1 parent a595ac7 commit c2cfd4c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
23 changes: 21 additions & 2 deletions .github/workflows/clean-aws-resources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,28 @@ jobs:
role-to-assume: ${{ secrets[matrix.role_secret] }}
aws-region: ${{ matrix.region }}

- name: Clean old dedicated host
- name: Clean old host
working-directory: tool/clean
run: go run ./clean_host/clean_host.go ${{ matrix.region }}

clean-hosts-china:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ vars.TERRAFORM_AWS_ASSUME_ROLE_CN }}
aws-region: "cn-north-1"

- name: Clean old hosts
working-directory: tool/clean
run: go run ./clean_host/clean_host.go --tags=clean
run: go run ./clean_host/clean_host.go cn-north-1

clean-ecs-clusters:
runs-on: ubuntu-latest
Expand Down
22 changes: 7 additions & 15 deletions tool/clean/clean_host/clean_host.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

//go:build clean
// +build clean

package main

import (
"context"
"log"
"os"
"time"

"github.com/aws/aws-sdk-go-v2/config"
Expand All @@ -19,8 +16,6 @@ import (
"github.com/aws/amazon-cloudwatch-agent/tool/clean"
)

var REGIONS = []string{"us-east-1", "us-west-2"}

// Clean integration hosts if they have been open longer than 1 day
func main() {
err := cleanHost()
Expand All @@ -33,16 +28,13 @@ func cleanHost() error {
log.Print("Begin to clean EC2 Host")

cxt := context.Background()
var err error
for _, region := range REGIONS {
defaultConfig, err := config.LoadDefaultConfig(cxt, config.WithRegion(region))
if err != nil {
return err
}
ec2client := ec2.NewFromConfig(defaultConfig)

terminateInstances(cxt, ec2client)
defaultConfig, err := config.LoadDefaultConfig(cxt, config.WithRegion(os.Args[1]))
if err != nil {
return err
}
ec2client := ec2.NewFromConfig(defaultConfig)

terminateInstances(cxt, ec2client)
return err
}

Expand Down

0 comments on commit c2cfd4c

Please sign in to comment.