Simplify vars needed for restore CR & do not garbage collect secrets

This commit is contained in:
Christian M. Adams
2021-04-23 17:12:54 -04:00
parent 57f9530198
commit c817a2234d
9 changed files with 62 additions and 25 deletions

View File

@@ -30,13 +30,16 @@ spec:
description: Name of the deployment to be restored to description: Name of the deployment to be restored to
type: string type: string
tower_backup_pvc: tower_backup_pvc:
description: Name of the PVC to be restored from description: Name of the PVC to be restored from, set as a status found on the awxbackup object (towerBackupClaim)
type: string type: string
tower_backup_pvc_namespace: tower_backup_pvc_namespace:
description: Namespace the PVC is in description: Namespace the PVC is in
type: string type: string
tower_backup_dir: tower_backup_dir:
description: Backup directory name, a status found on the awxbackup object (towerBackupComplete) description: Backup directory name, set as a status found on the awxbackup object (towerBackupDirectory)
type: string
tower_backup:
description: AWXBackup object name
type: string type: string
tower_secret_key_secret: tower_secret_key_secret:
description: Custom secret_key secret name description: Custom secret_key secret name
@@ -54,4 +57,4 @@ spec:
description: Label selector used to identify postgres pod for backing up data description: Label selector used to identify postgres pod for backing up data
type: string type: string
oneOf: oneOf:
- required: ["tower_name", "tower_backup_pvc", "tower_backup_pvc_namespace", "tower_backup_dir"] - required: ["tower_name", "tower_backup_pvc_namespace"]

View File

@@ -482,13 +482,16 @@ spec:
description: Name of the deployment to be restored to description: Name of the deployment to be restored to
type: string type: string
tower_backup_pvc: tower_backup_pvc:
description: Name of the PVC to be restored from description: Name of the PVC to be restored from, set as a status found on the awxbackup object (towerBackupClaim)
type: string type: string
tower_backup_pvc_namespace: tower_backup_pvc_namespace:
description: Namespace the PVC is in description: Namespace the PVC is in
type: string type: string
tower_backup_dir: tower_backup_dir:
description: Backup directory name, a status found on the awxbackup object (towerBackupComplete) description: Backup directory name, set as a status found on the awxbackup object (towerBackupDirectory)
type: string
tower_backup:
description: AWXBackup object name
type: string type: string
tower_secret_key_secret: tower_secret_key_secret:
description: Custom secret_key secret name description: Custom secret_key secret name
@@ -506,7 +509,7 @@ spec:
description: Label selector used to identify postgres pod for backing up data description: Label selector used to identify postgres pod for backing up data
type: string type: string
oneOf: oneOf:
- required: ["tower_name", "tower_backup_pvc", "tower_backup_pvc_namespace", "tower_backup_dir"] - required: ["tower_name", "tower_backup_pvc_namespace"]
--- ---
apiVersion: rbac.authorization.k8s.io/v1 apiVersion: rbac.authorization.k8s.io/v1

View File

@@ -30,13 +30,16 @@ spec:
description: Name of the deployment to be restored to description: Name of the deployment to be restored to
type: string type: string
tower_backup_pvc: tower_backup_pvc:
description: Name of the PVC to be restored from description: Name of the PVC to be restored from, set as a status found on the awxbackup object (towerBackupClaim)
type: string type: string
tower_backup_pvc_namespace: tower_backup_pvc_namespace:
description: Namespace the PVC is in description: Namespace the PVC is in
type: string type: string
tower_backup_dir: tower_backup_dir:
description: Backup directory name, a status found on the awxbackup object (towerBackupComplete) description: Backup directory name, set as a status found on the awxbackup object (towerBackupDirectory)
type: string
tower_backup:
description: AWXBackup object name
type: string type: string
tower_secret_key_secret: tower_secret_key_secret:
description: Custom secret_key secret name description: Custom secret_key secret name
@@ -54,4 +57,4 @@ spec:
description: Label selector used to identify postgres pod for backing up data description: Label selector used to identify postgres pod for backing up data
type: string type: string
oneOf: oneOf:
- required: ["tower_name", "tower_backup_pvc", "tower_backup_pvc_namespace", "tower_backup_dir"] - required: ["tower_name", "tower_backup_pvc_namespace"]

View File

