# _helpers.tpl
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "sapho.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).
*/}}
{{- define "sapho.fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | 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).
*/}}
{{- define "sapho.mysql.fullname" -}}
{{- printf "%s-%s" .Release.Name "mysql" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
 # deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "sapho.fullname" . }}
  labels:
    app: {{ template "sapho.fullname" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    release: {{ .Release.Name }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ template "sapho.fullname" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ template "sapho.fullname" . }}
        release: {{ .Release.Name }}
    spec:
      containers:
      - name: {{ template "sapho.fullname" . }}
        image: "{{ .Values.image }}"
        imagePullPolicy: {{ default "" .Values.imagePullPolicy | quote }}
        env:
        - name: SAPHO_VERSION
          value: {{ .Values.saphoVersion }}
        - name: SAPHO_DB_HOSTNAME
          value: {{ template "sapho.mysql.fullname" . }}
        - name: SAPHO_DB_PORT
          value: {{ .Values.saphoDBport | quote }}
        - name: SAPHO_DB_TYPE
          value: {{ .Values.saphoDBtype }}
        - name: SAPHO_DB_USERNAME
          value: {{ .Values.saphoDBuser }}
        - name: SAPHO_DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: {{ template "sapho.mysql.fullname" . }}
              key: mysql-root-password
        ports:
        - name: http
          containerPort: 8080
        livenessProbe:
          httpGet:
            path: /
            port: http
          initialDelaySeconds: 180
          timeoutSeconds: 10
        readinessProbe:
          httpGet:
            path: /
            port: http
          initialDelaySeconds: 30
          timeoutSeconds: 5
        resources:
{{ toYaml .Values.resources | indent 12 }}
 # service.yaml
apiVersion: v1
kind: Service
metadata:
  name: {{ template "sapho.fullname" . }}
  labels:
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
spec:
  type: {{ .Values.service.type }}
  ports:
  - port: {{ .Values.service.externalPort }}
    targetPort: {{ .Values.service.internalPort }}
    protocol: TCP
    name: {{ .Values.service.name }}
  selector:
    app: {{ template "sapho.fullname" . }}

# Default values for sapho.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1
image: sapho/ops-docker-tomcat:8-jre8

mysql:
  persistence:
    enabled: true
    ## mysql data 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)
    ##
    # storageClass: "-"
    accessMode: ReadWriteOnce
    size: 8Gi
  resources:
    requests:
      memory: 512Mi
      cpu: 250m

service:
  name: sapho
  type: LoadBalancer
  externalPort: 80
  internalPort: 8080

resources:
#  limits:
#    cpu: 500m
#    memory: 2048Mi
  requests:
    cpu: 250m
    memory: 2048Mi
saphoVersion: 4.2.0
saphoDBport: 3306
saphoDBtype: mysql
saphoDBuser: root
