-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
74 changed files
with
414 additions
and
302 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 |
---|---|---|
@@ -1 +1,3 @@ | ||
postgres.txt | ||
**/charts/ | ||
values.yaml |
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
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 |
---|---|---|
@@ -1,31 +1,72 @@ | ||
{{/* | ||
Postgres Password lookup | ||
*/}} | ||
{{- define "postgres.master.password" -}} | ||
{{- $localpass := (lookup "v1" "Secret" "postgres" "postgres-postgresql" ) -}} | ||
{{- if $localpass }} | ||
{{- default (index $localpass.data "postgres-password" | b64dec) }} | ||
{{- else }} | ||
{{- default $.Values.global.postgres.master.password }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
|
||
|
||
{{- define "db-setup.setup-job" -}} | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: db-setup | ||
name: {{ .Chart.Name }}-dbcreate | ||
annotations: | ||
"helm.sh/hook": "pre-install,pre-upgrade" | ||
"helm.sh/hook-delete-policy": hook-succeeded | ||
spec: | ||
template: | ||
metadata: | ||
labels: | ||
app: gen3job | ||
annotations: | ||
"helm.sh/hook": pre-install | ||
"helm.sh/hook-weight": "-5" | ||
"helm.sh/hook-delete-policy": hook-succeeded | ||
spec: | ||
restartPolicy: OnFailure | ||
containers: | ||
- name: db-setup | ||
image: quay.io/cdis/awshelper:master | ||
imagePullPolicy: Always | ||
command: ["/bin/bash", "-c"] | ||
env: | ||
- name: PGPASSWORD | ||
value: "{{ include "postgres.master.password" . }}" | ||
- name: PGUSER | ||
value: "{{ $.Values.global.postgres.master.username }}" | ||
- name: PGPORT | ||
value: "{{ $.Values.global.postgres.master.port }}" | ||
- name: PGHOST | ||
value: "{{ $.Values.global.postgres.host }}" | ||
args: | ||
- | | ||
export PGPASSWORD="{{ $.Values.postgres.master.password }}" | ||
{{- range .Values.postgres.databases }} | ||
psql -h {{ $.Values.postgres.host }} -U {{ $.Values.postgres.master.username }} -p {{ $.Values.postgres.master.port }} -tc "SELECT 1 FROM pg_database WHERE datname = '{{ .databaseName }}'" | grep -q 1 || psql -h {{ $.Values.postgres.host }} -U {{ $.Values.postgres.master.username }} -p {{ $.Values.postgres.master.port }} -c "CREATE DATABASE {{ .databaseName }};" | ||
psql -h {{ $.Values.postgres.host }} -U {{ $.Values.postgres.master.username }} -p {{ $.Values.postgres.master.port }} -tc "SELECT 1 FROM pg_user WHERE usename = '{{ .username }}'" | grep -q 1 || psql -h {{ $.Values.postgres.host }} -U {{ $.Values.postgres.master.username }} -p {{ $.Values.postgres.master.port }} -c "CREATE USER {{ .username }} WITH PASSWORD '{{ .password }}';" | ||
psql -h {{ $.Values.postgres.host }} -U {{ $.Values.postgres.master.username }} -p {{ $.Values.postgres.master.port }} -c "GRANT ALL ON DATABASE {{ .databaseName }} TO {{ .username }} WITH GRANT OPTION;" | ||
psql -h {{ $.Values.postgres.host }} -U {{ $.Values.postgres.master.username }} -p {{ $.Values.postgres.master.port }} -d {{ .databaseName }} -c "CREATE EXTENSION ltree; ALTER ROLE {{ .username }} WITH LOGIN" | ||
if psql -lqt | cut -d \| -f 1 | grep -qw {{ .databaseName }}; then | ||
echo "Database named {{ .databaseName }} already exists." | ||
else | ||
psql -tc "SELECT 1 FROM pg_database WHERE datname = '{{ .databaseName }}'" | grep -q 1 || psql -c "CREATE DATABASE {{ .databaseName }};" | ||
psql -tc "SELECT 1 FROM pg_user WHERE usename = '{{ .username }}'" | grep -q 1 || psql -c "CREATE USER {{ .username }} WITH PASSWORD '{{ .password }}';" | ||
psql -c "GRANT ALL ON DATABASE {{ .databaseName }} TO {{ .username }} WITH GRANT OPTION;" | ||
psql -d {{ .databaseName }} -c "CREATE EXTENSION ltree; ALTER ROLE {{ .username }} WITH LOGIN" | ||
fi | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{ define "db-setup.secret" }} | ||
{{- range .Values.postgres.databases }} | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: {{ .service }}-dbcreds | ||
annotations: | ||
"helm.sh/hook": "pre-install,pre-upgrade" | ||
"helm.sh/resource-policy": "keep" | ||
stringData: | ||
database: "{{ .databaseName }}" | ||
username: "{{ .username }}" | ||
password: "{{ .password }}" | ||
{{- end -}} | ||
{{- end -}} |
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 |
---|---|---|
@@ -1,15 +1,20 @@ | ||
global: | ||
postgres: | ||
host: postgres-postgresql.postgres.svc.cluster.local | ||
master: | ||
username: postgres | ||
port: 5432 | ||
# If password is left empty the lookup function will look for postgres master password | ||
password: | ||
|
||
postgres: | ||
host: postgres-postgresql.postgres.svc.cluster.local | ||
|
||
master: | ||
username: postgres | ||
password: postgres | ||
port: 5432 | ||
|
||
# An array of databases to create. | ||
databases: | ||
- databaseName: wts | ||
- service: wts | ||
databaseName: wts | ||
username: wts | ||
password: wts_password | ||
- databaseName: indexd | ||
- service: indexd | ||
databaseName: indexd | ||
username: indexd | ||
password: indexd_password |
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.