-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #583 from redhatci/rem_ztp_by_ref
Add delete-ztp-by-reference action
- Loading branch information
Showing
4 changed files
with
114 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
--- | ||
asm_delete_ztp_resources: true | ||
... |
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,73 @@ | ||
--- | ||
- name: Assert the required variables are defined | ||
ansible.builtin.assert: | ||
that: | ||
- asm_source_repo is defined | ||
- asm_source_repo | length > 0 | ||
- asm_target_revision is defined | ||
- asm_target_revision | length > 0 | ||
|
||
- name: Get all ArgoCD Applications | ||
kubernetes.core.k8s_info: | ||
api_version: argoproj.io/v1alpha1 | ||
kind: Application | ||
namespace: openshift-gitops | ||
register: _asm_all_apps | ||
no_log: true | ||
|
||
- name: Delete ArgoCD Applications | ||
vars: | ||
app_sites: "{{ _asm_all_apps.resources | selectattr('spec.source.repoURL', 'equalto', asm_source_repo) | ||
| selectattr('spec.source.path', 'equalto', 'sites') | ||
| selectattr('spec.source.targetRevision', 'equalto', asm_target_revision) | ||
| map(attribute='metadata.name') | list }}" | ||
app_policies: "{{ _asm_all_apps.resources | selectattr('spec.source.repoURL', 'equalto', asm_source_repo) | ||
| selectattr('spec.source.path', 'equalto', 'policies') | ||
| selectattr('spec.source.targetRevision', 'equalto', asm_target_revision) | ||
| map(attribute='metadata.name') | list }}" | ||
apps_list: "{{ app_sites + app_policies | default([]) }}" | ||
app_ns: openshift-gitops | ||
when: | ||
- apps_list | length > 0 | ||
block: | ||
- name: Patch ArgoCD application finalizers | ||
kubernetes.core.k8s: | ||
api_version: argoproj.io/v1alpha1 | ||
kind: Application | ||
name: "{{ app }}" | ||
namespace: "{{ app_ns }}" | ||
definition: | ||
metadata: | ||
finalizers: | ||
- "resources-finalizer.argocd.argoproj.io" | ||
loop: "{{ apps_list }}" | ||
loop_control: | ||
loop_var: app | ||
when: | ||
- asm_delete_ztp_resources | bool | ||
|
||
- name: Delete Argo Applications | ||
kubernetes.core.k8s: | ||
state: absent | ||
api_version: argoproj.io/v1alpha1 | ||
kind: Application | ||
name: "{{ app }}" | ||
namespace: "{{ app_ns }}" | ||
loop: "{{ apps_list }}" | ||
loop_control: | ||
loop_var: app | ||
|
||
- name: Wait for ArgoCD application deletion | ||
kubernetes.core.k8s_info: | ||
api_version: argoproj.io/v1alpha1 | ||
kind: Application | ||
name: "{{ app }}" | ||
namespace: "{{ app_ns }}" | ||
register: _asm_app_status | ||
until: _asm_app_status.resources | length == 0 | ||
retries: 120 | ||
delay: 10 | ||
loop: "{{ apps_list }}" | ||
loop_control: | ||
loop_var: app | ||
... |
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