Skip to content

Commit 9c06090

Browse files
jmckulkjkatz
authored andcommitted
Adds ansible roles for pgo-installer
These ansible roles will setup, run, and cleanup the necessary resources for the install job depending on the tags that are used and the settings in the inventory file. The roles will run the preflight checks on the inventory file before the job is submitted. This will help provide the use more immediate feedback if there is an error in the inventory file. Preflight checks are also added for specific container install checks that need to be done. This commit also adds documentation for both the pgo-installer image and the Ansible roles for the pgo-installer. Updates ansible roles for postgres-operator to fix bug. Task was referencing backrest_aws_s3_key_secret instead of backrest_aws_s3_secret.
1 parent 53ebae6 commit 9c06090

File tree

14 files changed

+586
-6
lines changed

14 files changed

+586
-6
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: "Deploy with PostgreSQL Operator Installer (pgo-installer)"
3+
date:
4+
draft: false
5+
weight: 100
6+
---
7+
8+
## Install the Postgres Operator with Installer Image
9+
10+
The following jobs can be run to install, update, and uninstall the Crunchy
11+
PostgreSQL Operator in your Kubernetes or OpenShift cluster using the
12+
pgo-installer image. Examples of these job can be found in
13+
`$PGOROOT/installers/pgo-installer/ansible/roles/pgo-installer/templates`. The
14+
job templates will need to updated with the following variables to run correctly.
15+
16+
### Installer Namespace
17+
The job template allows you to specify the namespace in
18+
which to run the install job. This does not specify which namespace the
19+
postgres-operator will be installed but they can both be in the same namespace.
20+
The namespace should be defined in place of the `{{ pgo_installer_namespace }}`
21+
variable.
22+
23+
### Cluster Resources
24+
#### Service Account
25+
The postgres-operator-installer
26+
requires a service account with cluster-admin privileges. You can create a
27+
service account manually and assign it to the job by updating the `{{
28+
pgo_installer_sa }}` variable.
29+
30+
#### Config Map
31+
The ansible installer used by the `pgo-installer` image requires
32+
an inventory file to be created as a configmap in your environment. This
33+
configmap will be used to install the PostgreSQL Operator and should meet all
34+
of the requirements outlined in the ansible install instructions.
35+
36+
### Job Varibles
37+
#### Command
38+
The command defined in the installer job uses
39+
the `pgo-install.sh` script to pass in the ansible tag to be run. The command
40+
can use any of the tags supported by the ansible installer.
41+
42+
#### Image Prefix and Tag
43+
The install job uses the `pgo-installer` image that is
44+
built using each version of the ansible installer. You will need to update the
45+
`{{ pgo_image_prefix }}` and `{{ pgo_image_tag }}` for the version of the
46+
installer that you are using. The `pgo-installer` tag must match the version of
47+
the Crunchy PostgreSQL Operator that you are installing.
48+
49+
#### Image Pull Policy
50+
The image pull policy needs to be defined for your job.
51+
In most cases this should be updated to `IfNotPresent`.
52+
53+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
title: "Ansible Roles for pgo-installer"
3+
date:
4+
draft: false
5+
weight: 20
6+
---
7+
8+
The ansible roles for the `pgo-installer` can be used to setup and run the
9+
install jobs with the `pgo-installer` image. Ansible will perform the steps
10+
oulined in the [Deploy with PostgreSQL Operator
11+
Installer](#/installation/postgres-operator-install).
12+
13+
## Prerequisites
14+
The following is required prior to installing Crunchy PostgreSQL Operator
15+
using Ansible:
16+
17+
* [postgres-operator playbooks](https://github.com/CrunchyData/postgres-operator/) source code for the target version
18+
* Ansible 2.8.0+
19+
20+
### Updating the Inventory file
21+
The PostgreSQL Operator Installer requires an inventory file to be installed.
22+
This inventory file must be created as a configmap that is mounted by the
23+
`pgo-installer` image. Once mounted, the file can be used to configure how the
24+
operator will function when deployed into Kubernetes.
25+
26+
An example inventory file can be found here:
27+
`$PGOROOT/installers/ansible/inventory`
28+
29+
Please reference the [Configuring the Inventory File](/installation/install-with-ansible/prerequisites#configuring-the-inventory-file)
30+
documentation as you update the inventory file.
31+
32+
#### PGO-Installer Specific Inventory Options
33+
The PostgreSQL Operator Installer has settings defined in the example inventory
34+
file that are not referenced in the [Configuring the Inventory File](i/installation/install-with-ansible/prerequisites#configuring-the-inventory-file)
35+
section of the documentation.
36+
37+
| Name | Default | Required | Description |
38+
|------|---------|----------|-------------|
39+
| `kubernetes_in_cluster` | false | **Required** | Set to true allow the installer to run from within a Kubernetes cluster. This must be true to use the `pgo-installer`. |
40+
| `use_cluster_admin` | false | **Required** | Set to true allow the installer to use cluster-admin to setup cluster-wide resources. This must be true to use the `pgo-installer`|
41+
| `pgo_installer_environment` | `kubernetes` | **Required** | Specifies if the Ansible Roles for PGO-Installer should use `kubectl` or `oc`. Options: `kubernetes`, `openshift` |
42+
43+
You have the option to manually create the resources needed to run the
44+
PostgreSQL Operator Installer. If you manually create the resources you can
45+
disable their creation and provide the name to your resource using the following
46+
options.
47+
48+
| Name | Default | Required | Description |
49+
|------|---------|----------|-------------|
50+
| `pgo_installer_namespace` | `pgo-install` | | Defines the namespace in which the install job will run. |
51+
| `pgo_installer_sa` | `pgo-installer-sa` | | Defines the name of the `serviceaccount` used by the `pgo-installer`. |
52+
| `pgo_installer_crb` | `pgo_installer_crb` | | Defines the name of the `clusterrolebinding` that is given to the `pgo_installer_sa` service account. |
53+
| `pgo_installer_configmap` | `pgo-installer-inventory` | | Defines the name of the `configmap` that is mounted by the `pgo-installer` and stores the inventory file for the PostgreSQL Operator install. |
54+
| `create_pgo_installer_namespace` | false | | Enables creation of the `pgo_installer_namespace` |
55+
| `create_pgo_installer_service_account` | false | | Enables the creation of the `pgo_installer_sa`. This `serviceaccount` is only created if `use_cluster_admin` is true. |
56+
| `create_pgo_installer_clusterrolebinding` | false | | Enables thecreation of the `pgo_installer_crb`. This `clusterrolebinding` is only created if `use_cluster_admin` is true. |
57+
| `create_pgo_installer_configmap` | false | |Enables the creation of the `pgo_installer_configmap` |
58+
59+
### Ansible Role Options
60+
| Tag Name | Description |
61+
|----------|--------------|
62+
| `install-container` | Uses the `pgo-installer` image to install the PostgreSQL Operator. |
63+
| `update-container` | Uses the `pgo-installer` image to update the PostgreSQL Operator. |
64+
| `uninstall-container` | Uses the `pgo-installer` image to uninstall the PostgreSQL Operator. |
65+
| `clean` | This option can be added to the `install-container`, `update-container`, and `uninstall-container` tags to delete the job after it completes. |
66+
| `clean-all` | The `namespace` and `clusterrolebinding` will be deleted if they exist. |
67+

installers/ansible/inventory

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,10 @@ crunchy_debug='false'
5151
# needed by the pgo-install job. If you create these resources manually, these
5252
# options can be disabled. If these resource are not enabled here they must be
5353
# created manually
54-
55-
# Defines the environment where the installer will run. Options are kubernetes
56-
# and openshift.
57-
# Default: kubernetes
58-
# pgo_installer_environment='kubernetes'
54+
# create_pgo_installer_namespace='false'
55+
# create_pgo_installer_service_account='false'
56+
# create_pgo_installer_clusterrolebinding='false'
57+
# create_pgo_installer_configmap='false'
5958

6059
# Deploy into Openshift
6160
# ==================

installers/ansible/roles/pgo-operator/tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@
194194
--from-file=sshd_config='{{ role_path }}/files/pgo-backrest-repo/sshd_config' \
195195
--from-file=aws-s3-ca.crt='{{ role_path }}/files/pgo-backrest-repo/aws-s3-ca.crt' \
196196
--from-literal=aws-s3-key='{{ backrest_aws_s3_key }}' \
197-
--from-literal=aws-s3-key-secret='{{ backrest_aws_s3_key_secret }}' \
197+
--from-literal=aws-s3-key-secret='{{ backrest_aws_s3_secret }}' \
198198
-n {{ pgo_operator_namespace }}
199199
tags:
200200
- install
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
- name: Deploy Crunchy PostgreSQL Operator
3+
hosts: all
4+
vars:
5+
max_storage_configs: 50 # the max num of storage configs that can be defined in the inventory
6+
max_resource_configs: 50 # the max num of resource configs that can be defined in the inventory
7+
gather_facts: true
8+
roles:
9+
- pgo-preflight
10+
- pgo-installer
11+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
pgo_installer_namespace: "pgo-install"
3+
pgo_installer_sa: "pgo-installer-sa"
4+
pgo_installer_crb: "pgo-installer-crb"
5+
pgo_installer_role: "cluster-admin"
6+
pgo_installer_environment: "kubernetes"
7+
pgo_installer_configmap: "pgo-installer-inventory"
8+
job_wait_timeout: 300s
9+
installer_img_pull_policy: "IfNotPresent"
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
---
2+
- name: Set output directory fact
3+
set_fact:
4+
output_dir: "{{ ansible_env.HOME }}/.pgo/{{ pgo_installer_namespace }}/output"
5+
tags:
6+
- always
7+
8+
- name: Ensure output directory exists
9+
file:
10+
path: "{{ output_dir }}"
11+
state: directory
12+
mode: 0700
13+
tags:
14+
- always
15+
16+
- include_vars: openshift.yml
17+
when: pgo_installer_environment == 'openshift'
18+
tags:
19+
- always
20+
21+
- name: Use kubectl or oc
22+
set_fact:
23+
kubectl_or_oc: "{{ openshift_oc_bin if openshift_oc_bin is defined else 'kubectl' }}"
24+
tags:
25+
- always
26+
27+
- name: Clean all jobs
28+
set_fact:
29+
job: "all"
30+
tags:
31+
- always
32+
33+
- name: Check Run Setup
34+
set_fact:
35+
run_setup: true
36+
tags:
37+
- install-container
38+
- uninstall-container
39+
- update-container
40+
41+
- name: Setup Install Container
42+
when: run_setup | default(False) | bool
43+
tags:
44+
- always
45+
block:
46+
- name: Check Install Namespace
47+
when: not (create_pgo_installer_namespace | default(False) | bool)
48+
shell: "{{ kubectl_or_oc }} get namespace {{ pgo_installer_namespace }}"
49+
50+
- name: Create Install Namespace
51+
when: create_pgo_installer_namespace | default(False) | bool
52+
shell: "{{ kubectl_or_oc }} create namespace {{ pgo_installer_namespace }}"
53+
54+
- name: Check PGO-Install Service Account
55+
when:
56+
- use_cluster_admin | default(False) | bool
57+
- not (create_pgo_installer_service_account | default(False) | bool)
58+
shell: "{{ kubectl_or_oc }} get serviceaccount {{ pgo_installer_sa }} -n {{ pgo_installer_namespace }}"
59+
60+
- name: Create PGO-Install Service Account
61+
when:
62+
- use_cluster_admin | default(False) | bool
63+
- create_pgo_installer_service_account | default(False) | bool
64+
shell: "{{ kubectl_or_oc }} create serviceaccount {{ pgo_installer_sa }} -n {{ pgo_installer_namespace }}"
65+
66+
- name: Check PGO-Installer Cluster Role Binding
67+
when:
68+
- use_cluster_admin | default(False) | bool
69+
- not (create_pgo_installer_clusterrolebinding | default(False) | bool)
70+
shell: "{{ kubectl_or_oc }} get clusterrolebinding {{ pgo_installer_crb }}"
71+
72+
- name: Create PGO-Installer Cluster Role Binding
73+
when:
74+
- use_cluster_admin | default(False) | bool
75+
- create_pgo_installer_clusterrolebinding | default(False) | bool
76+
shell: "{{ kubectl_or_oc }} create clusterrolebinding {{ pgo_installer_crb }} --clusterrole={{ pgo_installer_role }} --serviceaccount={{ pgo_installer_namespace }}:{{ pgo_installer_sa }}"
77+
78+
- name: Check Inventory Config Map
79+
when:
80+
- not (create_pgo_installer_configmap | default(False) | bool)
81+
shell: "{{ kubectl_or_oc }} get configmap {{ pgo_installer_configmap }} -n {{ pgo_installer_namespace }}"
82+
83+
- name: Create Inventory Config Map
84+
when:
85+
- create_pgo_installer_configmap | default(False) | bool
86+
shell: "{{ kubectl_or_oc }} create configmap {{ pgo_installer_configmap }} -n {{ pgo_installer_namespace }} --from-file=inventory={{ inventory_dir }}/inventory"
87+
88+
- name: Run Install Job
89+
tags:
90+
- install-container
91+
block:
92+
- name:
93+
set_fact:
94+
job: "install"
95+
- name: Template Install Job Json
96+
template:
97+
src: pgo-installer-job.json.j2
98+
dest: "{{ output_dir }}/pgo-installer-job.json"
99+
mode: '0600'
100+
- name: Create Install Job
101+
shell: "{{ kubectl_or_oc }} create -n {{ pgo_installer_namespace }} -f {{ output_dir }}/pgo-installer-job.json"
102+
register: job_started
103+
- name: Wait for Install Job
104+
when: job_started != 0
105+
shell: "{{ kubectl_or_oc }} wait -n {{ pgo_installer_namespace }} --timeout={{ job_wait_timeout }} --for=condition=Complete jobs.batch/pgo-installer"
106+
rescue:
107+
- debug:
108+
msg: Install failed
109+
110+
- name: Run Uninstall Job
111+
tags:
112+
- uninstall-container
113+
block:
114+
- name:
115+
set_fact:
116+
job: "uninstall"
117+
- name: Template Uninstall Job Json
118+
template:
119+
src: pgo-uninstaller-job.json.j2
120+
dest: "{{ output_dir }}/pgo-uninstaller-job.json"
121+
mode: '0600'
122+
- name: Create Uninstall Job
123+
shell: "{{ kubectl_or_oc }} create -n {{ pgo_installer_namespace }} -f {{ output_dir }}/pgo-uninstaller-job.json"
124+
register: job_started
125+
- name: Wait for Uninstall Job
126+
when: job_started != 0
127+
shell: "{{ kubectl_or_oc }} wait -n {{ pgo_installer_namespace }} --timeout={{ job_wait_timeout }} --for=condition=Complete jobs.batch/pgo-uninstaller"
128+
rescue:
129+
- debug:
130+
msg: Uninstall failed
131+
132+
- name: Run Update Job
133+
tags:
134+
- update-container
135+
block:
136+
- name:
137+
set_fact:
138+
job: "update"
139+
- name: Template Update Job Json
140+
template:
141+
src: pgo-update-job.json.j2
142+
dest: "{{ output_dir }}/pgo-update-job.json"
143+
mode: '0600'
144+
- name: Create Update Job
145+
shell: "{{ kubectl_or_oc }} create -n {{ pgo_installer_namespace }} -f {{ output_dir }}/pgo-update-job.json"
146+
register: job_started
147+
- name: Wait for Update Job
148+
when: job_started != 0
149+
shell: "{{ kubectl_or_oc }} wait -n {{ pgo_installer_namespace }} --timeout={{ job_wait_timeout }} --for=condition=Complete jobs.batch/pgo-updater"
150+
rescue:
151+
- debug:
152+
msg: Update failed
153+
154+
155+
- name: Cleanup Jobs
156+
tags:
157+
- clean
158+
block:
159+
- name: Clean Update Job
160+
shell: "{{ kubectl_or_oc }} delete -n {{ pgo_installer_namespace }} jobs.batch/pgo-updater"
161+
when: job == 'update' or job == 'all'
162+
ignore_errors: yes
163+
- name: Clean Installer Job
164+
shell: "{{ kubectl_or_oc }} delete -n {{ pgo_installer_namespace }} jobs.batch/pgo-installer"
165+
when: job == 'install' or job == 'all'
166+
ignore_errors: yes
167+
- name: Clean Uninstaller Job
168+
shell: "{{ kubectl_or_oc }} delete -n {{ pgo_installer_namespace }} jobs.batch/pgo-uninstaller"
169+
when: job == 'uninstall' or job == 'all'
170+
ignore_errors: yes
171+
172+
- name: Clean All
173+
tags:
174+
- clean-all
175+
block:
176+
- name: Clean namespace
177+
shell: "{{ kubectl_or_oc }} delete namespace {{ pgo_installer_namespace }}"
178+
ignore_errors: yes
179+
- name: Clean clusterrolebinding
180+
shell: "{{ kubectl_or_oc }} delete clusterrolebinding {{ pgo_installer_crb }}"
181+
ignore_errors: yes

0 commit comments

Comments
 (0)