Skip to content
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

Fix aws-nuke staling when there are a lot of S3Objects #101

Merged
merged 5 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Containerfile.conan
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN make sandbox-list
FROM registry.access.redhat.com/ubi8/ubi:latest
MAINTAINER Guillaume Coré <gucore@redhat.com>

ARG AWSNUKE_VERSION=v3.26.0
ARG AWSNUKE_VERSION=v3.35.2
ARG AWSNUKE_LEGACY_VERSION=v2.25.0
ARG RUSH_VERSION=v0.5.4

Expand All @@ -18,6 +18,7 @@ USER root
COPY --from=builder /sandbox/build/sandbox-list /usr/local/bin/sandbox-list
COPY conan/requirements.txt /tmp/requirements.txt
COPY conan/requirements.yml /tmp/requirements.yml
COPY conan/ansible.cfg /etc/ansible/ansible.cfg

RUN mkdir -p -m 770 /home/opentlc-mgr/pool_management/output_dir_sandbox \
&& chmod -R 770 /home/opentlc-mgr \
Expand Down
2 changes: 2 additions & 0 deletions conan/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[defaults]
callbacks_enabled=ansible.posix.profile_tasks
1 change: 1 addition & 0 deletions conan/requirements.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
collections:
- name: amazon.aws
- name: ansible.posix
- name: community.aws
- name: community.crypto
- name: community.general
8 changes: 4 additions & 4 deletions conan/wipe_sandbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ sandbox_reset() {
echo "$(date -uIs) ${sandbox} $(grep -Eo 'Nuke complete: [^"]+' "${logfile}")"

if [ "${debug}" = "true" ]; then
echo "$(date -uIs) =========BEGIN========== ${logfile}"
echo "$(date -uIs) =========BEGIN========== ${HOSTNAME} ${logfile}"
cat "${logfile}"
echo "$(date -uIs) =========END============ ${logfile}"
echo "$(date -uIs) =========END============ ${HOSTNAME} ${logfile}"
fi

rm "${eventlog}"
Expand All @@ -265,9 +265,9 @@ sandbox_reset() {
echo "$(date -uIs) ${sandbox} reset took $((duration / 60))m$((duration % 60))s"

echo "$(date -uIs) ${sandbox} reset FAILED." >&2
echo "$(date -uIs) =========BEGIN========== ${logfile}" >&2
echo "$(date -uIs) =========BEGIN========== ${HOSTNAME} ${logfile}" >&2
cat "${logfile}" >&2
echo "$(date -uIs) =========END============ ${logfile}" >&2
echo "$(date -uIs) =========END============ ${HOSTNAME} ${logfile}" >&2
sandbox_increase_conan_cleanup_count "${sandbox}"
echo "$(date -uIs) ${sandbox} cleanup count: $(get_conan_cleanup_count "${sandbox}")"
sync
Expand Down
18 changes: 18 additions & 0 deletions playbooks/roles/infra-aws-sandbox/files/manual_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@

client = boto3.client('ec2')

# Stop all instances to save costs

try:
response = client.describe_instances()

for reservation in response['Reservations']:
for instance in reservation['Instances']:
if instance['State']['Name'] == 'running':
client.stop_instances(
InstanceIds=[
instance['InstanceId']
]
)
print("Stopping instance: " + instance['InstanceId'])
changed = True
except botocore.exceptions.ClientError as e:
print(e)

try:
response = client.describe_vpcs()

Expand Down
1 change: 1 addition & 0 deletions playbooks/roles/infra-aws-sandbox/tasks/reset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
dest: "{{ output_dir }}/{{ account_name }}_nuke-config.yml"

- name: Generate config file for aws-nuke-legacy
when: run_aws_nuke_legacy | default(false) | bool
template:
src: "{{ role_path }}/templates/nuke-config-legacy.yml.j2"
dest: "{{ output_dir }}/{{ account_name }}_nuke-config-legacy.yml"
Expand Down
43 changes: 27 additions & 16 deletions playbooks/roles/infra-aws-sandbox/templates/nuke-config.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,34 @@ resource-types:
excludes:
# don't nuke OpenSearch Packages, see https://github.com/rebuy-de/aws-nuke/issues/1123
- AmazonML
- Cloud9Environment
- CloudSearchDomain
- CodeStarProject
- FMSNotificationChannel
- FMSPolicy
- MachineLearningBranchPrediction
- MachineLearningDataSource
- MachineLearningEvaluation
- MachineLearningMLModel
- OSPackage
- Cloud9Environment # Deprecated service
- CloudSearchDomain # Deprecated service
- CodeStarConnection # Deprecated service
- CodeStarNotification # Deprecated service
- CodeStarProject # Deprecated service
- FMSNotificationChannel # Excluded because it's not available
- FMSPolicy # Excluded because it's not available
- MachineLearningBranchPrediction # Excluded due to ML being unavailable
- MachineLearningDataSource # Excluded due to ML being unavailable
- MachineLearningEvaluation # Excluded due to ML being unavailable
- MachineLearningMLModel # Excluded due to ML being unavailable
- OpsWorksApp
- OpsWorksCMBackup
- OpsWorksCMServer
- OpsWorksCMServerState
- OpsWorksInstance
- OpsWorksLayer
- OpsWorksUserProfile
- OpsWorksApp # Deprecated service
- OpsWorksCMBackup # Deprecated service
- OpsWorksCMServer # Deprecated service
- OpsWorksCMServerState # Deprecated service
- OpsWorksInstance # Deprecated service
- OpsWorksLayer # Deprecated service
- OpsWorksUserProfile # Deprecated service
- RedshiftServerlessNamespace # Deprecated service
- RedshiftServerlessSnapshot # Deprecated service
- RedshiftServerlessWorkgroup # Deprecated service
- RoboMakerDeploymentJob # Deprecated Service
- RoboMakerFleet # Deprecated Service
- RoboMakerRobot # Deprecated Service
- RoboMakerRobotApplication
- RoboMakerSimulationApplication
- RoboMakerSimulationJob
- S3Object # Excluded because S3 bucket removal handles removing all S3Objects
- ServiceCatalogTagOption # Excluded due to https://github.com/rebuy-de/aws-nuke/issues/515
- ServiceCatalogTagOptionPortfolioAttachment # Excluded due to https://github.com/rebuy-de/aws-nuke/issues/515
Loading