mirror of
https://github.com/Thumbscrew/k8s-charts.git
synced 2025-07-06 20:52:45 +00:00
add support for internal and external postgres
This commit is contained in:
@ -60,3 +60,81 @@ Create the name of the service account to use
|
||||
{{- default "default" .Values.serviceAccount.name }}
|
||||
{{- end }}
|
||||
{{- 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).
|
||||
*/}}
|
||||
{{- define "tandoor-recipes.postgresql.fullname" -}}
|
||||
{{- printf "%s-%s" .Release.Name "postgresql" | trunc 63 | trimSuffix "-" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/*
|
||||
Set postgres host
|
||||
*/}}
|
||||
{{- define "tandoor-recipes.postgresql.host" -}}
|
||||
{{- if .Values.postgresql.enabled -}}
|
||||
{{- template "tandoor-recipes.postgresql.fullname" . -}}
|
||||
{{- else -}}
|
||||
{{ required "A valid externalPostgresql.host is required" .Values.externalPostgresql.host }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/*
|
||||
Set postgres secret
|
||||
*/}}
|
||||
{{- define "tandoor-recipes.postgresql.secret" -}}
|
||||
{{- if .Values.postgresql.enabled -}}
|
||||
{{- template "tandoor-recipes.postgresql.fullname" . -}}
|
||||
{{- else -}}
|
||||
{{- template "tandoor-recipes.fullname" . -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/*
|
||||
Set postgres port
|
||||
*/}}
|
||||
{{- define "tandoor-recipes.postgresql.port" -}}
|
||||
{{- if .Values.postgresql.enabled -}}
|
||||
{{- if .Values.postgresql.service -}}
|
||||
{{- .Values.postgresql.service.port | default 5432 }}
|
||||
{{- else -}}
|
||||
5432
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- required "A valid externalPostgresql.port is required" .Values.externalPostgresql.port -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/*
|
||||
Set postgresql username
|
||||
*/}}
|
||||
{{- define "tandoor-recipes.postgresql.username" -}}
|
||||
{{- if .Values.postgresql.enabled -}}
|
||||
{{ required "A valid postgresql.auth.username is required" .Values.postgresql.auth.username }}
|
||||
{{- else -}}
|
||||
{{ required "A valid externalPostgresql.username is required" .Values.externalPostgresql.username }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/*
|
||||
Set postgresql password
|
||||
*/}}
|
||||
{{- define "tandoor-recipes.postgresql.password" -}}
|
||||
{{- if .Values.postgresql.enabled -}}
|
||||
{{ required "A valid postgresql.auth.password is required" .Values.postgresql.auth.password }}
|
||||
{{- else if not (and .Values.externalPostgresql.existingSecret .Values.externalPostgresql.existingSecretPasswordKey) -}}
|
||||
{{ required "A valid externalPostgresql.password is required" .Values.externalPostgresql.password }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/*
|
||||
Set postgresql database
|
||||
*/}}
|
||||
{{- define "tandoor-recipes.postgresql.database" -}}
|
||||
{{- if .Values.postgresql.enabled -}}
|
||||
{{- .Values.postgresql.auth.database | default "recipes" }}
|
||||
{{- else -}}
|
||||
{{ required "A valid externalPostgresql.database is required" .Values.externalPostgresql.database }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
@ -5,9 +5,9 @@ metadata:
|
||||
labels:
|
||||
{{- include "tandoor-recipes.labels" . | nindent 4 }}
|
||||
spec:
|
||||
{{- if not .Values.autoscaling.enabled }}
|
||||
replicas: {{ .Values.replicaCount }}
|
||||
{{- end }}
|
||||
strategy:
|
||||
type: Recreate
|
||||
selector:
|
||||
matchLabels:
|
||||
{{- include "tandoor-recipes.selectorLabels" . | nindent 6 }}
|
||||
@ -37,6 +37,24 @@ spec:
|
||||
- name: http
|
||||
containerPort: {{ .Values.service.port }}
|
||||
protocol: TCP
|
||||
env:
|
||||
- name: DB_ENGINE
|
||||
value: django.db.backends.postgresql
|
||||
- name: POSTGRES_HOST
|
||||
value: {{ include "tandoor-recipes.postgresql.host" . }}
|
||||
- name: POSTGRES_PORT
|
||||
value: {{ include "tandoor-recipes.postgresql.port" . | quote }}
|
||||
- name: POSTGRES_USER
|
||||
value: {{ include "tandoor-recipes.postgresql.username" . }}
|
||||
- name: POSTGRES_PASSWORD
|
||||
value: {{ include "tandoor-recipes.postgresql.password" . }}
|
||||
- name: POSTGRES_DB
|
||||
value: {{ include "tandoor-recipes.postgresql.database" . }}
|
||||
- name: SECRET_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: recipes-secret-key
|
||||
key: password
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
|
@ -1,32 +0,0 @@
|
||||
{{- if .Values.autoscaling.enabled }}
|
||||
apiVersion: autoscaling/v2
|
||||
kind: HorizontalPodAutoscaler
|
||||
metadata:
|
||||
name: {{ include "tandoor-recipes.fullname" . }}
|
||||
labels:
|
||||
{{- include "tandoor-recipes.labels" . | nindent 4 }}
|
||||
spec:
|
||||
scaleTargetRef:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
name: {{ include "tandoor-recipes.fullname" . }}
|
||||
minReplicas: {{ .Values.autoscaling.minReplicas }}
|
||||
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
|
||||
metrics:
|
||||
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
|
||||
- type: Resource
|
||||
resource:
|
||||
name: cpu
|
||||
target:
|
||||
type: Utilization
|
||||
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
|
||||
{{- end }}
|
||||
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
|
||||
- type: Resource
|
||||
resource:
|
||||
name: memory
|
||||
target:
|
||||
type: Utilization
|
||||
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
|
||||
{{- end }}
|
||||
{{- end }}
|
12
charts/tandoor-recipes/templates/secret.yaml
Normal file
12
charts/tandoor-recipes/templates/secret.yaml
Normal file
@ -0,0 +1,12 @@
|
||||
{{- if empty .Values.secretKey }}
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: "recipes-secret-key"
|
||||
type: Opaque
|
||||
data:
|
||||
{{- $secretObj := (lookup "v1" "Secret" .Release.Namespace "recipes-secret-key") | default dict }}
|
||||
{{- $secretData := (get $secretObj "data") | default dict }}
|
||||
{{- $secretKey := (get $secretData "recipes-secret-key") | default (randAlphaNum 32 | b64enc) }}
|
||||
password: {{ $secretKey | quote }}
|
||||
{{- end }}
|
Reference in New Issue
Block a user