-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from akash4sh/main
Add job.yaml for external postgresql
- Loading branch information
Showing
5 changed files
with
87 additions
and
2 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
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,22 @@ | ||
{{- if not .Values.postgresql.enabled }} | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: postgresql-query | ||
annotations: | ||
"helm.sh/hook": pre-install | ||
"helm.sh/hook-weight": "1" | ||
"helm.sh/hook-delete-policy": before-hook-creation | ||
data: | ||
create-database.sql: | | ||
SELECT 'CREATE DATABASE {{ .Values.externalPostgresql.database }}' | ||
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname='{{ .Values.externalPostgresql.database }}')\gexec | ||
SELECT 'CREATE USER {{ .Values.externalPostgresql.username }} WITH PASSWORD ''{{ .Values.externalPostgresql.password }}''' | ||
WHERE NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname='{{ .Values.externalPostgresql.username }}')\gexec | ||
ALTER DATABASE {{ .Values.externalPostgresql.database }} OWNER TO {{ .Values.externalPostgresql.username }}; | ||
ALTER ROLE {{ .Values.externalPostgresql.username }} CREATEDB; | ||
{{- 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
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,45 @@ | ||
{{- if not .Values.postgresql.enabled }} | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: create-users-databases | ||
annotations: | ||
"helm.sh/hook": pre-install | ||
"helm.sh/hook-weight": "2" | ||
"helm.sh/hook-delete-policy": hook-succeeded | ||
spec: | ||
template: | ||
metadata: | ||
name: create-users-databases | ||
spec: | ||
containers: | ||
- name: postgresql-client | ||
image: {{ .Values.postgresql.image.registry }}/{{ .Values.postgresql.image.repository }}:{{ .Values.postgresql.image.tag }} | ||
command: | ||
- "/bin/bash" | ||
- "-c" | ||
- | | ||
psql -h {{ .Values.externalPostgresql.host }} -p 5432 -U postgres -f /scripts/create-database.sql | ||
env: | ||
- name: PGPASSWORD | ||
{{- if not .Values.externalPostgresql.existingSecret }} | ||
value: "{{ .Values.externalPostgresql.postgresqlPassword }}" | ||
{{- else }} | ||
valueFrom: | ||
secretKeyRef: | ||
name: {{ .Values.externalPostgresql.existingSecret.name }} | ||
key: {{ .Values.externalPostgresql.existingSecret.passwordKey }} | ||
{{- end }} | ||
volumeMounts: | ||
- name: script-volume | ||
mountPath: /scripts | ||
readOnly: true | ||
restartPolicy: Never | ||
volumes: | ||
- name: script-volume | ||
configMap: | ||
name: postgresql-query | ||
{{- 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