diff --git a/ansible/templates/awxbackup_crd.yml.j2 b/ansible/templates/awxbackup_crd.yml.j2 index d0ad49a9..02e18a27 100644 --- a/ansible/templates/awxbackup_crd.yml.j2 +++ b/ansible/templates/awxbackup_crd.yml.j2 @@ -32,6 +32,9 @@ spec: tower_backup_pvc: description: Name of the PVC to be used for storing the backup type: string + tower_backup_pvc_namespace: + description: Namespace PVC is in + type: string tower_backup_size: description: Size of PVC type: string diff --git a/ansible/templates/awxrestore_crd.yml.j2 b/ansible/templates/awxrestore_crd.yml.j2 index 39b669a6..e7e65923 100644 --- a/ansible/templates/awxrestore_crd.yml.j2 +++ b/ansible/templates/awxrestore_crd.yml.j2 @@ -32,6 +32,9 @@ spec: tower_backup_pvc: description: Name of the PVC to be used for storing the backup type: string + tower_backup_pvc_namespace: + description: Namespace PVC is in + type: string tower_backup_dir: description: Backup directory name, a status found on the awxbackup object (towerBackupComplete) type: string diff --git a/deploy/awx-operator.yaml b/deploy/awx-operator.yaml index 6fc80e38..109337a2 100644 --- a/deploy/awx-operator.yaml +++ b/deploy/awx-operator.yaml @@ -560,6 +560,10 @@ spec: tower_backup_pvc: description: Name of the PVC to be used for storing the backup type: string + tower_backup_pvc_namespace: + default: 'default' + description: Namespace PVC is in + type: string tower_backup_size: description: Size of PVC type: string @@ -615,6 +619,10 @@ spec: tower_backup_pvc: description: Name of the PVC to be used for storing the backup type: string + tower_backup_pvc_namespace: + default: 'default' + description: Namespace PVC is in + type: string tower_backup_size: description: Size of PVC type: string diff --git a/deploy/crds/awxbackup_v1beta1_crd.yaml b/deploy/crds/awxbackup_v1beta1_crd.yaml index d0ad49a9..02e18a27 100644 --- a/deploy/crds/awxbackup_v1beta1_crd.yaml +++ b/deploy/crds/awxbackup_v1beta1_crd.yaml @@ -32,6 +32,9 @@ spec: tower_backup_pvc: description: Name of the PVC to be used for storing the backup type: string + tower_backup_pvc_namespace: + description: Namespace PVC is in + type: string tower_backup_size: description: Size of PVC type: string diff --git a/deploy/crds/awxrestore_v1beta1_crd.yaml b/deploy/crds/awxrestore_v1beta1_crd.yaml index 39b669a6..e7e65923 100644 --- a/deploy/crds/awxrestore_v1beta1_crd.yaml +++ b/deploy/crds/awxrestore_v1beta1_crd.yaml @@ -32,6 +32,9 @@ spec: tower_backup_pvc: description: Name of the PVC to be used for storing the backup type: string + tower_backup_pvc_namespace: + description: Namespace PVC is in + type: string tower_backup_dir: description: Backup directory name, a status found on the awxbackup object (towerBackupComplete) type: string diff --git a/roles/backup/defaults/main.yml b/roles/backup/defaults/main.yml index 59310cdd..2076c68c 100644 --- a/roles/backup/defaults/main.yml +++ b/roles/backup/defaults/main.yml @@ -4,6 +4,7 @@ tower_name: '' # Specify a pre-created PVC (name) to backup to tower_backup_pvc: '' +tower_backup_pvc_namespace: 'default' # Size of backup PVC if created dynamically tower_backup_size: '' diff --git a/roles/backup/tasks/cleanup.yml b/roles/backup/tasks/cleanup.yml index e20e8718..11dc6d07 100644 --- a/roles/backup/tasks/cleanup.yml +++ b/roles/backup/tasks/cleanup.yml @@ -11,6 +11,6 @@ community.kubernetes.k8s: name: "{{ meta.name }}-db-management" kind: Pod - namespace: "{{ meta.namespace }}" + namespace: "{{ tower_backup_pvc_namespace }}" state: absent force: true diff --git a/roles/backup/tasks/init.yml b/roles/backup/tasks/init.yml index 68fb305c..27158bf6 100644 --- a/roles/backup/tasks/init.yml +++ b/roles/backup/tasks/init.yml @@ -4,7 +4,7 @@ community.kubernetes.k8s: name: "{{ meta.name }}-db-management" kind: Pod - namespace: "{{ meta.namespace }}" + namespace: "{{ tower_backup_pvc_namespace }}" state: absent force: true wait: true @@ -14,7 +14,7 @@ k8s_info: name: "{{ tower_backup_pvc }}" kind: PersistentVolumeClaim - namespace: "{{ meta.namespace }}" + namespace: "{{ tower_backup_pvc_namespace }}" register: provided_pvc when: - tower_backup_pvc != '' @@ -48,16 +48,14 @@ - name: Create PVC for backup community.kubernetes.k8s: kind: PersistentVolumeClaim - namespace: "{{ meta.namespace }}" template: "backup_pvc.yml.j2" when: - tower_backup_pvc == '' or tower_backup_pvc is not defined - name: Create management pod from templated deployment config community.kubernetes.k8s: - name: "{{ meta.name }}-db-management" + name: "{{ tower_backup_pvc_namespace }}-db-management" kind: Deployment - namespace: "{{ meta.namespace }}" state: present template: "management-pod.yml.j2" wait: true diff --git a/roles/backup/templates/backup_pvc.yml.j2 b/roles/backup/templates/backup_pvc.yml.j2 index 693b00ec..57778b82 100644 --- a/roles/backup/templates/backup_pvc.yml.j2 +++ b/roles/backup/templates/backup_pvc.yml.j2 @@ -3,7 +3,7 @@ apiVersion: v1 kind: PersistentVolumeClaim metadata: name: {{ meta.name }}-backup-claim - namespace: {{ meta.namespace}} + namespace: {{ tower_backup_pvc_namespace }} spec: accessModes: - ReadWriteOnce diff --git a/roles/backup/templates/management-pod.yml.j2 b/roles/backup/templates/management-pod.yml.j2 index 87ddff8e..d938da20 100644 --- a/roles/backup/templates/management-pod.yml.j2 +++ b/roles/backup/templates/management-pod.yml.j2 @@ -3,7 +3,7 @@ apiVersion: v1 kind: Pod metadata: name: {{ meta.name }}-db-management - namespace: {{ meta.namespace }} + namespace: {{ tower_backup_pvc_namespace }} spec: containers: - name: {{ meta.name }}-db-management diff --git a/roles/backup/vars/main.yml b/roles/backup/vars/main.yml index 851b98f0..dbb48bf8 100644 --- a/roles/backup/vars/main.yml +++ b/roles/backup/vars/main.yml @@ -1,4 +1,3 @@ --- - deployment_type: "awx" tower_postgres_image: postgres:12 diff --git a/roles/restore/README.md b/roles/restore/README.md index 16e1d7ce..1325c402 100644 --- a/roles/restore/README.md +++ b/roles/restore/README.md @@ -29,8 +29,8 @@ metadata: namespace: my-namespace spec: tower_name: mytower - tower_backup_pvc: myoldtower-awxbackup-adfx7ciow - tower_backup_dir: tower-openshift-backup-2021-04-01-15:49:17 + tower_backup_pvc: awxbackup1-backup-claim + tower_backup_dir: /backups/tower-openshift-backup-2021-04-02-03:25:08 ``` Note that the `tower_name` above is the name of the AWX deployment you intend to create and restore to. diff --git a/roles/restore/defaults/main.yml b/roles/restore/defaults/main.yml index 67a38b79..3bafde7e 100644 --- a/roles/restore/defaults/main.yml +++ b/roles/restore/defaults/main.yml @@ -4,6 +4,7 @@ tower_name: '' # Required: specify a pre-created PVC (name) to restore from tower_backup_pvc: '' +tower_backup_pvc_namespace: 'default' # Required: backup name, found on the awxbackup object tower_backup_dir: '' diff --git a/roles/restore/tasks/cleanup.yml b/roles/restore/tasks/cleanup.yml index 9976a8c9..7b094f32 100644 --- a/roles/restore/tasks/cleanup.yml +++ b/roles/restore/tasks/cleanup.yml @@ -4,6 +4,6 @@ community.kubernetes.k8s: name: "{{ meta.name }}-db-management" kind: Pod - namespace: "{{ meta.namespace }}" + namespace: "{{ tower_backup_pvc_namespace }}" state: absent force: true diff --git a/roles/restore/tasks/init.yml b/roles/restore/tasks/init.yml index 009fba00..f650a568 100644 --- a/roles/restore/tasks/init.yml +++ b/roles/restore/tasks/init.yml @@ -4,7 +4,7 @@ community.kubernetes.k8s: name: "{{ meta.name }}-db-management" kind: Pod - namespace: "{{ meta.namespace }}" + namespace: "{{ tower_backup_pvc_namespace }}" state: absent force: true wait: true @@ -14,7 +14,7 @@ k8s_info: name: "{{ tower_backup_pvc }}" kind: PersistentVolumeClaim - namespace: "{{ meta.namespace }}" + namespace: "{{ tower_backup_pvc_namespace }}" register: provided_pvc when: - tower_backup_pvc != '' @@ -49,7 +49,6 @@ community.kubernetes.k8s: name: "{{ meta.name }}-db-management" kind: Deployment - namespace: "{{ meta.namespace }}" state: present template: "management-pod.yml.j2" wait: true diff --git a/roles/restore/tasks/preflight.yml b/roles/restore/tasks/preflight.yml index 108162ec..d9c98553 100644 --- a/roles/restore/tasks/preflight.yml +++ b/roles/restore/tasks/preflight.yml @@ -1,11 +1,17 @@ --- +- name: Create namespace for deployment + k8s: + name: "{{ meta.namespace }}" + kind: Namespace + state: present + # Check to make sure provided pvc exists, error loudly if not. Otherwise, the management pod will just stay in pending state forever. - name: Check provided PVC exists k8s_info: name: "{{ tower_backup_pvc }}" kind: PersistentVolumeClaim - namespace: "{{ meta.namespace }}" + namespace: "{{ tower_backup_pvc_namespace }}" register: provided_pvc when: - tower_backup_pvc != '' diff --git a/roles/restore/templates/management-pod.yml.j2 b/roles/restore/templates/management-pod.yml.j2 index 87ddff8e..d938da20 100644 --- a/roles/restore/templates/management-pod.yml.j2 +++ b/roles/restore/templates/management-pod.yml.j2 @@ -3,7 +3,7 @@ apiVersion: v1 kind: Pod metadata: name: {{ meta.name }}-db-management - namespace: {{ meta.namespace }} + namespace: {{ tower_backup_pvc_namespace }} spec: containers: - name: {{ meta.name }}-db-management