Skip to content

Commit e39acc8

Browse files
author
a.b.christie
committed
feat: No PSP and style changes
1 parent fbc78a6 commit e39acc8

7 files changed

Lines changed: 45 additions & 74 deletions

File tree

roles/postgresql/defaults/main.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pg_vol_size_g: 50
1717
# The StorageClass of the postgres persistent volume.
1818
# A blank class implied the cluster default.
1919
# Unused if 'pg_vol_size_g' is '0'
20-
pg_vol_storageclass: " "
20+
pg_vol_storageclass: ' '
2121

2222
# The volume size (Gi) of a separate 'pgcopy' volume.
2323
# The volume is mounted into the database container
@@ -29,11 +29,11 @@ pg_vol_storageclass: " "
2929
pg_copy_vol_size_g: 0
3030
# The StorageClass of the persistent volume.
3131
# A blank class implied the cluster default.
32-
pg_copy_vol_storageclass: " "
32+
pg_copy_vol_storageclass: ' '
3333

3434
# Root-user variables
3535
pg_user: postgres
36-
pg_user_password: "{{ lookup('password', '/dev/null length=8 chars=ascii_letters,digits') }}"
36+
pg_user_password: "{{ lookup('password', '/dev/null length=14 chars=ascii_letters,digits') }}"
3737
pg_database: postgres
3838

3939
# An auxiliary user.

roles/postgresql/tasks/deploy.yaml

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
- name: Assert control variables (aux user)
66
assert:
77
that:
8-
- pg_aux_user_password|string|length > 0
9-
- pg_aux_database|string|length > 0
10-
when: pg_aux_user|string|length > 0
8+
- pg_aux_user_password | string | length > 0
9+
- pg_aux_database | string | length > 0
10+
when: pg_aux_user | string | length > 0
1111

1212
# Create namespace
1313

@@ -23,16 +23,14 @@
2323
vars:
2424
pull_namespace: "{{ pg_namespace }}"
2525
pull_secret: "{{ pg_dockerhub_pullsecret }}"
26-
when: pg_dockerhub_pullsecret|string|length > 0
26+
when: pg_dockerhub_pullsecret | string | length > 0
2727

2828
- name: Creating namespace material
2929
k8s:
30-
definition: "{{ lookup('template', '{{ item }}.yaml.j2') }}"
30+
definition: "{{ lookup('template', item) }}"
3131
wait: yes
3232
loop:
33-
- serviceaccount
34-
- role-im-psp-unrestricted
35-
- rolebinding-pg-sa
33+
- serviceaccount.yaml.j2
3634

3735
# Secrets (database) ----------------------------------------------------------
3836

@@ -52,23 +50,23 @@
5250
pg_aux_user_fact: "{{ pg_aux_user }}"
5351
pg_aux_user_password_fact: "{{ pg_aux_user_password }}"
5452
pg_aux_database_fact: "{{ pg_aux_database }}"
55-
when: pg_s_result.resources|length == 0
53+
when: pg_s_result.resources | length == 0
5654

5755
- name: Set database secret facts (pre-deployed secrets)
5856
set_fact:
59-
pg_user_fact: "{{ pg_s_result.resources[0].data.database_admin_user|b64decode }}"
60-
pg_user_password_fact: "{{ pg_s_result.resources[0].data.database_admin_user_password|b64decode }}"
61-
pg_database_fact: "{{ pg_s_result.resources[0].data.database_name|b64decode }}"
62-
pg_aux_user_fact: "{{ pg_s_result.resources[0].data.database_aux_user|b64decode }}"
63-
pg_aux_user_password_fact: "{{ pg_s_result.resources[0].data.database_aux_user_password|b64decode }}"
64-
pg_aux_database_fact: "{{ pg_s_result.resources[0].data.database_aux_database|b64decode }}"
65-
when: pg_s_result.resources|length == 1
57+
pg_user_fact: "{{ pg_s_result.resources[0].data.database_admin_user | b64decode }}"
58+
pg_user_password_fact: "{{ pg_s_result.resources[0].data.database_admin_user_password | b64decode }}"
59+
pg_database_fact: "{{ pg_s_result.resources[0].data.database_name | b64decode }}"
60+
pg_aux_user_fact: "{{ pg_s_result.resources[0].data.database_aux_user | b64decode }}"
61+
pg_aux_user_password_fact: "{{ pg_s_result.resources[0].data.database_aux_user_password | b64decode }}"
62+
pg_aux_database_fact: "{{ pg_s_result.resources[0].data.database_aux_database | b64decode }}"
63+
when: pg_s_result.resources | length == 1
6664

6765
- name: Write Database secrets
6866
k8s:
6967
definition: "{{ lookup('template', 'secret.yaml.j2') }}"
7068
wait: yes
71-
when: pg_s_result.resources|length == 0
69+
when: pg_s_result.resources | length == 0
7270

7371
- name: Display Database admin password
7472
debug:
@@ -85,7 +83,7 @@
8583

8684
- name: Assert {{ pg_vol_storageclass }} StorageClass
8785
assert:
88-
that: sc_result.resources|length == 1
86+
that: sc_result.resources | length == 1
8987
fail_msg: The {{ pg_vol_storageclass }} StorageClass must be available on the cluster
9088
when: pg_vol_storageclass != " "
9189

@@ -94,7 +92,7 @@
9492
definition: "{{ lookup('template', 'pvc-pg.yaml.j2') }}"
9593
wait: yes
9694
wait_timeout: "{{ wait_timeout }}"
97-
when: pg_vol_size_g|int > 0
95+
when: pg_vol_size_g | int > 0
9896

