Skip to content

Commit

Permalink
Merge pull request #5 from andyverberne/issue/#3
Browse files Browse the repository at this point in the history
Fixes #3. Adds an Open Notifications worker pod.
  • Loading branch information
sergei-maertens authored Apr 15, 2021
2 parents 45a5f35 + a5d69d2 commit 650967f
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 31 deletions.
12 changes: 0 additions & 12 deletions charts/open-notificaties/Chart.lock

This file was deleted.

2 changes: 1 addition & 1 deletion charts/open-notificaties/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: open-notificaties
description: API voor het routeren van notificaties

type: application
version: 0.2.1
version: 0.3.0
appVersion: 1.1.0

dependencies:
Expand Down
43 changes: 41 additions & 2 deletions charts/open-notificaties/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,22 @@ Create chart name and version as used by the chart label.
{{/*
Common labels
*/}}
{{- define "open-notificaties.labels" -}}
{{- define "open-notificaties.commonLabels" -}}
helm.sh/chart: {{ include "open-notificaties.chart" . }}
{{ include "open-notificaties.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Labels
*/}}
{{- define "open-notificaties.labels" -}}
{{ include "open-notificaties.commonLabels" . }}
{{ include "open-notificaties.selectorLabels" . }}
{{- end }}

{{/*
Selector labels
*/}}
Expand All @@ -60,3 +67,35 @@ Create the name of the service account to use
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
Create a name for the worker
We truncate at 56 chars in order to provide space for the "-worker" suffix
*/}}
{{- define "open-notificaties.workerName" -}}
{{ include "open-notificaties.name" . | trunc 56 | trimSuffix "-" }}-worker
{{- end }}

{{/*
Create a default fully qualified name for the worker.
We truncate at 56 chars in order to provide space for the "-worker" suffix
*/}}
{{- define "open-notificaties.workerFullname" -}}
{{ include "open-notificaties.fullname" . | trunc 56 | trimSuffix "-" }}-worker
{{- end }}

{{/*
Worker labels
*/}}
{{- define "open-notificaties.workerLabels" -}}
{{ include "open-notificaties.commonLabels" . }}
{{ include "open-notificaties.workerSelectorLabels" . }}
{{- end }}

{{/*
Worker selector labels
*/}}
{{- define "open-notificaties.workerSelectorLabels" -}}
app.kubernetes.io/name: {{ include "open-notificaties.workerName" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
3 changes: 2 additions & 1 deletion charts/open-notificaties/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ data:
{{- if .Values.settings.email.useTLS }}
EMAIL_USE_TLS: "True"
{{- end }}
IS_HTTPS: {{ if .Values.settings.isHttps }}"True"{{ else }}"False"{{ end }}
IS_HTTPS: {{ if .Values.settings.isHttps }}"True"{{ else }}"False"{{ end }}
RABBITMQ_HOST: {{ .Values.settings.messageBroker.host }}
60 changes: 60 additions & 0 deletions charts/open-notificaties/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,63 @@ spec:
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "open-notificaties.workerFullname" . }}
labels:
{{- include "open-notificaties.workerLabels" . | nindent 4 }}
spec:
{{- if not .Values.worker.autoscaling.enabled }}
replicas: {{ .Values.worker.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "open-notificaties.workerSelectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
checksum/configmap: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "open-notificaties.workerSelectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "open-notificaties.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}-worker
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
envFrom:
- secretRef:
name: {{ include "open-notificaties.fullname" . }}
- configMapRef:
name: {{ include "open-notificaties.fullname" . }}
resources:
{{- toYaml .Values.workerResources | nindent 12 }}
command:
- /celery_worker.sh
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}

29 changes: 29 additions & 0 deletions charts/open-notificaties/templates/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,32 @@ spec:
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
---
{{- if .Values.worker.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "open-notificaties.workerFullname" . }}
labels:
{{- include "open-notificaties.workerLabels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "open-notificaties.workerFullname" . }}
minReplicas: {{ .Values.worker.autoscaling.minReplicas }}
maxReplicas: {{ .Values.worker.autoscaling.maxReplicas }}
metrics:
{{- if .Values.worker.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.worker.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.worker.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.worker.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
7 changes: 4 additions & 3 deletions charts/open-notificaties/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ metadata:
{{- include "open-notificaties.labels" . | nindent 4 }}
type: Opaque
data:
CELERY_BROKER_URL: {{ .Values.settings.celeryBrokerUrl | toString | b64enc | quote }}
CELERY_RESULT_BACKEND: {{ .Values.settings.celeryResultBackend | toString | b64enc | quote }}
{{ $rabbitmq_url := printf "amqp://%s:%s@%s:5672" .Values.rabbitmq.auth.username .Values.rabbitmq.auth.password .Values.settings.messageBroker.host -}}
CELERY_BROKER_URL: {{ print $rabbitmq_url "//" | b64enc | quote }}
CELERY_RESULT_BACKEND: {{ print $rabbitmq_url "//" | b64enc | quote }}
DB_PASSWORD: {{ .Values.settings.database.password | toString | b64enc | quote }}
{{- if .Values.settings.email.password }}
EMAIL_PASSWORD: {{ .Values.settings.email.password | toString | b64enc | quote }}
{{- end }}
PUBLISHER_BROKER_URL: {{ .Values.settings.publisherBrokerUrl | toString | b64enc | quote }}
PUBLISHER_BROKER_URL: {{ print $rabbitmq_url "/%2F" | b64enc | quote }}
SECRET_KEY: {{ .Values.settings.secretKey | toString | b64enc | quote }}
{{- if .Values.settings.sentry.dsn }}
SENTRY_DSN: {{ .Values.settings.sentry.dsn | toString | b64enc | quote }}
Expand Down
15 changes: 12 additions & 3 deletions charts/open-notificaties/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ persistence:
size: 1Gi
existingClaim: null

worker:
replicaCount: 1
resources: {}
autoscaling:
enabled: false
minReplicas: 1
maxReplicas: 100
targetCPUUtilizationPercentage: 80
# targetMemoryUtilizationPercentage: 80

settings:
allowedHosts: open-notificaties.gemeente.nl

Expand All @@ -118,9 +128,8 @@ settings:
sentry:
dsn: ""

publisherBrokerUrl: amqp://guest:guest@open-notificaties-rabbitmq:5672/%2F
celeryBrokerUrl: amqp://guest:guest@open-notificaties-rabbitmq:5672//
celeryResultBackend: amqp://guest:guest@open-notificaties-rabbitmq:5672//
messageBroker:
host: open-notificaties-rabbitmq

isHttps: true

Expand Down
9 changes: 0 additions & 9 deletions charts/open-zaak/Chart.lock

This file was deleted.

0 comments on commit 650967f

Please sign in to comment.