forked from kubernetes-sigs/kubespray
-
Notifications
You must be signed in to change notification settings - Fork 0
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 (kubernetes-sigs#…
…10245) * 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> * tests: cleanup stale packet namespace after 2 hours 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> * tests: ignore vm cleanup failure Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@proton.ch> * tests: use pipeline_id var instead of fetching namespace for cleanup packet vm Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@proton.ch> --------- Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@proton.ch>
- Loading branch information
1 parent
9d9e36a
commit c6f16e1
Showing
7 changed files
with
61 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
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,7 @@ | ||
--- | ||
|
||
- hosts: localhost | ||
gather_facts: no | ||
become: true | ||
roles: | ||
- { role: cleanup-packet-ci } |
16 changes: 16 additions & 0 deletions
16
tests/cloud_playbooks/roles/cleanup-packet-ci/tasks/main.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,16 @@ | ||
--- | ||
|
||
- 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 }}" | ||
failed_when: false | ||
loop: "{{ namespaces.resources }}" | ||
when: | ||
- (now() - (item.metadata.creationTimestamp | to_datetime("%Y-%m-%dT%H:%M:%SZ"))).total_seconds() >= 7200 |
17 changes: 17 additions & 0 deletions
17
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,17 @@ | ||
--- | ||
|
||
- 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 }}" | ||
failed_when: false | ||
loop: "{{ namespaces.resources }}" | ||
when: | ||
- (item.metadata.labels.pipeline_id | int) < (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