-
Notifications
You must be signed in to change notification settings - Fork 26
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
Adding a EKS Purge Job, removing the AKS job, making the frequency once a day for test job #1462
Merged
Merged
Changes from all commits
Commits
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 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,47 @@ | ||
# ------------------------------------------------------------ | ||
# Copyright 2023 The Radius Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ------------------------------------------------------------ | ||
|
||
#!/bin/bash | ||
|
||
# Current time in seconds since epoch | ||
current_time=$(date +%s) | ||
|
||
# Age limit in seconds (6 hours * 3600 seconds/hour) | ||
age_limit=$((6 * 3600)) | ||
|
||
echo "Starting cluster purge script." | ||
|
||
# List clusters and their creation times, filter and delete those older than 6 hours and starting with 'eks-samplestest-' | ||
aws eks list-clusters --query "clusters[]" --output text | xargs -I {} aws eks describe-cluster --name {} --query "cluster.{name: name, createdAt: createdAt}" --output text | while read -r created_at name; do | ||
# Convert creation time to seconds since the epoch | ||
# Remove milliseconds and adjust timezone format from "-07:00" to "-0700" | ||
formatted_created_at="${created_at%.*}${created_at##*.}" | ||
formatted_created_at="${formatted_created_at%:*}${formatted_created_at##*:}" | ||
|
||
# Convert creation time to seconds | ||
created_at_seconds=$(date -d "$formatted_created_at" +%s) | ||
|
||
# Calculate age in seconds | ||
age=$((current_time - created_at_seconds)) | ||
|
||
# Check if age is greater than age limit and name starts with 'eks-samplestest-' | ||
if [ "$age" -gt "$age_limit" ] && [[ "$name" == eks-samplestest-* ]]; then | ||
echo "Deleting cluster $name older than 6 hours." | ||
eksctl delete cluster --name "$name" --wait --force | ||
else | ||
echo "Cluster $name is not older than 6 hours or does not meet naming criteria." | ||
fi | ||
done | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reformat |
This file contains 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
This file contains 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,42 @@ | ||
name: Purge AWS EKS Clusters | ||
|
||
on: | ||
schedule: | ||
# Runs every day at 7 AM | ||
- cron: "0 7 * * *" | ||
|
||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
AWS_REGION: us-west-2 | ||
|
||
jobs: | ||
purge_eks_clusters: | ||
name: Purge AWS EKS Clusters | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install AWS CLI | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y awscli | ||
|
||
- name: Install eksctl | ||
run: | | ||
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp | ||
sudo mv /tmp/eksctl /usr/local/bin | ||
|
||
- name: Delete old EKS clusters | ||
env: | ||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
AWS_REGION: ${{ env.AWS_REGION }} | ||
run: bash .github/scripts/purge-aws-eks-clusters.sh | ||
|
||
- name: Create GitHub issue on failure | ||
if: failure() && github.event_name != 'pull_request' | ||
run: | | ||
gh issue create --title "Purge AWS EKS Clusters workflow failed" \ | ||
--body "Test failed on ${{ github.repository }}. See [workflow logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details." \ | ||
--repo ${{ github.repository }} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reformat |
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very cool 👍