@@ -25,7 +25,7 @@ Then create a file named `backup-awx.yml` with the following contents:
apiVersion: awx.ansible.com/v1beta1 apiVersion: awx.ansible.com/v1beta1
kind: AWXBackup kind: AWXBackup
metadata: metadata:
name: awxbackup name: awxbackup-2021-04-22
namespace: my-namespace namespace: my-namespace
spec: spec:
tower_name: mytower tower_name: mytower

View File

@@ -32,9 +32,8 @@ metadata:
namespace: my-namespace namespace: my-namespace
spec: spec:
tower_name: mytower tower_name: mytower
tower_backup_pvc: myoldtower-backup-claim tower_backup: awxbackup-2021-04-22
tower_backup_pvc_namespace: 'old-awx-namespace' tower_backup_pvc_namespace: 'old-awx-namespace'
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. Note that the `tower_name` above is the name of the AWX deployment you intend to create and restore to.
@@ -92,6 +91,13 @@ If a custom postgres configuration secret was used when deploying AWX, it must b
tower_postgres_configuration_secret: 'awx-postgres-configuration' tower_postgres_configuration_secret: 'awx-postgres-configuration'
``` ```
If the awxbackup object no longer exists, it is still possible to restore from the backup it created by specifying the pvc name and the back directory.
```
tower_backup_pvc: myoldtower-backup-claim
tower_backup_dir: /backups/tower-openshift-backup-2021-04-02-03:25:08
```
Testing Testing
---------------- ----------------

View File

@@ -6,14 +6,9 @@ tower_name: ''
tower_backup_pvc: '' tower_backup_pvc: ''
tower_backup_pvc_namespace: '' tower_backup_pvc_namespace: ''
# TODO: If the backup_dir is not provided, it should default to the most recent backup based on the timestamp at the end of the file name.
# Required: backup name, found on the awxbackup object # Required: backup name, found on the awxbackup object
tower_backup_dir: '' tower_backup_dir: ''
# TODO: Should we add a unique id at the end of the secret when backing up, then use it here?
# or will that make future backups more complicated because the user will have to specify the names of all the secrets?
# Names of any secrets you want to use instead of the ones in the backup
# TODO: Is this necessary? User's will be able to use the rekey role # TODO: Is this necessary? User's will be able to use the rekey role
tower_admin_password_secret: "{{ tower_name }}-admin-password" tower_admin_password_secret: "{{ tower_name }}-admin-password"

View File

@@ -7,3 +7,18 @@
namespace: "{{ tower_backup_pvc_namespace }}" namespace: "{{ tower_backup_pvc_namespace }}"
state: absent state: absent
force: true force: true
- name: Remove ownerReferences from secrets to avoid garbage collection
k8s:
definition:
apiVersion: v1
kind: Secret
metadata:
name: '{{ item }}'
namespace: '{{ meta.namespace }}'
ownerReferences: null
loop:
- '{{ tower_name }}-admin-password'
- '{{ tower_name }}-secret-key'
- '{{ tower_name }}-postgres-configuration'
- '{{ tower_name }}-broadcast-websocket'

View File

@@ -1,12 +1,24 @@
--- ---
- name: Set default pvc name
set_fact:
_default_backup_pvc: "{{ tower_name }}-backup-claim"
# by default, it will re-use the old pvc if already created (unless pvc is provided) - name: Set variables from awxbackup object statuses if provided
- name: Set PVC to use for backup block:
set_fact: - name: Look up details for the backup object
backup_pvc: "{{ tower_backup_pvc | default(_default_backup_pvc, true) }}" k8s_info:
api_version: "{{ api_version }}"
kind: "AWXBackup"
name: "{{ tower_backup }}"
namespace: "{{ tower_backup_pvc_namespace }}"
register: this_backup
- name: Set backup pvc name from status
set_fact:
tower_backup_pvc: "{{ this_backup['resources'][0]['status']['towerBackupClaim'] }}"
- name: Set tmp backup directory from status
set_fact:
tower_backup_dir: "{{ this_backup['resources'][0]['status']['towerBackupDirectory'] }}"
when:
- tower_backup != '' or tower_backup is defined
# Check to make sure provided pvc exists, error loudly if not. Otherwise, the management pod will just stay in pending state forever. # 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 - name: Check provided PVC exists

View File

@@ -17,6 +17,6 @@ spec:
volumes: volumes:
- name: {{ meta.name }}-backup - name: {{ meta.name }}-backup
persistentVolumeClaim: persistentVolumeClaim:
claimName: {{ backup_pvc }} claimName: {{ tower_backup_pvc }}
readOnly: false readOnly: false
restartPolicy: Never restartPolicy: Never