Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
harrryr committed Aug 29, 2024
1 parent 8ea1c05 commit 5603bcd
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/resource-cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
schedule:
- cron: '0 18 * * *' # scheduled to run at 18:00 UTC every day
workflow_dispatch: # be able to run on demand
push:

jobs:
cleanup-ec2-instances:
Expand Down Expand Up @@ -53,3 +54,67 @@ jobs:
run: |
python -m pip install -r requirements.txt
python cleaner.py
cleanup-k8s-on-ec2:
runs-on: ubuntu-latest
if: ${{ github.event.schedule && startsWith(format('{::yyyy-MM-dd}', now()), format('{::yyyy-MM}-01', now())) }}
strategy:
matrix:
instance: [
{ repo_name: 'amazon-cloudwatch-agent-operator', ec2_name: 'cw-agent-operator-release', language: 'java' },
{ repo_name: 'amazon-cloudwatch-agent-operator', ec2_name: 'cw-agent-operator-release', language: 'python' },
{ repo_name: 'amazon-cloudwatch-agent', ec2_name: 'cw-agent-release', language: 'java' },
{ repo_name: 'amazon-cloudwatch-agent', ec2_name: 'cw-agent-release', language: 'python' },
{ repo_name: 'aws-otel-python-instrumentation', ec2_name: 'adot-python-release', language: 'python' },
{ repo_name: 'aws-otel-java-instrumentation', ec2_name: 'adot-java-release', language: 'java' },
{ repo_name: 'aws-application-signals-test-framework', ec2_name: 'python-canary', language: 'python' },
{ repo_name: 'aws-application-signals-test-framework', ec2_name: 'java-canary', language: 'java' },
{ repo_name: 'aws-application-signals-test-framework', ec2_name: 'e2e-playground', language: 'all' } ]
permissions:
id-token: write
contents: read
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ env.E2E_TEST_ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }}
aws-region: us-east-1

- name: Delete Key Pair and EC2 Instance
run: |
STORAGE_SECRET_KEYS=(
"e2e-test/${{ env.REPO }}/${{ env.LANGUAGE }}-k8s-master-node-endpoint-temporary-storage"
)
endpoint_secret=$(aws secretsmanager get-secret-value --secret-id "${CURRENT_SECRET_KEYS[0]}" --query SecretString --output text)
instance_name=$(aws ec2 describe-instances \
--filters "Name=ip-address,Values=$public_ip" \
--query "Reservations[*].Instances[*].{Name:Tags[?Key=='Name']|[0].Value}" \
--output text)
prev_testing_id=$(echo $instance_name | awk -F'-' '{print $(NF-1)"-"$NF}')
aws ec2 delete-key-pair --key-name "k8s-on-ec2-${{ matrix.instance.ec2_name }}-${{ matrix.instance.language }}-key-pair-$prev_testing_id"
main_instance_name=k8s-on-ec2-${{ matrix.instance.ec2_name }}-${{ matrix.instance.language }}-master-$prev_testing_id
worker_instance_name=k8s-on-ec2-${{ matrix.instance.ec2_name }}-${{ matrix.instance.language }}-worker-$prev_testing_id
main_instance_id=$(aws ec2 describe-instances \
--filters "Name=tag:Name,Values=$main_instance_name" \
--query "Reservations[*].Instances[*].InstanceId" \
--output text)
worker_instance_id=$(aws ec2 describe-instances \
--filters "Name=tag:Name,Values=$worker_instance_name" \
--query "Reservations[*].Instances[*].InstanceId" \
--output text)
aws ec2 terminate-instances --instance-ids $main_instance_id
aws ec2 terminate-instances --instance-ids $worker_instance_id
publish-metric:
needs: [ cleanup-ec2-instances, cleanup-k8s-on-ec2 ]
if: always()
uses: ./.github/workflows/enablement-test-publish-result.yml
secrets: inherit
with:
aws-region: 'us-east-1'
caller-workflow-name: 'enablement-test-resource-cleanup'
validation-result: ${{ (needs.cleanup-ec2-instances.result == 'success' && needs.cleanup-k8s-on-ec2.result != 'failure') && 'success' || 'failure' }}

0 comments on commit 5603bcd

Please sign in to comment.