Rename product specific variable names

This commit is contained in:
Christian M. Adams
2021-04-27 22:51:29 -04:00
parent d743936ee4
commit 5ae36367a4
27 changed files with 128 additions and 128 deletions

View File

@@ -28,10 +28,10 @@ metadata:
name: awxbackup-2021-04-22
namespace: my-namespace
spec:
tower_name: mytower
deployment_name: mytower
```
Note that the `tower_name` above is the name of the AWX deployment you intend to backup from. The namespace above is the one containing the AWX deployment that will be backed up.
Note that the `deployment_name` above is the name of the AWX deployment you intend to backup from. The namespace above is the one containing the AWX deployment that will be backed up.
Finally, use `kubectl` to create the backup object in your cluster:
@@ -48,7 +48,7 @@ Role Variables
A custom, pre-created pvc can be used by setting the following variables.
```
tower_backup_pvc: 'awx-backup-volume-claim'
backup_pvc: 'awx-backup-volume-claim'
```
> If no pvc or storage class is provided, the cluster's default storage class will be used to create the pvc.
@@ -56,16 +56,16 @@ tower_backup_pvc: 'awx-backup-volume-claim'
This role will automatically create a pvc using a Storage Class if provided:
```
tower_backup_storage_class: 'standard'
tower_backup_size: '20Gi'
backup_storage_class: 'standard'
backup_storage_requirements: '20Gi'
```
By default, the backup pvc will be created in the same namespace the awxbackup object is created in. If you want your backup to be stored
in a specific namespace, you can do so by specifying `tower_backup_pvc_namespace`. Keep in mind that you will
in a specific namespace, you can do so by specifying `backup_pvc_namespace`. Keep in mind that you will
need to provide the same namespace when restoring.
```
tower_backup_pvc_namespace: 'custom-namespace'
backup_pvc_namespace: 'custom-namespace'
```
If a custom postgres configuration secret was used when deploying AWX, it will automatically be used by the backup role.

View File

@@ -1,13 +1,13 @@
---
# Required: specify name of tower deployment to backup from
tower_name: ''
deployment_name: ''
# Specify a pre-created PVC (name) to backup to
tower_backup_pvc: ''
tower_backup_pvc_namespace: "{{ meta.namespace }}"
backup_pvc: ''
backup_pvc_namespace: "{{ meta.namespace }}"
# Size of backup PVC if created dynamically
tower_backup_size: ''
backup_storage_requirements: ''
# Specify storage class to determine how to dynamically create PVC's with
tower_backup_storage_class: ''
backup_storage_class: ''

View File

@@ -5,7 +5,7 @@
version: v1beta1
kind: AWX
namespace: '{{ meta.namespace }}'
name: '{{ tower_name }}'
name: '{{ deployment_name }}'
register: _awx_cro
- name: Set AWX object
@@ -22,7 +22,7 @@
- name: Write awx object to pvc
k8s_exec:
namespace: "{{ tower_backup_pvc_namespace }}"
namespace: "{{ backup_pvc_namespace }}"
pod: "{{ meta.name }}-db-management"
command: >-
bash -c "echo '{{ awx_definition_file }}' > {{ backup_dir }}/awx_object"

View File

@@ -4,6 +4,6 @@
k8s:
name: "{{ meta.name }}-db-management"
kind: Pod
namespace: "{{ tower_backup_pvc_namespace }}"
namespace: "{{ backup_pvc_namespace }}"
state: absent
force: true

View File

@@ -4,7 +4,7 @@
k8s:
name: "{{ meta.name }}-db-management"
kind: Pod
namespace: "{{ tower_backup_pvc_namespace }}"
namespace: "{{ backup_pvc_namespace }}"
state: absent
force: true
wait: true
@@ -12,45 +12,45 @@
# 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 }}"
name: "{{ backup_pvc }}"
kind: PersistentVolumeClaim
namespace: "{{ tower_backup_pvc_namespace }}"
namespace: "{{ backup_pvc_namespace }}"
register: provided_pvc
when:
- tower_backup_pvc != ''
- backup_pvc != ''
- 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."
error_msg: "{{ backup_pvc }} does not exist, please create this pvc first."
- 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."
msg: "{{ backup_pvc }} does not exist, please create this pvc first."
when:
- tower_backup_pvc != ''
- backup_pvc != ''
- provided_pvc.resources | length == 0
# If tower_backup_pvc is defined, use in management-pod.yml.j2
# If backup_pvc is defined, use in management-pod.yml.j2
- name: Set default pvc name
set_fact:
_default_backup_pvc: "{{ tower_name }}-backup-claim"
_default_backup_pvc: "{{ deployment_name }}-backup-claim"
# by default, it will re-use the old pvc if already created (unless a pvc is provided)
- name: Set PVC to use for backup
set_fact:
backup_pvc: "{{ tower_backup_pvc | default(_default_backup_pvc, true) }}"
backup_claim: "{{ backup_pvc | default(_default_backup_pvc, true) }}"
- name: Create PVC for backup
k8s:
kind: PersistentVolumeClaim
template: "backup_pvc.yml.j2"
when:
- tower_backup_pvc == '' or tower_backup_pvc is not defined
- backup_pvc == '' or backup_pvc is not defined
- name: Create management pod from templated deployment config
k8s:
@@ -69,6 +69,6 @@
k8s_info:
api_version: "{{ api_version }}"
kind: "AWX" # Find a way to dynamically get this
name: "{{ tower_name }}"
name: "{{ deployment_name }}"
namespace: "{{ meta.namespace }}"
register: this_awx

View File

@@ -24,12 +24,12 @@
- name: Set flag signifying this backup was successful
set_fact:
tower_backup_complete: true
backup_complete: true
- include_tasks: cleanup.yml
when:
- this_backup['resources'][0]['status']['towerBackupDirectory'] is not defined
- this_backup['resources'][0]['status']['backupDirectory'] is not defined
- name: Update status variables
include_tasks: update_status.yml

View File

@@ -23,7 +23,7 @@
- name: Default label selector to custom resource generated postgres
set_fact:
postgres_label_selector: "app.kubernetes.io/name={{ tower_name }}-postgres"
postgres_label_selector: "app.kubernetes.io/name={{ deployment_name }}-postgres"
when: postgres_label_selector is not defined
- name: Get the postgres pod information
@@ -53,21 +53,21 @@
- name: Create directory for backup
k8s_exec:
namespace: "{{ tower_backup_pvc_namespace }}"
namespace: "{{ backup_pvc_namespace }}"
pod: "{{ meta.name }}-db-management"
command: >-
mkdir -p {{ backup_dir }}
- name: Precreate file for database dump
k8s_exec:
namespace: "{{ tower_backup_pvc_namespace }}"
namespace: "{{ backup_pvc_namespace }}"
pod: "{{ meta.name }}-db-management"
command: >-
touch {{ backup_dir }}/tower.db
- name: Set permissions on file for database dump
k8s_exec:
namespace: "{{ tower_backup_pvc_namespace }}"
namespace: "{{ backup_pvc_namespace }}"
pod: "{{ meta.name }}-db-management"
command: >-
bash -c "chmod 0600 {{ backup_dir }}/tower.db && chown postgres:root {{ backup_dir }}/tower.db"
@@ -88,7 +88,7 @@
- name: Write pg_dump to backup on PVC
k8s_exec:
namespace: "{{ tower_backup_pvc_namespace }}"
namespace: "{{ backup_pvc_namespace }}"
pod: "{{ meta.name }}-db-management"
command: >-
bash -c "PGPASSWORD={{ awx_postgres_pass }} {{ pgdump }} > {{ backup_dir }}/tower.db"

View File

@@ -55,7 +55,7 @@
- name: Write postgres configuration to pvc
k8s_exec:
namespace: "{{ tower_backup_pvc_namespace }}"
namespace: "{{ backup_pvc_namespace }}"
pod: "{{ meta.name }}-db-management"
command: >-
bash -c "echo '{{ secrets_file }}' > {{ backup_dir }}/secrets.yml"

View File

@@ -12,6 +12,6 @@
name: "{{ meta.name }}"
namespace: "{{ meta.namespace }}"
status:
towerBackupDirectory: "{{ backup_dir }}"
towerBackupClaim: "{{ backup_pvc }}"
when: tower_backup_complete
backupDirectory: "{{ backup_dir }}"
backupClaim: "{{ backup_claim }}"
when: backup_complete

View File

@@ -2,14 +2,14 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ tower_name }}-backup-claim
namespace: {{ tower_backup_pvc_namespace }}
name: {{ deployment_name }}-backup-claim
namespace: {{ backup_pvc_namespace }}
spec:
accessModes:
- ReadWriteOnce
{% if tower_backup_storage_class != '' %}
storageClassName: {{ tower_backup_storage_class }}
{% if backup_storage_class != '' %}
storageClassName: {{ backup_storage_class }}
{% endif %}
resources:
requests:
storage: {{ tower_backup_size | default('5Gi', true) }}
storage: {{ backup_storage_requirements | default('5Gi', true) }}

View File

@@ -3,11 +3,11 @@ apiVersion: v1
kind: Pod
metadata:
name: {{ meta.name }}-db-management
namespace: {{ tower_backup_pvc_namespace }}
namespace: {{ backup_pvc_namespace }}
spec:
containers:
- name: {{ meta.name }}-db-management
image: "{{ tower_postgres_image }}"
image: "{{ postgres_image }}"
imagePullPolicy: Always
command: ["sleep", "infinity"]
volumeMounts:
@@ -17,6 +17,6 @@ spec:
volumes:
- name: {{ meta.name }}-backup
persistentVolumeClaim:
claimName: {{ backup_pvc }}
claimName: {{ backup_claim }}
readOnly: false
restartPolicy: Never

View File

@@ -1,4 +1,4 @@
---
deployment_type: "awx"
tower_postgres_image: postgres:12
tower_backup_complete: false
postgres_image: postgres:12
backup_complete: false