diff --git a/charts/quality-trace/Chart.yaml b/charts/quality-trace/Chart.yaml index c9e79223a..d6735e6d8 100644 --- a/charts/quality-trace/Chart.yaml +++ b/charts/quality-trace/Chart.yaml @@ -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 diff --git a/charts/quality-trace/templates/configmap-db.yaml b/charts/quality-trace/templates/configmap-db.yaml new file mode 100644 index 000000000..f063c4c80 --- /dev/null +++ b/charts/quality-trace/templates/configmap-db.yaml @@ -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 }} \ No newline at end of file diff --git a/charts/quality-trace/templates/configmap.yaml b/charts/quality-trace/templates/configmap.yaml index 1dfd97431..451e39eb1 100644 --- a/charts/quality-trace/templates/configmap.yaml +++ b/charts/quality-trace/templates/configmap.yaml @@ -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: diff --git a/charts/quality-trace/templates/job.yaml b/charts/quality-trace/templates/job.yaml new file mode 100644 index 000000000..8c3e7627c --- /dev/null +++ b/charts/quality-trace/templates/job.yaml @@ -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 }} + + diff --git a/charts/quality-trace/values.yaml b/charts/quality-trace/values.yaml index ca3092413..f983edc2f 100644 --- a/charts/quality-trace/values.yaml +++ b/charts/quality-trace/values.yaml @@ -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: @@ -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: \ No newline at end of file