-
Notifications
You must be signed in to change notification settings - Fork 33
OPSEXP-3170 Add workflow to cleanup AWS MQ configuration leftovers #1229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
d9be596
list mq configurations
siddavamshi4 40c746f
Update delete-mq-configs.yml
siddavamshi4 6e262c2
with test on pushes
siddavamshi4 e196b42
Update delete-mq-configs.yml
siddavamshi4 437dd71
Update delete-mq-configs.yml
siddavamshi4 e3b4608
aws login with secrets
siddavamshi4 18418b2
with query changes
siddavamshi4 a6cf0d8
test run to check deletions
siddavamshi4 5c5945f
with no pagination
siddavamshi4 9f2b4d5
test run with retention_days as 1000
siddavamshi4 5978c35
test to get count
siddavamshi4 56718d8
test to remove pagination
siddavamshi4 eb368ba
testing pagination
siddavamshi4 7c1ab54
with --max-results
siddavamshi4 2d190a1
test pagination with --max-results
siddavamshi4 b16e755
testing listing with a script
siddavamshi4 d1b60cc
running tests with pagination
siddavamshi4 ae19d6f
test with prefix molecule-
siddavamshi4 8b40018
testing break after 20 reocrds
siddavamshi4 b8dd3ce
testing to delete 20 records
siddavamshi4 2436231
test deletion of 20 records
siddavamshi4 a84a54a
with scheduled deletion of AWS mq
siddavamshi4 e8ace43
with AWS OIDC authentication
siddavamshi4 52ed0ff
optimized job
siddavamshi4 3c5ee85
with aws_region env variable
siddavamshi4 c20a6fb
with dry- run configuration
siddavamshi4 96747d2
removed extra space
siddavamshi4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| name: Cleanup MQ Configurations | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| dry_run: | ||
| type: boolean | ||
| default: true | ||
| description: "If true, skips deletion for safe testing" | ||
| schedule: | ||
| - cron: '23 5 1 * *' | ||
|
|
||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
|
|
||
| env: | ||
| RETENTION_DAYS: 30 | ||
| AWS_REGION: eu-west-1 | ||
| DRY_RUN: ${{ inputs.dry_run && github.event_name != 'schedule' }} | ||
|
|
||
| jobs: | ||
| delete-mq-configs: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Login to AWS | ||
| uses: aws-actions/configure-aws-credentials@b47578312673ae6fa5b5096b330d9fbac3d116df # v4.2.1 | ||
| with: | ||
| aws-region: ${{ env.AWS_REGION }} | ||
| role-to-assume: arn:aws:iam::372466110691:role/AlfrescoCI/mq-configuration-cleanup | ||
| role-session-name: ${{ github.event.repository.name }}-${{ github.run_id }} | ||
| role-duration-seconds: 1800 | ||
|
|
||
| - name: Delete old MQ configurations (using pagination) | ||
| run: | | ||
| set -o pipefail | ||
| threshold_epoch=$(date -d "$RETENTION_DAYS days ago" +"%s") | ||
| next_token="" | ||
|
|
||
| echo "Checking for MQ configurations older than $RETENTION_DAYS days..." | ||
|
|
||
| while true; do | ||
| list_configurations_cmd="aws mq list-configurations --max-results 100 --output json" | ||
|
|
||
| if [ -z "$next_token" ]; then | ||
| response=$($list_configurations_cmd ) | ||
siddavamshi4 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| else | ||
| response=$($list_configurations_cmd --next-token "$next_token" ) | ||
siddavamshi4 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fi | ||
|
|
||
| configs=$(echo "$response" | jq -c '.Configurations[]?') | ||
| next_token=$(echo "$response" | jq -r '.NextToken') | ||
|
|
||
| while read -r config; do | ||
| id=$(jq -r '.Id' <<< "$config") | ||
| name=$(jq -r '.Name' <<< "$config") | ||
|
|
||
| if [[ "$name" != molecule-* ]]; then | ||
| echo "Skipping: $name (ID: $id) — doesn't match prefix 'molecule-'" | ||
| continue | ||
| fi | ||
|
|
||
| created=$(jq -r '.LatestRevision.Created' <<< "$config") | ||
| created_epoch=$(date -d "${created%%.*}" +"%s" || echo 0) | ||
siddavamshi4 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
gionn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| age_days=$(( ( $(date -u +"%s") - created_epoch ) / 86400 )) | ||
|
|
||
| attached=$(aws mq list-brokers \ | ||
| --query "BrokerSummaries[?Configuration.Id=='$id'].BrokerId" \ | ||
| --output text) | ||
|
|
||
| if [ -n "$attached" ]; then | ||
| echo "In use: $name ($id) — broker: $attached" | ||
| continue | ||
| fi | ||
|
|
||
| if [ "$created_epoch" -lt "$threshold_epoch" ]; then | ||
| if [ "$DRY_RUN" = "false" ]; then | ||
| echo "Deleting: $name ($id) — $age_days days old" | ||
| aws mq delete-configuration --configuration-id "$id" | ||
| else | ||
| echo "Dry run would delete: $name ($id) — $age_days days old" | ||
| fi | ||
| else | ||
| echo "Keeping: $name ($id) — $age_days days old" | ||
| fi | ||
gionn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| done < <(echo "$configs") | ||
|
|
||
| # Exit loop if no more pages | ||
| [ "$next_token" == "null" ] || [ -z "$next_token" ] && break | ||
| done | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.