Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated helm chart to support existing secret for postgresql #76

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion charts/scsctl/.helmignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@
.idea/
*.tmproj
.vscode/
values.sample.yaml
2 changes: 1 addition & 1 deletion charts/scsctl/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0
version: 0.1.1

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
78 changes: 46 additions & 32 deletions charts/scsctl/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,29 @@ spec:
serviceAccountName: {{ include "scsctl.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
initContainers:
- name: create-postgres-datbase
image: "docker.io/bitnami/postgresql:16.0.0-debian-11-r13"
imagePullPolicy: Always
command:
- "/bin/sh"
- "-c"
- >
echo "Creating database {{ .Values.postgresql.database }} if it does not exist..." &&
psql -h {{ .Values.postgresql.host }} -p {{ .Values.postgresql.port }} -U {{ .Values.postgresql.username }} -lqt | cut -d \| -f 1 | grep -qw {{ .Values.postgresql.database }} || psql -h {{ .Values.postgresql.host }} -p {{ .Values.postgresql.port }} -U {{ .Values.postgresql.username }} -c "CREATE DATABASE {{ .Values.postgresql.database }};" &&
echo "Database {{ .Values.postgresql.database }} created or already exists. Listing all databases:" &&
psql -h {{ .Values.postgresql.host }} -p {{ .Values.postgresql.port }} -U {{ .Values.postgresql.username }} -l &&
sleep 5
env:
- name: PGPASSWORD
{{- if not .Values.postgresql.existingSecret }}
value: "{{ .Values.postgresql.password }}"
{{- else }}
valueFrom:
secretKeyRef:
name: {{ .Values.postgresql.existingSecret.name }}
key: {{ .Values.postgresql.existingSecret.passwordKey }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
securityContext:
Expand All @@ -37,48 +60,39 @@ spec:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
args:
- server
env:
- name: SCSCTL_PG_HOST
value: "{{ .Values.env.SCSCTL_PG_HOST }}"
- name: SCSCTL_PG_PORT
value: "{{ .Values.env.SCSCTL_PG_PORT }}"
- name: SCSCTL_PG_USER
value: "{{ .Values.env.SCSCTL_PG_USER }}"
- name: SCSCTL_PG_PASSWORD
value: "{{ .Values.env.SCSCTL_PG_PASSWORD }}"
- name: SCSCTL_PG_DATABASE
value: "{{ .Values.env.SCSCTL_PG_DATABASE }}"
- name: SCSCTL_ENVIRONMENT
value: "{{ .Values.env.SCSCTL_ENVIRONMENT }}"
- name: SCSCTL_PG_HOST
value: "{{ .Values.postgresql.host }}"
- name: SCSCTL_PG_PORT
value: "{{ .Values.postgresql.port }}"
- name: SCSCTL_PG_USER
value: "{{ .Values.postgresql.username }}"
- name: SCSCTL_PG_PASSWORD
{{- if not .Values.postgresql.existingSecret }}
value: "{{ .Values.postgresql.password }}"
{{- else }}
valueFrom:
secretKeyRef:
name: {{ .Values.postgresql.existingSecret.name }}
key: {{ .Values.postgresql.existingSecret.passwordKey }}
{{- end }}
- name: SCSCTL_PG_DATABASE
value: "{{ .Values.postgresql.database }}"
- name: SCSCTL_ENVIRONMENT
value: "{{ .Values.env.SCSCTL_ENVIRONMENT }}"

livenessProbe:
httpGet:
path: /
path: /healthz
port: http
readinessProbe:
httpGet:
path: /
path: /ready
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
initContainers:
- name: create-postgres-datbase
image: "{{ .Values.initContainer.image }}"
imagePullPolicy: {{ .Values.initContainer.imagePullPolicy }}
command: ['sh', '-c', 'until pg_isready -h {{ .Values.env.SCSCTL_PG_HOST }} -p {{ .Values.env.SCSCTL_PG_PORT }}; do echo waiting for database; sleep 2; done; psql -h {{ .Values.env.SCSCTL_PG_HOST }} -p {{ .Values.env.SCSCTL_PG_PORT }} -U {{ .Values.env.SCSCTL_PG_USER }} -d {{ .Values.env.SCSCTL_PG_DATABASE }} -c "CREATE DATABASE {{ .Values.env.SCSCTL_PG_DATABASE }}";']
env:
- name: SCSCTL_PG_HOST
value: "{{ .Values.env.SCSCTL_PG_HOST }}"
- name: SCSCTL_PG_PORT
value: "{{ .Values.env.SCSCTL_PG_PORT }}"
- name: SCSCTL_PG_USER
value: "{{ .Values.env.SCSCTL_PG_USER }}"
- name: SCSCTL_PG_PASSWORD
value: "{{ .Values.env.SCSCTL_PG_PASSWORD }}"
- name: SCSCTL_PG_DATABASE
value: "{{ .Values.env.SCSCTL_PG_DATABASE }}"
resources:
{{- toYaml .Values.initContainer.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
91 changes: 0 additions & 91 deletions charts/scsctl/values.sample.yaml

This file was deleted.

Loading