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

Add helm chart #150

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,8 @@ __pycache__/

# all-contributors-cli
node_modules

### Helm
helm/*/myvalues.yaml
# Dependencies
helm/*/charts
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ WORKDIR /anem-per-feina/

RUN apt-get update \
&& apt-get install --no-install-recommends -qy wait-for-it \
build-essential \
&& rm -rf /var/lib/apt/list/*

COPY requirements.txt ./
Expand Down
1 change: 1 addition & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ WORKDIR /anem-per-feina/

RUN apt-get update \
&& apt-get install --no-install-recommends -qy wait-for-it \
build-essential \
&& rm -rf /var/lib/apt/list/*

COPY requirements.txt ./
Expand Down
23 changes: 23 additions & 0 deletions helm/apf/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
9 changes: 9 additions & 0 deletions helm/apf/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dependencies:
- name: redis
repository: https://charts.bitnami.com/bitnami
version: 11.0.6
- name: postgresql
repository: https://charts.bitnami.com/bitnami
version: 9.8.1
digest: sha256:7ffea47877067e199faa37e7cd087d175e79657220cc27ad70b560448a1ea34d
generated: "2020-10-30T13:02:10.028763072+01:00"
22 changes: 22 additions & 0 deletions helm/apf/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: v2
name: apf
description: A Helm chart for Kubernetes
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

# 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
# follow Semantic Versioning. They should reflect the version the application is using.
appVersion: 1.16.0

dependencies:
- name: redis
version: 11.0.6
repository: https://charts.bitnami.com/bitnami
- name: postgresql
version: 9.8.1
repository: https://charts.bitnami.com/bitnami
62 changes: 62 additions & 0 deletions helm/apf/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "apf.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "apf.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "apf.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "apf.labels" -}}
helm.sh/chart: {{ include "apf.chart" . }}
{{ include "apf.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "apf.selectorLabels" -}}
app.kubernetes.io/name: {{ include "apf.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "apf.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "apf.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
12 changes: 12 additions & 0 deletions helm/apf/templates/certificate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: {{ include "apf.fullname" . }}-cert
spec:
secretName: {{ include "apf.fullname" . }}-cert
issuerRef:
kind: ClusterIssuer
name: {{ .Values.certificate.issuername }}
commonName: {{ .Values.certificate.hostname }}
dnsNames:
- {{ .Values.certificate.hostname }}
58 changes: 58 additions & 0 deletions helm/apf/templates/deployments/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "apf.fullname" . }}
labels:
{{- include "apf.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.app.replicaCount }}
selector:
matchLabels:
{{- include "apf.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "apf.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "apf.serviceAccountName" . }}
containers:
- name: {{ .Chart.Name }}-celery
image: "{{ .Values.app.image }}:{{ .Values.app.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.app.pullPolicy }}
command:
- invoke
- migrate
- uwsgi
- --port
- {{ .Values.app.container.port | quote }}
- -w
- {{ .Values.app.workers | quote }}
- -t
- {{ .Values.app.threads | quote }}
envFrom:
- secretRef:
name: {{ include "apf.fullname" . }}
ports:
- name: http
containerPort: {{ .Values.app.container.port }}
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 4
readinessProbe:
httpGet:
path: /
port: http
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 4
resources:
{{- toYaml .Values.app.resources | nindent 12 }}
33 changes: 33 additions & 0 deletions helm/apf/templates/deployments/celery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "apf.fullname" . }}-celery
labels:
{{- include "apf.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.celery.replicaCount }}
selector:
matchLabels:
{{- include "apf.selectorLabels" . | nindent 6 }}-celery
template:
metadata:
labels:
{{- include "apf.selectorLabels" . | nindent 8 }}-celery
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "apf.serviceAccountName" . }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.app.image }}:{{ .Values.app.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.celery.pullPolicy }}
command:
- invoke
- celery-queues
envFrom:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe liveness tests could be implemented via celery -b XXX inspect ping command (or something similar)

- secretRef:
name: {{ include "apf.fullname" . }}
resources:
{{- toYaml .Values.celery.resources | nindent 12 }}
32 changes: 32 additions & 0 deletions helm/apf/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "apf.fullname" . -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "apf.labels" . | nindent 4 }}
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web, websecure
cert-manager.io/cluster-issuer: {{ .Values.certificate.issuername | quote }}
spec:
{{- if .Values.ingress.tls }}
tls:
- secretName: {{ $fullName }}-cert
{{- end }}
rules:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo: review traefik

{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
pathType: Prefix
backend:
service:
name: {{ $fullName }}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

port:
number: {{ .servicePort }}
{{- end }}
{{- end }}
{{- end }}
30 changes: 30 additions & 0 deletions helm/apf/templates/secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ include "apf.fullname" . }}
labels:
app: {{ template "apf.name" . }}
chart: {{ template "apf.chart" . }}
release: {{ .Release.Name | quote }}
heritage: {{ .Release.Service | quote }}
data:
BASE_URL: {{ .Values.baseurl | b64enc | quote }}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why all those vars are stored as a Secret? Is there any added value that justifies it?

DEBUG: {{ .Values.app.debug | b64enc | quote }}
LOG_LEVEL: {{ .Values.app.log_level | b64enc | quote }}
SECRET_KEY: {{ required "secret key is needed" .Values.app.secretKey | b64enc | quote }}
# Postgres
POSTGRES_DB: {{ .Values.postgresql.postgresqlDatabase | b64enc | quote }}
POSTGRES_USER: {{ .Values.postgresql.postgresqlUsername | b64enc | quote }}
POSTGRES_HOST: {{ printf "%s-postgresql" (include "apf.name" .) | b64enc | quote }}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be apf.fullname

POSTGRES_PORT: {{ .Values.postgresql.service.port | b64enc | quote }}
POSTGRES_PASSWORD: {{ required "postgres password is needed" .Values.postgresql.postgresqlPassword | b64enc | quote }}
# Celery
CELERY_BROKER_PROTOCOL: {{ .Values.celery.broker.protocol | b64enc | quote }}
CELERY_BROKER_HOST: {{ printf "%s-redis-master" (include "apf.name" .) | b64enc | quote }}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be apf.fullname

CELERY_BROKER_PORT: {{ .Values.redis.redisPort | b64enc | quote }}
CELERY_BROKER_DB: {{ .Values.redis.db | b64enc | quote }}
CELERY_REDIRECT_STDOUTS_LEVEL: {{ .Values.celery.stdouts_level | b64enc | quote }}
# Telegram
TELEGRAM_TOKEN: {{ .Values.notifications.telegram.token | b64enc | quote }}
NOTIF_TELEGRAM_ENABLED: {{ .Values.notifications.telegram.enabled | b64enc | quote }}
TELEGRAM_CHAT_IDS: {{ .Values.notifications.telegram.chatIds | b64enc | quote }}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are more env vars needed to deploy the NPF (twitter, sentry, ...)

12 changes: 12 additions & 0 deletions helm/apf/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "apf.serviceAccountName" . }}
labels:
{{- include "apf.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
14 changes: 14 additions & 0 deletions helm/apf/templates/services/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "apf.fullname" . }}
labels:
{{- include "apf.labels" . | nindent 4 }}
spec:
ports:
- port: {{ .Values.app.service.port }}
targetPort: {{ .Values.app.service.port }}
protocol: TCP
name: http
selector:
{{- include "apf.selectorLabels" . | nindent 4 }}
14 changes: 14 additions & 0 deletions helm/apf/templates/services/celery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "apf.fullname" . }}-celery
labels:
{{- include "apf.labels" . | nindent 4 }}-celery
spec:
ports:
- port: {{ .Values.celery.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "apf.selectorLabels" . | nindent 4 }}-celery
Loading