From d4b295e8b4bb4a9233275edf576ea76e85bc2bc7 Mon Sep 17 00:00:00 2001 From: aknochow Date: Tue, 24 Feb 2026 16:06:24 -0500 Subject: [PATCH] Add automatic backup PVC creation with create_backup_pvc option (#2097) When users specify a custom backup_pvc name, the operator now automatically creates the PVC instead of failing with "does not exist, please create this pvc first." Changes: - Add create_backup_pvc variable (default: true) to backup defaults - Update error condition to check create_backup_pvc before failing - Update PVC creation condition to include create_backup_pvc - Add create_backup_pvc field to AWXBackup CRD Users who want the previous behavior can set create_backup_pvc: false. --- config/crd/bases/awx.ansible.com_awxbackups.yaml | 4 ++++ roles/backup/defaults/main.yml | 3 +++ roles/backup/tasks/init.yml | 7 ++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/config/crd/bases/awx.ansible.com_awxbackups.yaml b/config/crd/bases/awx.ansible.com_awxbackups.yaml index 863ac77f..5716108d 100644 --- a/config/crd/bases/awx.ansible.com_awxbackups.yaml +++ b/config/crd/bases/awx.ansible.com_awxbackups.yaml @@ -51,6 +51,10 @@ spec: backup_pvc: description: Name of the backup PVC type: string + create_backup_pvc: + description: If true (default), automatically create the backup PVC if it does not exist + type: boolean + default: true backup_pvc_namespace: description: (Deprecated) Namespace the PVC is in type: string diff --git a/roles/backup/defaults/main.yml b/roles/backup/defaults/main.yml index 255a1f01..59595b79 100644 --- a/roles/backup/defaults/main.yml +++ b/roles/backup/defaults/main.yml @@ -8,6 +8,9 @@ api_version: '{{ deployment_type }}.ansible.com/v1beta1' backup_pvc: '' backup_pvc_namespace: "{{ ansible_operator_meta.namespace }}" +# If true (default), automatically create the backup PVC if it does not exist +create_backup_pvc: true + # Size of backup PVC if created dynamically backup_storage_requirements: '' diff --git a/roles/backup/tasks/init.yml b/roles/backup/tasks/init.yml index 377e4c1e..a24f12e7 100644 --- a/roles/backup/tasks/init.yml +++ b/roles/backup/tasks/init.yml @@ -22,17 +22,18 @@ block: - name: Set error message set_fact: - error_msg: "{{ backup_pvc }} does not exist, please create this pvc first." + error_msg: "{{ backup_pvc }} does not exist, please create this pvc first or ensure create_backup_pvc is set to true (default) for automatic backup_pvc creation." - name: Handle error import_tasks: error_handling.yml - name: Fail early if pvc is defined but does not exist fail: - msg: "{{ backup_pvc }} does not exist, please create this pvc first." + msg: "{{ backup_pvc }} does not exist, please create this pvc first or ensure create_backup_pvc is set to true (default) for automatic backup_pvc creation." when: - backup_pvc != '' - provided_pvc.resources | length == 0 + - not create_backup_pvc | bool # If backup_pvc is defined, use in management-pod.yml.j2 - name: Set default pvc name @@ -60,7 +61,7 @@ namespace: "{{ backup_pvc_namespace }}" ownerReferences: null when: - - backup_pvc == '' or backup_pvc is not defined + - (backup_pvc == '' or backup_pvc is not defined) or (create_backup_pvc | bool) - name: Set default postgres image set_fact: