mirror of
https://github.com/ansible/awx-operator.git
synced 2026-05-07 22:02:53 +00:00
Create an event when pvc is not set to alert the user
This commit is contained in:
@@ -22,7 +22,6 @@ spec:
|
|||||||
type: object
|
type: object
|
||||||
x-kubernetes-preserve-unknown-fields: true
|
x-kubernetes-preserve-unknown-fields: true
|
||||||
description: Schema validation for the AWXBackup CRD
|
description: Schema validation for the AWXBackup CRD
|
||||||
# TODO: Figure out how to require the tower_name field
|
|
||||||
properties:
|
properties:
|
||||||
spec:
|
spec:
|
||||||
type: object
|
type: object
|
||||||
@@ -30,3 +29,26 @@ spec:
|
|||||||
tower_name:
|
tower_name:
|
||||||
description: Name of the deployment to be backed up
|
description: Name of the deployment to be backed up
|
||||||
type: string
|
type: string
|
||||||
|
tower_backup_pvc:
|
||||||
|
description: Name of the PVC to be used for storing the backup
|
||||||
|
type: string
|
||||||
|
tower_backup_size:
|
||||||
|
description: Size of PVC
|
||||||
|
type: string
|
||||||
|
tower_backup_storage_class:
|
||||||
|
description: Storage class to use when creating PVC for backup
|
||||||
|
type: string
|
||||||
|
tower_secret_key_secret:
|
||||||
|
description: Custom secret_key secret name
|
||||||
|
type: string
|
||||||
|
tower_admin_password_secret:
|
||||||
|
description: Custom admin_password secret name
|
||||||
|
type: string
|
||||||
|
tower_broadcast_websocket_secret:
|
||||||
|
description: Custom broadcast_websocket secret name
|
||||||
|
type: string
|
||||||
|
tower_postgres_configuration_secret:
|
||||||
|
description: Custom postgres_configuration secret name
|
||||||
|
type: string
|
||||||
|
oneOf:
|
||||||
|
- required: ["tower_name"]
|
||||||
|
|||||||
@@ -550,7 +550,6 @@ spec:
|
|||||||
type: object
|
type: object
|
||||||
x-kubernetes-preserve-unknown-fields: true
|
x-kubernetes-preserve-unknown-fields: true
|
||||||
description: Schema validation for the AWXBackup CRD
|
description: Schema validation for the AWXBackup CRD
|
||||||
# TODO: Figure out how to require the tower_name field
|
|
||||||
properties:
|
properties:
|
||||||
spec:
|
spec:
|
||||||
type: object
|
type: object
|
||||||
@@ -558,3 +557,26 @@ spec:
|
|||||||
tower_name:
|
tower_name:
|
||||||
description: Name of the deployment to be backed up
|
description: Name of the deployment to be backed up
|
||||||
type: string
|
type: string
|
||||||
|
tower_backup_pvc:
|
||||||
|
description: Name of the PVC to be used for storing the backup
|
||||||
|
type: string
|
||||||
|
tower_backup_size:
|
||||||
|
description: Size of PVC
|
||||||
|
type: string
|
||||||
|
tower_backup_storage_class:
|
||||||
|
description: Storage class to use when creating PVC for backup
|
||||||
|
type: string
|
||||||
|
tower_secret_key_secret:
|
||||||
|
description: Custom secret_key secret name
|
||||||
|
type: string
|
||||||
|
tower_admin_password_secret:
|
||||||
|
description: Custom admin_password secret name
|
||||||
|
type: string
|
||||||
|
tower_broadcast_websocket_secret:
|
||||||
|
description: Custom broadcast_websocket secret name
|
||||||
|
type: string
|
||||||
|
tower_postgres_configuration_secret:
|
||||||
|
description: Custom postgres_configuration secret name
|
||||||
|
type: string
|
||||||
|
oneOf:
|
||||||
|
- required: ["tower_name"]
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ spec:
|
|||||||
type: object
|
type: object
|
||||||
x-kubernetes-preserve-unknown-fields: true
|
x-kubernetes-preserve-unknown-fields: true
|
||||||
description: Schema validation for the AWXBackup CRD
|
description: Schema validation for the AWXBackup CRD
|
||||||
# TODO: Figure out how to require the tower_name field
|
|
||||||
properties:
|
properties:
|
||||||
spec:
|
spec:
|
||||||
type: object
|
type: object
|
||||||
@@ -30,3 +29,26 @@ spec:
|
|||||||
tower_name:
|
tower_name:
|
||||||
description: Name of the deployment to be backed up
|
description: Name of the deployment to be backed up
|
||||||
type: string
|
type: string
|
||||||
|
tower_backup_pvc:
|
||||||
|
description: Name of the PVC to be used for storing the backup
|
||||||
|
type: string
|
||||||
|
tower_backup_size:
|
||||||
|
description: Size of PVC
|
||||||
|
type: string
|
||||||
|
tower_backup_storage_class:
|
||||||
|
description: Storage class to use when creating PVC for backup
|
||||||
|
type: string
|
||||||
|
tower_secret_key_secret:
|
||||||
|
description: Custom secret_key secret name
|
||||||
|
type: string
|
||||||
|
tower_admin_password_secret:
|
||||||
|
description: Custom admin_password secret name
|
||||||
|
type: string
|
||||||
|
tower_broadcast_websocket_secret:
|
||||||
|
description: Custom broadcast_websocket secret name
|
||||||
|
type: string
|
||||||
|
tower_postgres_configuration_secret:
|
||||||
|
description: Custom postgres_configuration secret name
|
||||||
|
type: string
|
||||||
|
oneOf:
|
||||||
|
- required: ["tower_name"]
|
||||||
|
|||||||
@@ -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 }}"
|
namespace: "{{ meta.namespace }}"
|
||||||
register: provided_pvc
|
register: provided_pvc
|
||||||
when:
|
when:
|
||||||
- tower_backup_pvc != '' or tower_backup_pvc is defined
|
- tower_backup_pvc != ''
|
||||||
|
|
||||||
- name: Update status
|
- name: Surface error to user
|
||||||
set_fact:
|
block:
|
||||||
error_msg: "{{ tower_backup_pvc }} does not exist, please create this pvc first."
|
- name: Set error message
|
||||||
notify: "Update awxbackup status"
|
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
|
- name: Handle error
|
||||||
fail:
|
import_tasks: error_handling.yml
|
||||||
msg: "{{ tower_backup_pvc }} does not exist, please create this pvc first."
|
|
||||||
when: provided_pvc.resources | length == 0
|
- 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
|
# If tower_backup_pvc is defined, use in management-pod.yml.j2
|
||||||
- name: Set default pvc name
|
- 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
|
||||||
@@ -11,4 +11,3 @@
|
|||||||
group: awx.ansible.com
|
group: awx.ansible.com
|
||||||
kind: AWXBackup
|
kind: AWXBackup
|
||||||
role: backup
|
role: backup
|
||||||
reconcilePeriod: 360m
|
|
||||||
|
|||||||
Reference in New Issue
Block a user