9997
# Best practice ... wait for the PVC to bind.
10098
# e.g. wait until resources[0].status.phase == Bound (initially Pending)
@@ -106,15 +104,15 @@
106104
namespace: "{{ pg_namespace }}"
107105
register: pg_pvc_result
108106
until: >-
109-
pg_pvc_result.resources|length > 0
107+
pg_pvc_result.resources | length > 0
110108
and pg_pvc_result.resources[0].status is defined
111109
and pg_pvc_result.resources[0].status.phase is defined
112110
and pg_pvc_result.resources[0].status.phase == 'Bound'
113111
delay: 5
114-
retries: "{{ (bind_timeout|int / 5)|int }}"
112+
retries: "{{ (bind_timeout | int / 5) | int }}"
115113
when:
116-
- pg_vol_size_g|int > 0
117-
- wait_for_bind|bool
114+
- pg_vol_size_g | int > 0
115+
- wait_for_bind | bool
118116

119117
# Database volume (pg-copy) ---------------------------------------------------
120118

@@ -130,7 +128,7 @@
130128

131129
- name: Assert {{ pg_copy_vol_storageclass }} StorageClass
132130
assert:
133-
that: sc_result.resources|length == 1
131+
that: sc_result.resources | length == 1
134132
fail_msg: The {{ pg_copy_vol_storageclass }} StorageClass must be available on the cluster
135133
when: pg_copy_vol_storageclass != " "
136134

@@ -150,28 +148,28 @@
150148
namespace: "{{ pg_namespace }}"
151149
register: pg_copy_pvc_result
152150
until: >-
153-
pg_copy_pvc_result.resources|length > 0
151+
pg_copy_pvc_result.resources | length > 0
154152
and pg_copy_pvc_result.resources[0].status is defined
155153
and pg_copy_pvc_result.resources[0].status.phase is defined
156154
and pg_copy_pvc_result.resources[0].status.phase == 'Bound'
157155
delay: 5
158-
retries: "{{ (bind_timeout|int / 5)|int }}"
159-
when: wait_for_bind|bool
156+
retries: "{{ (bind_timeout | int / 5) | int }}"
157+
when: wait_for_bind | bool
160158

161-
when: pg_copy_vol_size_g|int > 0
159+
when: pg_copy_vol_size_g | int > 0
162160

163161
# Database (postgres) ---------------------------------------------------------
164162

165163
- name: Postgres
166164
k8s:
167-
definition: "{{ lookup('template', '{{ item }}.yaml.j2') }}"
165+
definition: "{{ lookup('template', item) }}"
168166
wait: yes
169167
wait_timeout: "{{ wait_timeout }}"
170168
loop:
171-
- configmap-postgres-conf
172-
- configmap-postgres-init
173-
- service
174-
- statefulset
169+
- configmap-postgres-conf.yaml.j2
170+
- configmap-postgres-init.yaml.j2
171+
- service.yaml.j2
172+
- statefulset.yaml.j2
175173

176174
- name: Wait for Postgres
177175
k8s_info:
@@ -181,10 +179,10 @@
181179
- app=postgres
182180
register: result
183181
until: >-
184-
result.resources|length > 0
182+
result.resources | length > 0
185183
and result.resources[0].status.containerStatuses is defined
186-
and result.resources[0].status.containerStatuses|length == 1
184+
and result.resources[0].status.containerStatuses | length == 1
187185
and result.resources[0].status.containerStatuses[0].ready is defined
188186
and result.resources[0].status.containerStatuses[0].ready
189187
delay: 20
190-
retries: "{{ (wait_timeout|int / 20)|int }}"
188+
retries: "{{ (wait_timeout | int / 20) | int }}"

roles/postgresql/tasks/main.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
- name: Assert authentication
1212
assert:
1313
that:
14-
- k8s_auth_host|length > 0
15-
- k8s_auth_api_key|length > 0
14+
- k8s_auth_host | length > 0
15+
- k8s_auth_api_key | length > 0
1616

1717
# Go...
1818

1919
- block:
2020

2121
- include_tasks: deploy.yaml
22-
when: pg_state|string == 'present'
22+
when: pg_state | string == 'present'
2323
- include_tasks: undeploy.yaml
24-
when: pg_state|string == 'absent'
24+
when: pg_state | string == 'absent'
2525

2626
module_defaults:
2727
group/k8s:

roles/postgresql/templates/configmap-postgres-conf.yaml.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ metadata:
55
name: postgres-conf
66
namespace: {{ pg_namespace }}
77
data:
8-
postgresql.conf: "{{ pg_configuration|replace('\n', '\\n') }}"
8+
postgresql.conf: "{{ pg_configuration | replace('\n', '\\n') }}"

roles/postgresql/templates/role-im-psp-unrestricted.yaml.j2

Lines changed: 0 additions & 11 deletions
This file was deleted.

roles/postgresql/templates/rolebinding-pg-sa.yaml.j2

Lines changed: 0 additions & 14 deletions
This file was deleted.

roles/postgresql/templates/statefulset.yaml.j2

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ spec:
2525
requiredDuringSchedulingIgnoredDuringExecution:
2626
nodeSelectorTerms:
2727
- matchExpressions:
28-
- key: informaticsmatters.com/purpose
29-
operator: In
30-
values:
31-
- core
28+
- key: informaticsmatters.com/purpose-core
29+
operator: Exists
3230
{% endif %}
3331

34-
{% if all_image_preset_pullsecret_name|string|length > 0 %}
32+
{% if all_image_preset_pullsecret_name | string | length > 0 %}
3533
imagePullSecrets:
3634
- name: {{ all_image_preset_pullsecret_name }}
3735
{% endif %}

0 commit comments

Comments
 (0)