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

Create helm hook job for dev database creation #206

Merged
merged 3 commits into from
Oct 29, 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
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 0.1.78 (2024-10-28)
---------------------------
charts/snowplow-iglu-server: Adds helm hook job to create dev database (closes #205)

Version 0.1.77 (2024-10-25)
---------------------------
charts/service-deployment: update hpa to supply metrics object instead of fixed CPU utilization threshold (closes #202)
Expand Down
2 changes: 1 addition & 1 deletion charts/snowplow-iglu-server/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
name: snowplow-iglu-server
description: A Helm Chart to deploy the Snowplow Iglu Server project
version: 0.9.0
version: 0.10.0
appVersion: "0.12.0"
icon: https://raw.githubusercontent.com/snowplow-devops/helm-charts/master/docs/logo/snowplow.png
home: https://github.com/snowplow-devops/helm-charts
Expand Down
4 changes: 4 additions & 0 deletions charts/snowplow-iglu-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ When `dev_db` is `true` the hook job `-dev-db-user-setup` will be initiated

### AWS (EKS) settings

When `dev_db` is `true` the hook job `-create-dev-db` will be initiated

#### TargetGroup binding

To manage the load balancer externally to the kubernetes cluster you can bind the deployment to an existing TargetGroup ARN. Its important that the TargetGroup exist ahead of time and that you use the same port as you have used in your `values.yaml`.
Expand Down Expand Up @@ -151,6 +153,8 @@ You will need to fill these targeted fields:
| global.labels | object | `{}` | Global labels deployed to all resources deployed by the chart |
| service.annotations | object | `{}` | Map of annotations to add to the service |
| service.aws.targetGroupARN | string | `""` | EC2 TargetGroup ARN to bind the service onto |
| service.aws.dev_db | bool | `false` | Whether we deploy for dev db in AWS |
| service.aws.secrets.admin_username | string | `""` | The admin username that will be used for the psql command |
| service.config.database.dbname | string | `""` | Postgres database name |
| service.config.database.host | string | `""` | Postgres database host |
| service.config.database.port | int | `5432` | Postgres database port |
Expand Down
53 changes: 52 additions & 1 deletion charts/snowplow-iglu-server/templates/iglu-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,58 @@ spec:
- name: "CONFIG_FORCE_iglu_database_dbname"
value: "{{ .Values.service.config.database.dbname }}"
- name: "CONFIG_FORCE_iglu_database_port"
value: "{{ .Values.service.gcp.proxy.port }}"
value: "{{ .Values.service.config.database.port }}"
envFrom:
- secretRef:
name: {{ include "iglu.app.secret.name" . }}
{{- end }}

{{- if .Values.service.aws.dev_db }}

---

apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "iglu.hooks.name" . }}-create-dev-db
labels:
{{- include "snowplow.labels" $ | nindent 4 }}
annotations:
"helm.sh/hook": post-install,post-upgrade
"helm.sh/hook-delete-policy": hook-succeeded,hook-failed
"helm.sh/hook-weight": "1"
spec:
template:
metadata:
name: {{ include "iglu.hooks.name" . }}-create-dev-db
spec:
restartPolicy: Never
containers:
- name: {{ include "iglu.hooks.name" . }}-create-dev-db
image: postgres:15-alpine
imagePullPolicy: Always
command: ["/bin/bash", "-c"]
args:
- |
export PGPASSWORD="${CONFIG_FORCE_iglu_database_admin_password}"
psql -h "${CONFIG_FORCE_iglu_database_host}" \
-d "${CONFIG_FORCE_iglu_database_prod_dbname}" \
-U "${CONFIG_FORCE_iglu_database_admin_username}" \
-p "${CONFIG_FORCE_iglu_database_port}" \
-c "CREATE DATABASE ${CONFIG_FORCE_iglu_database_dbname};" && echo "OK"
env:
- name: "CONFIG_FORCE_iglu_database_admin_password"
value: "{{ .Values.service.aws.secrets.admin_password }}"
- name: "CONFIG_FORCE_iglu_database_admin_username"
value: "{{ .Values.service.aws.secrets.admin_username }}"
- name: "CONFIG_FORCE_iglu_database_prod_dbname"
value: "{{ .Values.service.aws.prod_dbname }}"
- name: "CONFIG_FORCE_iglu_database_host"
value: "{{ .Values.service.config.database.host }}"
- name: "CONFIG_FORCE_iglu_database_dbname"
value: "{{ .Values.service.config.database.dbname }}"
- name: "CONFIG_FORCE_iglu_database_port"
value: "{{ .Values.service.config.database.port }}"
envFrom:
- secretRef:
name: {{ include "iglu.app.secret.name" . }}
Expand Down
4 changes: 4 additions & 0 deletions charts/snowplow-iglu-server/values-aws.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ service:

aws:
targetGroupARN: "<target-group-arn>"
dev_db: "<dev_db>"
prod_dbname: "<prod_dbname>"
secrets:
admin_username: "<admin_username>"
5 changes: 5 additions & 0 deletions charts/snowplow-iglu-server/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ service:
aws:
# -- EC2 TargetGroup ARN to bind the service onto
targetGroupARN: ""
# -- Whether we deploy for dev db
dev_db: false
prod_dbname: ""
secrets:
admin_username: ""

azure:
# -- Whether we deploy for dev db
Expand Down
Loading