-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable container based database migration support
* Add support for container based database migration via CR * Update operator role to enable command execution on a pod * Add check to postgres role around migration * Add migration of data tasks * Add scale down tasks * Update status role to record db migration * Misc. fix for conflicting label selectors fixes #8472 https://pulp.plan.io/issues/8472
- Loading branch information
1 parent
32ffe8d
commit 30f45a3
Showing
23 changed files
with
262 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Enable container based database migration support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
--- | ||
|
||
- name: Store Database Configuration | ||
set_fact: | ||
migrant_postgres_user: "{{ old_pg_config['resources'][0]['data']['username'] | b64decode }}" | ||
migrant_postgres_pass: "{{ old_pg_config['resources'][0]['data']['password'] | b64decode }}" | ||
migrant_postgres_database: "{{ old_pg_config['resources'][0]['data']['database'] | b64decode }}" | ||
migrant_postgres_port: "{{ old_pg_config['resources'][0]['data']['port'] | b64decode }}" | ||
migrant_postgres_host: "{{ old_pg_config['resources'][0]['data']['host'] | b64decode }}" | ||
|
||
- name: Default label selector to custom resource generated postgres | ||
set_fact: | ||
postgres_label_selector: "app={{ meta.name }}-{{ deployment_type }}-postgres" | ||
when: postgres_label_selector is not defined | ||
|
||
- name: Get the postgres pod information | ||
k8s_info: | ||
kind: Pod | ||
namespace: '{{ meta.namespace }}' | ||
label_selectors: | ||
- "{{ postgres_label_selector }}" | ||
register: postgres_pod | ||
until: "postgres_pod['resources'][0]['status']['phase'] == 'Running'" | ||
delay: 5 | ||
retries: 60 | ||
|
||
- name: Set the resource pod name as a variable. | ||
set_fact: | ||
postgres_pod_name: "{{ postgres_pod['resources'][0]['metadata']['name'] }}" | ||
|
||
- include: scale_down.yml deployment_name={{ item }} | ||
with_items: | ||
- "{{ meta.name }}-api" | ||
- "{{ meta.name }}-content" | ||
- "{{ meta.name }}-resource-manager" | ||
- "{{ meta.name }}-worker" | ||
- "{{ meta.name }}-web" | ||
|
||
- name: Set pg_dump command | ||
set_fact: | ||
pgdump: >- | ||
pg_dump --clean --create | ||
-h {{ migrant_postgres_host }} | ||
-U {{ migrant_postgres_user }} | ||
-d {{ migrant_postgres_database }} | ||
-p {{ migrant_postgres_port }} | ||
- name: Set pg_restore command | ||
set_fact: | ||
psql_restore: >- | ||
psql -U {{ postgres_user }} | ||
-d {{ postgres_database }} | ||
-p {{ postgres_port }} | ||
- name: Stream backup from pg_dump to the new postgresql container | ||
community.kubernetes.k8s_exec: | ||
namespace: "{{ meta.namespace }}" | ||
pod: "{{ postgres_pod_name }}" | ||
command: | | ||
bash -c """ | ||
set -e -o pipefail | ||
PGPASSWORD={{ migrant_postgres_pass }} {{ pgdump }} | PGPASSWORD={{ postgres_pass }} {{ psql_restore }} | ||
echo 'Successful' | ||
""" | ||
register: data_migration | ||
failed_when: "'Successful' not in data_migration['stdout']" | ||
|
||
- name: Set flag signifying that this instance has been migrated | ||
set_fact: | ||
postgres_migrated_from_secret: "{{ postgres_migrant_configuration_secret }}" | ||
|
||
- name: Migration succesful from previous database | ||
debug: | ||
msg: "Database migrated from secret: {{ postgres_migrated_from_secret }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
|
||
- name: Check for presence of Deployment | ||
k8s_info: | ||
api_version: v1 | ||
kind: Deployment | ||
name: "{{ deployment_name }}" | ||
namespace: "{{ meta.namespace }}" | ||
register: scale_deployment | ||
|
||
- name: Scale down Deployment for migration | ||
k8s_scale: | ||
api_version: v1 | ||
kind: Deployment | ||
name: "{{ deployment_name }}" | ||
namespace: "{{ meta.namespace }}" | ||
replicas: 0 | ||
when: scale_deployment['resources'] | length |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.