mirror of
https://github.com/ansible/awx-operator.git
synced 2026-05-06 21:32:52 +00:00
Create an event when pvc is not set to alert the user
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
---
|
||||
|
||||
- name: Update awxbackup status
|
||||
block:
|
||||
- name: Set apiVersion and kind variables
|
||||
set_fact:
|
||||
api_version: '{{ hostvars["localhost"]["inventory_file"].split("/")[4:6] | join("/") }}'
|
||||
kind: '{{ hostvars["localhost"]["inventory_file"].split("/")[6] }}'
|
||||
|
||||
- name: Update error status
|
||||
operator_sdk.util.k8s_status:
|
||||
api_version: '{{ api_version }}'
|
||||
kind: "{{ kind }}"
|
||||
name: "{{ meta.name }}"
|
||||
namespace: "{{ meta.namespace }}"
|
||||
status:
|
||||
error: "{{ error_msg }}"
|
||||
16
roles/backup/tasks/error_handling.yml
Normal file
16
roles/backup/tasks/error_handling.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
---
|
||||
|
||||
- name: Set apiVersion and kind variables
|
||||
set_fact:
|
||||
api_version: '{{ hostvars["localhost"]["inventory_file"].split("/")[4:6] | join("/") }}'
|
||||
kind: '{{ hostvars["localhost"]["inventory_file"].split("/")[6] }}'
|
||||
|
||||
- name: Determine the timestamp
|
||||
set_fact:
|
||||
now: '{{ lookup("pipe", "date +%FT%TZ") }}'
|
||||
|
||||
- name: Emit ocp event with error
|
||||
community.kubernetes.k8s:
|
||||
kind: Event
|
||||
namespace: "{{ meta.namespace }}"
|
||||
template: "event.yml.j2"
|
||||
@@ -17,17 +17,23 @@
|
||||
namespace: "{{ meta.namespace }}"
|
||||
register: provided_pvc
|
||||
when:
|
||||
- tower_backup_pvc != '' or tower_backup_pvc is defined
|
||||
- tower_backup_pvc != ''
|
||||
|
||||
- name: Update status
|
||||
set_fact:
|
||||
error_msg: "{{ tower_backup_pvc }} does not exist, please create this pvc first."
|
||||
notify: "Update awxbackup status"
|
||||
- name: Surface error to user
|
||||
block:
|
||||
- name: Set error message
|
||||
set_fact:
|
||||
error_msg: "{{ tower_backup_pvc }} does not exist, please create this pvc first."
|
||||
|
||||
- name: Fail early if pvc is defined but does not exist
|
||||
fail:
|
||||
msg: "{{ tower_backup_pvc }} does not exist, please create this pvc first."
|
||||
when: provided_pvc.resources | length == 0
|
||||
- name: Handle error
|
||||
import_tasks: error_handling.yml
|
||||
|
||||
- name: Fail early if pvc is defined but does not exist
|
||||
fail:
|
||||
msg: "{{ tower_backup_pvc }} does not exist, please create this pvc first."
|
||||
when:
|
||||
- tower_backup_pvc != ''
|
||||
- provided_pvc.resources | length == 0
|
||||
|
||||
# If tower_backup_pvc is defined, use in management-pod.yml.j2
|
||||
- name: Set default pvc name
|
||||
|
||||
17
roles/backup/templates/event.yml.j2
Normal file
17
roles/backup/templates/event.yml.j2
Normal file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Event
|
||||
metadata:
|
||||
name: backup-error.{{ now }}
|
||||
namespace: {{ meta.namespace }}
|
||||
involvedObject:
|
||||
apiVersion: awx.ansible.com/v1beta1
|
||||
kind: {{ kind }}
|
||||
name: {{ meta.name }}
|
||||
namespace: {{ meta.namespace }}
|
||||
message: {{ error_msg }}
|
||||
reason: BackupFailed
|
||||
type: Warning
|
||||
firstTimestamp: {{ now }}
|
||||
lastTimestamp: {{ now }}
|
||||
count: 1
|
||||
Reference in New Issue
Block a user