-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: cleanup stale packet namespace automatically
Cancelled job on Gitlab can produce stale VMs as the delete playbook will never be executed. This commits allow removing old vms by getting all the namespace created from the same branch with an older pipeline id. Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@proton.ch>
- Loading branch information
1 parent
a1521dc
commit 8047626
Showing
4 changed files
with
37 additions
and
1 deletion.
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
28 changes: 28 additions & 0 deletions
28
tests/cloud_playbooks/roles/packet-ci/tasks/cleanup-old-vms.yml
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,28 @@ | ||
--- | ||
|
||
- name: Fetch current namespace | ||
kubernetes.core.k8s_info: | ||
api_version: v1 | ||
kind: Namespace | ||
name: "{{ test_name }}" | ||
label_selectors: | ||
- cijobs = true | ||
- branch = {{ branch }} | ||
register: current_namespace | ||
|
||
- name: Fetch a list of namespaces | ||
kubernetes.core.k8s_info: | ||
api_version: v1 | ||
kind: Namespace | ||
label_selectors: | ||
- cijobs = true | ||
- branch = {{ branch }} | ||
register: namespaces | ||
|
||
- name: Delete older namespaces | ||
command: "kubectl delete namespace {{ item.metadata.name }}" | ||
loop: "{{ namespaces.resources }}" | ||
when: | ||
- |- | ||
(item.metadata.labels.pipeline_id | int) | ||
< (current_namespace.resources[0].metadata.labels.pipeline_id | int) |
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