Create an event when pvc is not set to alert the user

This commit is contained in:
Christian M. Adams
2021-03-31 15:21:42 -04:00
parent 6bc149bae2
commit 80c8d87f71
8 changed files with 117 additions and 30 deletions

View File

@@ -22,7 +22,6 @@ spec:
type: object
x-kubernetes-preserve-unknown-fields: true
description: Schema validation for the AWXBackup CRD
# TODO: Figure out how to require the tower_name field
properties:
spec:
type: object
@@ -30,3 +29,26 @@ spec:
tower_name:
description: Name of the deployment to be backed up
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"]

View File

@@ -550,7 +550,6 @@ spec:
type: object
x-kubernetes-preserve-unknown-fields: true
description: Schema validation for the AWXBackup CRD
# TODO: Figure out how to require the tower_name field
properties:
spec:
type: object
@@ -558,3 +557,26 @@ spec:
tower_name:
description: Name of the deployment to be backed up
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"]

View File

@@ -22,7 +22,6 @@ spec:
type: object
x-kubernetes-preserve-unknown-fields: true
description: Schema validation for the AWXBackup CRD
# TODO: Figure out how to require the tower_name field
properties:
spec:
type: object
@@ -30,3 +29,26 @@ spec:
tower_name:
description: Name of the deployment to be backed up
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"]

View File

@@ -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 }}"

View 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"

View File

@@ -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

View 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

View File

@@ -11,4 +11,3 @@
group: awx.ansible.com
kind: AWXBackup
role: backup
reconcilePeriod: 360m