Skip to content

Commit

Permalink
Merge pull request #55 from akash4sh/main
Browse files Browse the repository at this point in the history
Add job.yaml for external postgresql
  • Loading branch information
jebjohns committed Mar 14, 2024
2 parents 8da3b5b + 46886f2 commit 2b327c1
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 2 deletions.
3 changes: 2 additions & 1 deletion charts/quality-trace/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ dependencies:
- name: postgresql
repository: https://charts.bitnami.com/bitnami
version: 12.1.6
condition: postgresql.enabled
description: A Helm chart for Trace Test
home: https://github.com/kubeshop/helm-charts
name: quality-trace
sources:
- https://github.com/kubeshop/helm-charts/tree/main/charts
type: application
version: 1.0.2
version: 1.0.3
22 changes: 22 additions & 0 deletions charts/quality-trace/templates/configmap-db.yaml
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 }}
6 changes: 6 additions & 0 deletions charts/quality-trace/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ data:
googleAnalytics:
enabled: {{.Values.analytics.enabled}}
postgres:
{{- if .Values.postgresql.enabled }}
host: {{ include "tracetest.postgresql.fullname" . }}
user: {{.Values.postgresql.auth.username}}
password: {{.Values.postgresql.auth.password}}
{{- else }}
host: {{ .Values.externalPostgresql.host }}
user: {{ .Values.externalPostgresql.username }}
password: {{ .Values.externalPostgresql.password }}
{{- end }}
port: 5432
params: sslmode=disable
telemetry:
Expand Down
45 changes: 45 additions & 0 deletions charts/quality-trace/templates/job.yaml
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 }}


13 changes: 12 additions & 1 deletion charts/quality-trace/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ telemetry:
type: collector
collector:
# endpoint to send traces to the collector
endpoint: otel-collector:4317
endpoint: quality-trace-otel-collector:4317

# Configures the server
server:
Expand Down Expand Up @@ -351,3 +351,14 @@ otelCollector:
receivers: [otlp]
processors: [probabilistic_sampler, batch]
exporters: [otlp/signoz, otlp/quality-trace, logging]


externalPostgresql:
host: postgresql
database: ""
username: ""
password: ""
postgresqlPassword: ""
existingSecret: {}
# name:
# passwordKey:

0 comments on commit 2b327c1

Please sign in to comment.