Commit c90c5da6 authored by Evili del Rio's avatar Evili del Rio

Add proper PVC for Django

parent 1cd908c7
Pipeline #1765 passed with stage
in 14 seconds
...@@ -2,3 +2,4 @@ ...@@ -2,3 +2,4 @@
*.lock *.lock
charts charts
*.*gz *.*gz
\#*\#
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
*.tmp *.tmp
*.orig *.orig
*~ *~
\#*\#
# Various IDEs # Various IDEs
.project .project
.idea/ .idea/
......
...@@ -61,3 +61,56 @@ Create the name of the service account to use ...@@ -61,3 +61,56 @@ Create the name of the service account to use
{{ default "default" .Values.serviceAccount.name }} {{ default "default" .Values.serviceAccount.name }}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
{{/*
Return Django Secret Key
*/}}
{{- define "django.secret_key" -}}
{{- if .Values.global.django.secretKey }}
{{- .Values.global.django.secretKey -}}
{{- else -}}
{{- randAlphaNum 72 -}}
{{- end -}}
{{- end -}}
{{/*
Return the proper Storage Class
*/}}
{{- define "django.storageClass" -}}
{{/*
Helm 2.11 supports the assignment of a value to a variable defined in a different scope,
but Helm 2.9 and 2.10 does not support it, so we need to implement this if-else logic.
*/}}
{{- if .Values.global -}}
{{- if .Values.global.storageClass -}}
{{- if (eq "-" .Values.global.storageClass) -}}
{{- printf "storageClassName: \"\"" -}}
{{- else }}
{{- printf "storageClassName: %s" .Values.global.storageClass -}}
{{- end -}}
{{- else -}}
{{- if .Values.persistence.storageClass -}}
{{- if (eq "-" .Values.persistence.storageClass) -}}
{{- printf "storageClassName: \"\"" -}}
{{- else }}
{{- printf "storageClassName: %s" .Values.persistence.storageClass -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{- if .Values.persistence.storageClass -}}
{{- if (eq "-" .Values.persistence.storageClass) -}}
{{- printf "storageClassName: \"\"" -}}
{{- else }}
{{- printf "storageClassName: %s" .Values.persistence.storageClass -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/*
Return Django Files ClaimName
*/}}
{{- define "django.claimName" -}}
{{ .Values.persistence.claimName | default (printf "%s-django-files" .Release.Name) }}
{{- end -}}
...@@ -27,15 +27,19 @@ spec: ...@@ -27,15 +27,19 @@ spec:
{{- toYaml .Values.securityContext | nindent 12 }} {{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Chart.AppVersion }}" image: "{{ .Values.image.repository }}:{{ .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }} imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Release.Name }}-postgresql
key: postgresql-password
envFrom: envFrom:
- configMapRef: - configMapRef:
name: django-config name: {{ .Release.Name }}-django-config
- configMapRef: - configMapRef:
name: postgres-config name: {{ .Release.Name }}-postgres-config
- secretRef: - secretRef:
name: postgres-password name: {{ .Release.Name }}-django-secret-key
- secretRef:
name: django-secret-key
ports: ports:
- name: gunicorn - name: gunicorn
containerPort: 5000 containerPort: 5000
...@@ -50,14 +54,14 @@ spec: ...@@ -50,14 +54,14 @@ spec:
livenessProbe: livenessProbe:
httpGet: httpGet:
path: /health_checks path: /health_checks
port: http port: gunicorn
initialDelaySeconds: 30 initialDelaySeconds: 30
periodSeconds: 10 periodSeconds: 10
timeoutSeconds: 5 timeoutSeconds: 5
readinessProbe: readinessProbe:
httpGet: httpGet:
path: /health_checks path: /health_checks
port: http port: gunicorn
initialDelaySeconds: 30 initialDelaySeconds: 30
periodSeconds: 10 periodSeconds: 10
timeoutSeconds: 5 timeoutSeconds: 5
...@@ -65,8 +69,12 @@ spec: ...@@ -65,8 +69,12 @@ spec:
{{- toYaml .Values.resources | nindent 12 }} {{- toYaml .Values.resources | nindent 12 }}
volumes: volumes:
- name: django-files - name: django-files
{{- if .Values.persistence.enabled }}
persistentVolumeClaim: persistentVolumeClaim:
claimName: django-files claimName: {{ include "django.claimName" . }}
{{- else }}
emptyDir: {}
{{- end }}
{{- with .Values.nodeSelector }} {{- with .Values.nodeSelector }}
nodeSelector: nodeSelector:
{{- toYaml . | nindent 8 }} {{- toYaml . | nindent 8 }}
......
apiVersion: v1 apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: django-config name: {{ .Release.Name }}-django-config
data: data:
DJANGO_DEBUG: "0" DJANGO_DEBUG: "0"
{{- range $key, $value := .Values.django.config }} {{- range $key, $value := .Values.django.config }}
{{ $key }}: {{ $value }} {{ $key }}: {{ $value | quote }}
{{- end }} {{- end }}
...@@ -2,6 +2,6 @@ apiVersion: v1 ...@@ -2,6 +2,6 @@ apiVersion: v1
kind: Secret kind: Secret
type: Opaque type: Opaque
metadata: metadata:
name: django-secret-key name: {{ .Release.Name }}-django-secret-key
data: data:
DJANGO_SECRET_KEY: {{ .Values.django.secret_key | default (randAlphaNum 72) }} DJANGO_SECRET_KEY: {{ include "django.secret_key" . | b64enc | quote }}
apiVersion: v1 apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: postgres-config name: {{ .Release.Name }}-postgres-config
data: data:
POSTGRES_DATABASE: {{ .Values.global.postgresql.postgresqlDatabase }} POSTGRES_DATABASE: {{ .Values.global.postgresql.postgresqlDatabase }}
POSTGRES_USER: {{ .Values.global.postgresql.postgresqlUsername }} POSTGRES_USER: {{ .Values.global.postgresql.postgresqlUsername }}
......
...@@ -15,7 +15,7 @@ image: ...@@ -15,7 +15,7 @@ image:
# #
django: django:
config: config:
DJANGO_ALLOWED_HOSTS: "['*']" DJANGO_ALLOWED_HOSTS: ['*']
# DJANGO_DEBUG: info # DJANGO_DEBUG: info
# DJANGO_SUPERUSER_USERNAME: admin # DJANGO_SUPERUSER_USERNAME: admin
# DJANGO_SUPERUSER_EMAIL: admin@example.com # DJANGO_SUPERUSER_EMAIL: admin@example.com
...@@ -63,6 +63,22 @@ ingress: ...@@ -63,6 +63,22 @@ ingress:
# hosts: # hosts:
# - chart-example.local # - chart-example.local
## Django files Persistent Volume Storage Class
## If defined, storageClassName: <storageClass>
## If set to "-", storageClassName: "", which disables dynamic provisioning
## If undefined (the default) or set to null, no storageClassName spec is
## set, choosing the default provisioner. (gp2 on AWS, standard on
## GKE, AWS & OpenStack)
##
persistence:
enabled: true
# claimName:
# storageClass: "-"
accessModes:
- ReadWriteOnce
size: 2Gi
annotations: {}
resources: {} resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious # We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little # choice for the user. This also increases chances charts run on environments with little
...@@ -82,6 +98,8 @@ tolerations: [] ...@@ -82,6 +98,8 @@ tolerations: []
affinity: {} affinity: {}
global: global:
django:
secretKey:
postgresql: postgresql:
postgresqlHost: postgresqlHost:
postgresqlUsername: django postgresqlUsername: django
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment