Skip to content

Commit

Permalink
tests: cleanup stale packet namespace after 2 hours
Browse files Browse the repository at this point in the history
This ensure that we don't have any packet namespace remaining for more
than 2 hours. All the jobs complete usually within 30min-1hour so 2
hours is enough to detect a stale namespace.

Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@proton.ch>
  • Loading branch information
MrFreezeex committed Jun 22, 2023
1 parent 8047626 commit 0d6840c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitlab-ci/packet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
allow_failure: true
extends: .packet

packet_cleanup_old:
stage: deploy-part1
extends: .packet_periodic
script:
- cd tests
- make cleanup-packet
after_script: []

# The ubuntu20-calico-aio jobs are meant as early stages to prevent running the full CI if something is horribly broken
packet_ubuntu20-calico-aio:
stage: deploy-part1
Expand Down
4 changes: 4 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ delete-packet:
-e pipeline_id="$(CI_PIPELINE_ID)" \
-e inventory_path=$(INVENTORY)

cleanup-packet:
ansible-playbook cloud_playbooks/cleanup-packet.yml -c local \
$(ANSIBLE_LOG_LEVEL)

create-vagrant:
vagrant up
find / -name vagrant_ansible_inventory
Expand Down
7 changes: 7 additions & 0 deletions tests/cloud_playbooks/cleanup-packet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---

- hosts: localhost
gather_facts: no
become: true
roles:
- { role: cleanup-packet-ci }
15 changes: 15 additions & 0 deletions tests/cloud_playbooks/roles/cleanup-packet-ci/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---

- name: Fetch a list of namespaces
kubernetes.core.k8s_info:
api_version: v1
kind: Namespace
label_selectors:
- cijobs = true
register: namespaces

- name: Delete stale namespaces for more than 2 hours
command: "kubectl delete namespace {{ item.metadata.name }}"
loop: "{{ namespaces.resources }}"
when:
- (now() - (item.metadata.creationTimestamp | to_datetime("%Y-%m-%dT%H:%M:%SZ"))).total_seconds() >= 7200

0 comments on commit 0d6840c

Please sign in to comment.