From 5603bcd828aeb2ad50df31f7c0311c7ec3aaab37 Mon Sep 17 00:00:00 2001 From: harryryu Date: Thu, 29 Aug 2024 14:36:49 -0700 Subject: [PATCH] test --- .github/workflows/resource-cleanup.yml | 65 ++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/.github/workflows/resource-cleanup.yml b/.github/workflows/resource-cleanup.yml index d335c8931..98a7dd583 100644 --- a/.github/workflows/resource-cleanup.yml +++ b/.github/workflows/resource-cleanup.yml @@ -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: @@ -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' }} \ No newline at end of file