# _deprecations.tpl
{{- /*
A template for handling deprecation messages. The messages templated here will
be combined into a single `fail` call. This creates a means for the user to
receive all messages at one time, in place a frustrating iterative approach.

To add a deprecation:

1. Define a new template prefixed `mattermost.deprecate.`
2. Check for deprecated values / patterns, and directly output messages (see
   message format below)
3. Add a line to `mattermost.deprecations` to include the new template.

Message format:

```
deprecatedHelmConfig.option is deprecated, please use the following configuration instead...

newHelmConfig:
  option:
    {{- .Values.deprecatedHelmConfig.option | toYaml | nindent 4 }}
```
*/}}

{{- /*
Compile all deprecations into a single message, and call fail.
*/}}

{{- define "mattermost.deprecations" }}
{{- $depHeader := print "\n\nFAILURE DUE TO DEPRECATIONS:\n----------------------------" }}
{{- $depMessage := "" }}

{{- /*
deprecations in order to transition to a passthrough configuration in configJSON
*/}}
{{- $passthroughs := list }}
{{- $passthroughs := append $passthroughs (include "mattermost.deprecate.auth.gitlab" .) }}
{{- $passthroughs := append $passthroughs (include "mattermost.deprecate.config.siteUrl" .) }}
{{- $passthroughs := append $passthroughs (include "mattermost.deprecate.config.siteName" .) }}
{{- $passthroughs := append $passthroughs (include "mattermost.deprecate.config.fileSettings" .) }}
{{- $passthroughs := append $passthroughs (include "mattermost.deprecate.config.emailSettings" .) }}
{{- $passthroughs := without $passthroughs "" }}
{{- if $passthroughs }}
{{- $passthroughsHeader := print "\n\nconfigJSON:" }}
{{- $passthroughsMessage := print $passthroughsHeader (join "\n" $passthroughs) }}
{{- $depMessage := print $depMessage $passthroughsMessage }}}
{{- end }}

{{- if typeIs "string" .Values.extraInitContainers }}
{{- $stringToListMessage := print "\n\nPlease make extraInitContainers a list instead of a string.\nGot a '|' symbol after extraInitContainers? Remove it." }}
{{- $depMessage := print $depMessage $stringToListMessage }}
{{- end }}

{{- /* print output */}}
{{- if $depMessage }}
{{- printf $depMessage | fail }}
{{- end }}
{{- end }}



{{- /* Deprecate auth.gitlab */}}
{{- define "mattermost.deprecate.auth.gitlab" }}
{{- if typeIs "map[string]interface {}" .Values.auth }}
{{- if typeIs "map[string]interface {}" .Values.auth.gitlab }}
  # auth.gitlab is deprecated, instead use:
  GitLabSettings:
    {{- .Values.auth.gitlab | toYaml | nindent 4 }}
{{- end }}
{{- end }}
{{- end }}

{{- /* Deprecate config.siteUrl */}}
{{- define "mattermost.deprecate.config.siteUrl" }}
{{- if typeIs "map[string]interface {}" .Values.config }}
{{- if .Values.config.siteUrl }}
  # config.siteUrl is deprecated, instead use:
  ServiceSettings:
    SiteURL: {{ .Values.config.siteUrl | quote }}
{{- end }}
{{- end }}
{{- end }}

{{- /* Deprecate config.siteName */}}
{{- define "mattermost.deprecate.config.siteName" }}
{{- if typeIs "map[string]interface {}" .Values.config }}
{{- if .Values.config.siteName }}
  # config.siteName is deprecated, instead use:
  TeamSettings:
    SiteName: {{ .Values.config.siteName | quote }}
{{- end }}
{{- end }}
{{- end }}

{{- /* Deprecate config.fileSettings */}}
{{- define "mattermost.deprecate.config.fileSettings" }}
{{- if typeIs "map[string]interface {}" .Values.config }}
{{- $FileSettings := dict }}
{{- if or .Values.config.filesAccessKey (or .Values.config.filesSecretKey .Values.config.fileBucketName) }}
{{- $_ := set $FileSettings "DriverName" "amazons3" }}
{{- $_ := set $FileSettings "AmazonS3AccessKeyId" (.Values.config.filesAccessKey | default "") }}
{{- $_ := set $FileSettings "AmazonS3SecretAccessKey" (.Values.config.filesSecretKey | default "") }}
{{- $_ := set $FileSettings "AmazonS3Bucket" (.Values.config.fileBucketName | default "") }}
  # config.fileSecretKey,
  # config.fileAccessKey,
  # config.fileBucketName,
  # are all deprecated, instead use:
  FileSettings:
    {{- $FileSettings | toYaml | nindent 4 }}
{{- end }}
{{- end }}
{{- end }}

{{- /* Deprecate config.emailSettings */}}
{{- define "mattermost.deprecate.config.emailSettings" }}
{{- if typeIs "map[string]interface {}" .Values.config }}
{{- if or .Values.config.smtpServer (or (hasKey .Values.config "enableSignUpWithEmail") (or .Values.config.feedbackName .Values.config.feedbackEmail)) }}
{{- $EmailSettings := dict }}
{{- if .Values.config.smtpServer }}
{{- $_ := set $EmailSettings "SendEmailNotifications" true }}
{{- else }}
{{- $_ := set $EmailSettings "SendEmailNotifications" false }}
{{- end }}
{{- $_ := set $EmailSettings "EnableSignUpWithEmail" (.Values.config.enableSignUpWithEmail | default true) }}
{{- $_ := set $EmailSettings "FeedbackName" (.Values.config.feedbackName | default "") }}
{{- $_ := set $EmailSettings "FeedbackEmail" (.Values.config.feedbackEmail | default "") }}
{{- $_ := set $EmailSettings "SMTPUsername" (.Values.config.smtpUsername | default "") }}
{{- $_ := set $EmailSettings "SMTPPassword" (.Values.config.smtpPassword | default "") }}
{{- if and .Values.config.smtpUsername .Values.config.smtpPassword }}
{{- $_ := set $EmailSettings "EnableSMTPAuth" true }}
{{- else }}
{{- $_ := set $EmailSettings "EnableSMTPAuth" false }}
{{- end }}
{{- $_ := set $EmailSettings "SMTPServer" (.Values.config.smtpServer | default "") }}
{{- $_ := set $EmailSettings "SMTPPort" (.Values.config.smtpPort | default "") }}
{{- $_ := set $EmailSettings "ConnectionSecurity" (.Values.config.smtpConnection | default "") }}
  # config.enableSignUpWithEmail,
  # config.feedbackName,
  # config.feedbackEmail,
  # config.smtpUsername,
  # config.smtpPassword,
  # config.smtpUsername,
  # config.smtpPassword,
  # config.smtpServer,
  # config.smtpPort,
  # config.smtpConnection,
  # are all deprecated, instead use:
  EmailSettings:
    {{- $EmailSettings | toYaml | nindent 4 }}
{{- end }}
{{- end }}
{{- end }}
 # _helpers.tpl
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "mattermost-team-edition.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 "mattermost-team-edition.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 "mattermost-team-edition.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
 # _warnings.tpl
{{- /*
A template for handling warning messages.
*/}}

{{- /* Warn about not setting salt and keys explicitly */}}
{{- define "mattermost.warnings" }}
{{- with .Values.configJSON }}
{{- if not (and (.EmailSettings.InviteSalt) (and .FileSettings.PublicLinkSalt .SqlSettings.AtRestEncryptKey)) }}
WARNING:
--------

Every `helm upgrade` will generate a new set of keys unless it is set manually like this:

configJSON:
  {{- if not .EmailSettings.InviteSalt }}
  EmailSettings:
    InviteSalt: {{ randAlphaNum 32 }}
  {{- end }}
  {{- if not .FileSettings.PublicLinkSalt }}
  FileSettings:
    PublicLinkSalt: {{ randAlphaNum 32 }}
  {{- end }}
  {{- if not .SqlSettings.AtRestEncryptKey }}
  SqlSettings:
    AtRestEncryptKey: {{ randAlphaNum 32 }}
  {{- end }}
{{- end }}
{{- end }}
{{- end }}
 # deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "mattermost-team-edition.fullname" . }}
  labels:
    app.kubernetes.io/name: {{ include "mattermost-team-edition.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    helm.sh/chart: {{ include "mattermost-team-edition.chart" . }}
spec:
  replicas: 1
  strategy:
    type: Recreate
    rollingUpdate: null
  revisionHistoryLimit: {{ .Values.revisionHistoryLimit }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "mattermost-team-edition.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
      app.kubernetes.io/managed-by: {{ .Release.Service }}
  template:
    metadata:
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/secret-config.yaml") . | sha256sum }}
      labels:
        app.kubernetes.io/name: {{ include "mattermost-team-edition.name" . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
        app.kubernetes.io/managed-by: {{ .Release.Service }}
        helm.sh/chart: {{ include "mattermost-team-edition.chart" . }}
    spec:
      initContainers:
      {{- if not .Values.externalDB.enabled }}
      - name: "init-mysql"
        image: "{{ .Values.initContainerImage.repository }}:{{ .Values.initContainerImage.tag }}"
        imagePullPolicy: {{ .Values.initContainerImage.imagePullPolicy }}
        command: ["sh", "-c", "until curl --max-time 5 http://{{ .Release.Name }}-mysql:3306; do echo waiting for {{ .Release.Name }}-mysql; sleep 5; done;"]
      {{- end }}
      {{- if .Values.extraInitContainers }}
      {{- .Values.extraInitContainers | toYaml | nindent 6 }}
      {{- end }}
      containers:
      - name: {{ .Chart.Name }}
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        imagePullPolicy: {{ .Values.image.imagePullPolicy }}
        env:
        {{- if .Values.extraEnvVars }}
          {{- .Values.extraEnvVars | toYaml | nindent 10 }}
        {{- end }}
        ports:
        - name: http
          containerPort: {{ .Values.service.internalPort }}
          protocol: TCP
        livenessProbe:
          initialDelaySeconds: 90
          timeoutSeconds: 5
          periodSeconds: 15
          httpGet:
            path: /api/v4/system/ping
            port: http
        readinessProbe:
          initialDelaySeconds: 15
          timeoutSeconds: 5
          periodSeconds: 15
          httpGet:
            path: /api/v4/system/ping
            port: http
        volumeMounts:
        - mountPath: /mattermost/config/config.json
          name: config-json
          subPath: config.json
        - mountPath: /mattermost/data
          name: mattermost-data
        resources:
          {{- .Values.resources | toYaml | nindent 12 }}
      volumes:
      - name: config-json
        secret:
          secretName: {{ include "mattermost-team-edition.fullname" . }}-config-json
      - name: mattermost-data
      {{ if .Values.persistence.data.enabled }}
        persistentVolumeClaim:
          claimName: {{ .Values.persistence.data.existingClaim | default (include "mattermost-team-edition.fullname" .) }}
      {{ else }}
        emptyDir: {}
      {{ end }}
 # ingress.yaml
{{ $ingress := .Values.ingress }}
{{ if $ingress.enabled }}
{{ $serviceName := include "mattermost-team-edition.name" . }}
{{ $servicePort := .Values.service.externalPort }}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{ include "mattermost-team-edition.fullname" . }}
  labels:
    app.kubernetes.io/name: {{ include "mattermost-team-edition.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    helm.sh/chart: {{ include "mattermost-team-edition.chart" . }}
  annotations:
    {{- if .Values.ingress.tls }}
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
    kubernetes.io/tls-acme: "true"
    {{- else }}
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    {{- end }}
    {{- with $ingress.annotations }}
    {{- . | toYaml | nindent 4 }}
    {{- end }}
spec:
  rules:
  {{ range $host := $ingress.hosts }}
  - host: {{ $host }}
    http:
      paths:
      - path: {{ $ingress.path }}
        backend:
          serviceName: {{ $serviceName }}
          servicePort: {{ $servicePort }}
  {{ end }}
  {{ if $ingress.tls }}
  tls:
    {{- $ingress.tls | toYaml | nindent 4 }}
  {{ end }}
{{ end }}
 # mattermost-config-test.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include  "mattermost-team-edition.fullname" . }}-tests
  labels:
    app.kubernetes.io/name: {{ include "mattermost-team-edition.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    helm.sh/chart: {{ include "mattermost-team-edition.chart" . }}
data:
  run.sh: |-
    @test "Testing Mattermost is accessible" {
      curl --retry 48 --retry-delay 10 {{ include "mattermost-team-edition.name" . }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.service.internalPort }}
    }
 # mattermost-test.yaml
apiVersion: v1
kind: Pod
metadata:
  name: "{{ include  "mattermost-team-edition.fullname" . }}-test-{{ randAlphaNum 5 | lower }}"
  labels:
    app.kubernetes.io/name: {{ include "mattermost-team-edition.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    helm.sh/chart: {{ include "mattermost-team-edition.chart" . }}
  annotations:
    "helm.sh/hook": test-success
spec:
  initContainers:
  - name: "test-framework"
    image: "dduportal/bats:0.4.0"
    command:
    - "bash"
    - "-c"
    - |
      set -ex
      # copy bats to tools dir
      cp -R /usr/local/libexec/ /tools/bats/
    volumeMounts:
    - mountPath: /tools
      name: tools
  containers:
  - name: {{ .Release.Name }}-test
    image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
    command: ["/tools/bats/bats", "-t", "/tests/run.sh"]
    volumeMounts:
    - mountPath: /tests
      name: tests
      readOnly: true
    - mountPath: /tools
      name: tools
  volumes:
  - name: tests
    configMap:
      name: {{ include  "mattermost-team-edition.fullname" . }}-tests
  - name: tools
    emptyDir: {}
  restartPolicy: Never
 # pvc.yaml
{{- if and .Values.persistence.data.enabled (not .Values.persistence.data.existingClaim) -}}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: {{ include "mattermost-team-edition.fullname" . }}
  labels:
    app.kubernetes.io/name: {{ include "mattermost-team-edition.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    helm.sh/chart: {{ include "mattermost-team-edition.chart" . }}
  annotations:
  {{- range $key, $value := .Values.persistence.data.annotations }}
    {{ $key }}: {{ $value | quote }}
  {{- end }}
spec:
  accessModes:
  - {{ .Values.persistence.data.accessMode | quote }}
  resources:
    requests:
      storage: {{ .Values.persistence.data.size | quote }}
{{- if .Values.persistence.data.storageClass }}
{{- if (eq "-" .Values.persistence.data.storageClass) }}
  storageClassName: ""
{{- else }}
  storageClassName: "{{ .Values.persistence.data.storageClass }}"
{{- end }}
{{- end }}
{{- end }}
 # secret-config.yaml
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "mattermost-team-edition.fullname" . }}-config-json
  labels:
    app.kubernetes.io/name: {{ include "mattermost-team-edition.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    helm.sh/chart: {{ include "mattermost-team-edition.chart" . }}
type: Opaque
data:
  {{- /* Make a deep enough copy of the default config */}}
  {{- $c := dict }}
  {{- range $key, $dictVal := .Values.configJSON }}
  {{- $dictCopy := merge (dict) $dictVal }}
  {{- $_ := set $c $key $dictCopy }}
  {{- end }}

  {{- /* Update the copied default config based on .Values */}}

  {{- if or .Values.configJSON.SqlSettings.DriverName .Values.configJSON.SqlSettings.DataSource }}
  {{- $message := "Use 'mysql' or 'externalDB' to instead of using a configuration with:\n\nconfigJSON:\n  SqlSettings\n    DriverName: ...\n    DataSource: ..." }}
  {{- print "\n\nDIRECT CONFIGURATION NOT SUPPORTED:\n-----------------------------------\n\n" $message | fail }}
  {{- end }}

  {{- if .Values.externalDB.enabled }}
  {{- $_ := set $c.SqlSettings "DriverName" (.Values.externalDB.externalDriverType) }}
  {{- $_ := set $c.SqlSettings "DataSource" (.Values.externalDB.externalConnectionString) }}
  {{- else }}
  {{- $_ := set $c.SqlSettings "DriverName" "mysql" }}
  {{- $_ := set $c.SqlSettings "DataSource" (print .Values.mysql.mysqlUser ":" .Values.mysql.mysqlPassword "@tcp(" .Release.Name "-mysql:3306)/" .Values.mysql.mysqlDatabase "?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s") }}
  {{- end }}

  {{- $_ := set $c.SqlSettings "AtRestEncryptKey" (.Values.configJSON.SqlSettings.AtRestEncryptKey | default (randAlphaNum 32)) }}
  {{- $_ := set $c.FileSettings "PublicLinkSalt" (.Values.configJSON.FileSettings.PublicLinkSalt | default (randAlphaNum 32)) }}
  {{- $_ := set $c.EmailSettings "InviteSalt" (.Values.configJSON.EmailSettings.InviteSalt | default (randAlphaNum 32)) }}

  {{- /* Render the processed config as a JSON string */}}
  {{- /* NOTE: Mounted at /mattermost/config/config.json on the mattermost pod */}}
  config.json: {{ $c | toJson | b64enc }}
 # service.yaml
apiVersion: v1
kind: Service
metadata:
  name: {{ include "mattermost-team-edition.name" . }}
  labels:
    app.kubernetes.io/name: {{ include "mattermost-team-edition.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    helm.sh/chart: {{ include "mattermost-team-edition.chart" . }}
spec:
  selector:
    app.kubernetes.io/name: {{ include "mattermost-team-edition.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
  type: {{ .Values.service.type }}
  ports:
  - port: {{ .Values.service.externalPort }}
    targetPort: http
    protocol: TCP
    name: {{  include "mattermost-team-edition.name" . }}

# Default values for mattermost-team-edition.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
image:
  repository: mattermost/mattermost-team-edition
  tag: 5.9.0
  imagePullPolicy: IfNotPresent

initContainerImage:
  repository: appropriate/curl
  tag: latest
  imagePullPolicy: IfNotPresent

## How many old ReplicaSets for Mattermost Deployment you want to retain
revisionHistoryLimit: 1

## Enable persistence using Persistent Volume Claims
## ref: http://kubernetes.io/docs/user-guide/persistent-volumes/
## ref: https://docs.gitlab.com/ee/install/requirements.html#storage
##
persistence:
  ## This volume persists generated data from users, like images, attachments...
  ##
  data:
    enabled: true
    size: 10Gi
    ## If defined, volume.beta.kubernetes.io/storage-class: <storageClass>
    ## Default: volume.alpha.kubernetes.io/storage-class: default
    ##
    # storageClass:
    accessMode: ReadWriteOnce
  # existingClaim: ""

service:
  type: ClusterIP
  externalPort: 8065
  internalPort: 8065

ingress:
  enabled: false
  path: /
  annotations: {}
    # kubernetes.io/ingress.class: nginx
    # certmanager.k8s.io/issuer:  your-issuer
    # nginx.ingress.kubernetes.io/proxy-body-size: 50m
    # nginx.ingress.kubernetes.io/proxy-send-timeout: "600"
    # nginx.ingress.kubernetes.io/proxy-read-timeout: "600"
    # nginx.ingress.kubernetes.io/proxy-buffering: "on"
    # nginx.ingress.kubernetes.io/configuration-snippet: |
    #   proxy_cache mattermost_cache;
    #   proxy_cache_revalidate on;
    #   proxy_cache_min_uses 2;
    #   proxy_cache_use_stale timeout;
    #   proxy_cache_lock on;
    #### To use the nginx cache you will need to set an http-snippet in the ingress-nginx configmap
    #### http-snippet: |
    ####     proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=mattermost_cache:10m max_size=3g inactive=120m use_temp_path=off;
  hosts:
    - mattermost.example.com
  tls:
    # - secretName: mattermost.example.com-tls
    #   hosts:
    #     - mattermost.example.com


## If use this please disable the mysql chart by setting mysql.enable to false
externalDB:
  enabled: false

  ## postgres or mysql
  externalDriverType: ""

  ## postgres:  "postgres://<USERNAME>:<PASSWORD>@<HOST>:5432/<DATABASE_NAME>?sslmode=disable&connect_timeout=10"
  ## mysql:     "<USERNAME>:<PASSWORD>@tcp(<HOST>:3306)/<DATABASE_NAME>?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s"
  externalConnectionString: ""

mysql:
  enabled: true
  mysqlRootPassword: ""
  mysqlUser: ""
  mysqlPassword: ""
  mysqlDatabase: mattermost

  repository: mysql
  tag: 5.7
  imagePullPolicy: IfNotPresent

  persistence:
    enabled: true
    ## 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: 10Gi
  # existingClaim: ""

## Additional env vars
extraEnvVars: []
  # This is an example of extra env vars when using with the deployment with GitLab Helm Charts
  # - name: POSTGRES_PASSWORD_GITLAB
  #   valueFrom:
  #     secretKeyRef:
  #       # NOTE: Needs to be manually created
  #       # kubectl create secret generic gitlab-postgresql-password --namespace <NAMESPACE> --from-literal postgres-password=<PASSWORD>
  #       name: gitlab-postgresql-password
  #       key: postgres-password
  # - name: POSTGRES_USER_GITLAB
  #   value: gitlab
  # - name: POSTGRES_HOST_GITLAB
  #   value: gitlab-postgresql
  # - name: POSTGRES_PORT_GITLAB
  #   value: "5432"
  # - name: POSTGRES_DB_NAME_MATTERMOST
  #   value: mm5
  # - name: MM_SQLSETTINGS_DRIVERNAME
  #   value: "postgres"
  # - name: MM_SQLSETTINGS_DATASOURCE
  #   value: postgres://$(POSTGRES_USER_GITLAB):$(POSTGRES_PASSWORD_GITLAB)@$(POSTGRES_HOST_GITLAB):$(POSTGRES_PORT_GITLAB)/$(POSTGRES_DB_NAME_MATTERMOST)?sslmode=disable&connect_timeout=10

## Additional init containers
extraInitContainers: []
  # This is an example of extra Init Container when using with the deployment with GitLab Helm Charts
  # - name: bootstrap-database
  #   image: "postgres:9.6-alpine"
  #   imagePullPolicy: IfNotPresent
  #   env:
  #     - name: POSTGRES_PASSWORD_GITLAB
  #       valueFrom:
  #         secretKeyRef:
  #           name: gitlab-postgresql-password
  #           key: postgres-password
  #     - name: POSTGRES_USER_GITLAB
  #       value: gitlab
  #     - name: POSTGRES_HOST_GITLAB
  #       value: gitlab-postgresql
  #     - name: POSTGRES_PORT_GITLAB
  #       value: "5432"
  #     - name: POSTGRES_DB_NAME_MATTERMOST
  #       value: mm5
  #   command:
  #     - sh
  #     - "-c"
  #     - |
  #       if PGPASSWORD=$POSTGRES_PASSWORD_GITLAB psql -h $POSTGRES_HOST_GITLAB -p $POSTGRES_PORT_GITLAB -U $POSTGRES_USER_GITLAB -lqt | cut -d \| -f 1 | grep -qw $POSTGRES_DB_NAME_MATTERMOST; then
  #       echo "database already exist, exiting initContainer"
  #       exit 0
  #       else
  #       echo "Database does not exist. creating...."
  #       PGPASSWORD=$POSTGRES_PASSWORD_GITLAB createdb -h $POSTGRES_HOST_GITLAB -p $POSTGRES_PORT_GITLAB -U $POSTGRES_USER_GITLAB $POSTGRES_DB_NAME_MATTERMOST
  #       echo "Done"
  #       fi

# NOTE: These acts as the default values for the config.json file read by the
# mattermost server itself. You can override the configJSON object just like any
# Helm template value. Since it is an object, the object you provide will merge
# with these defaults. Also note that this is YAML, so you can choose to use
# either JSON or YAML as JSON is a subset of YAML. No matter what you choose,
# the config.json file that will be generated will be correctly JSON formatted.
configJSON: {
  "ServiceSettings": {
    "SiteURL": "",
    "LicenseFileLocation": "",
    "ListenAddress": ":8065",
    "ConnectionSecurity": "",
    "TLSCertFile": "",
    "TLSKeyFile": "",
    "UseLetsEncrypt": false,
    "LetsEncryptCertificateCacheFile": "./config/letsencrypt.cache",
    "Forward80To443": false,
    "ReadTimeout": 300,
    "WriteTimeout": 300,
    "MaximumLoginAttempts": 10,
    "GoroutineHealthThreshold": -1,
    "GoogleDeveloperKey": "",
    "EnableOAuthServiceProvider": false,
    "EnableIncomingWebhooks": true,
    "EnableOutgoingWebhooks": true,
    "EnableCommands": true,
    "EnableOnlyAdminIntegrations": false,
    "EnablePostUsernameOverride": false,
    "EnablePostIconOverride": false,
    "EnableLinkPreviews": false,
    "EnableTesting": false,
    "EnableDeveloper": false,
    "EnableSecurityFixAlert": true,
    "EnableInsecureOutgoingConnections": false,
    "EnableMultifactorAuthentication": false,
    "EnforceMultifactorAuthentication": false,
    "AllowCorsFrom": "",
    "SessionLengthWebInDays": 30,
    "SessionLengthMobileInDays": 30,
    "SessionLengthSSOInDays": 30,
    "SessionCacheInMinutes": 10,
    "WebsocketSecurePort": 443,
    "WebsocketPort": 80,
    "WebserverMode": "gzip",
    "EnableCustomEmoji": false,
    "RestrictCustomEmojiCreation": "all",
    "RestrictPostDelete": "all",
    "AllowEditPost": "always",
    "PostEditTimeLimit": 300,
    "TimeBetweenUserTypingUpdatesMilliseconds": 5000,
    "EnablePostSearch": true,
    "EnableUserTypingMessages": true,
    "EnableUserStatuses": true,
    "ClusterLogTimeoutMilliseconds": 2000
  },
  "TeamSettings": {
    "SiteName": "Mattermost",
    "MaxUsersPerTeam": 50000,
    "EnableTeamCreation": true,
    "EnableUserCreation": true,
    "EnableOpenServer": true,
    "RestrictCreationToDomains": "",
    "EnableCustomBrand": false,
    "CustomBrandText": "",
    "CustomDescriptionText": "",
    "RestrictDirectMessage": "any",
    "RestrictTeamInvite": "all",
    "RestrictPublicChannelManagement": "all",
    "RestrictPrivateChannelManagement": "all",
    "RestrictPublicChannelCreation": "all",
    "RestrictPrivateChannelCreation": "all",
    "RestrictPublicChannelDeletion": "all",
    "RestrictPrivateChannelDeletion": "all",
    "RestrictPrivateChannelManageMembers": "all",
    "UserStatusAwayTimeout": 300,
    "MaxChannelsPerTeam": 50000,
    "MaxNotificationsPerChannel": 1000
  },
  "SqlSettings": {
    "DriverName": "",
    "DataSource": "",
    "DataSourceReplicas": [],
    "DataSourceSearchReplicas": [],
    "MaxIdleConns": 20,
    "MaxOpenConns": 35,
    "Trace": false,
    "AtRestEncryptKey": "",
    "QueryTimeout": 30
  },
  "LogSettings": {
    "EnableConsole": true,
    "ConsoleLevel": "INFO",
    "EnableFile": true,
    "FileLevel": "INFO",
    "FileFormat": "",
    "FileLocation": "",
    "EnableWebhookDebugging": true,
    "EnableDiagnostics": true
  },
  "PasswordSettings": {
    "MinimumLength": 5,
    "Lowercase": false,
    "Number": false,
    "Uppercase": false,
    "Symbol": false
  },
  "FileSettings": {
    "EnableFileAttachments": true,
    "MaxFileSize": 52428800,
    "DriverName": "local",
    "Directory": "./data/",
    "EnablePublicLink": false,
    "PublicLinkSalt": "",
    "ThumbnailWidth": 120,
    "ThumbnailHeight": 100,
    "PreviewWidth": 1024,
    "PreviewHeight": 0,
    "ProfileWidth": 128,
    "ProfileHeight": 128,
    "InitialFont": "luximbi.ttf",
    "AmazonS3AccessKeyId": "",
    "AmazonS3SecretAccessKey": "",
    "AmazonS3Bucket": "",
    "AmazonS3Region": "",
    "AmazonS3Endpoint": "s3.amazonaws.com",
    "AmazonS3SSL": false,
    "AmazonS3SignV2": false
  },
  "EmailSettings": {
    "EnableSignUpWithEmail": true,
    "EnableSignInWithEmail": true,
    "EnableSignInWithUsername": true,
    "SendEmailNotifications": false,
    "RequireEmailVerification": false,
    "FeedbackName": "",
    "FeedbackEmail": "",
    "FeedbackOrganization": "",
    "SMTPUsername": "",
    "SMTPPassword": "",
    "EnableSMTPAuth": "",
    "SMTPServer": "",
    "SMTPPort": "",
    "ConnectionSecurity": "",
    "InviteSalt": "",
    "SendPushNotifications": true,
    "PushNotificationServer": "https://push-test.mattermost.com",
    "PushNotificationContents": "generic",
    "EnableEmailBatching": false,
    "EmailBatchingBufferSize": 256,
    "EmailBatchingInterval": 30,
    "SkipServerCertificateVerification": false
  },
  "RateLimitSettings": {
    "Enable": false,
    "PerSec": 10,
    "MaxBurst": 100,
    "MemoryStoreSize": 10000,
    "VaryByRemoteAddr": true,
    "VaryByHeader": ""
  },
  "PrivacySettings": {
    "ShowEmailAddress": true,
    "ShowFullName": true
  },
  "SupportSettings": {
    "TermsOfServiceLink": "https://about.mattermost.com/default-terms/",
    "PrivacyPolicyLink": "https://about.mattermost.com/default-privacy-policy/",
    "AboutLink": "https://about.mattermost.com/default-about/",
    "HelpLink": "https://about.mattermost.com/default-help/",
    "ReportAProblemLink": "https://about.mattermost.com/default-report-a-problem/",
    "SupportEmail": "feedback@mattermost.com"
  },
  "AnnouncementSettings": {
    "EnableBanner": false,
    "BannerText": "",
    "BannerColor": "#f2a93b",
    "BannerTextColor": "#333333",
    "AllowBannerDismissal": true
  },
  "GitLabSettings": {
    "Enable": false,
    "Secret": "",
    "Id": "",
    "Scope": "",
    "AuthEndpoint": "",
    "TokenEndpoint": "",
    "UserApiEndpoint": ""
  },
  "LocalizationSettings": {
    "DefaultServerLocale": "en",
    "DefaultClientLocale": "en",
    "AvailableLocales": ""
  },
  "NativeAppSettings": {
    "AppDownloadLink": "https://about.mattermost.com/downloads/",
    "AndroidAppDownloadLink": "https://about.mattermost.com/mattermost-android-app/",
    "IosAppDownloadLink": "https://about.mattermost.com/mattermost-ios-app/"
  },
  "AnalyticsSettings": {
    "MaxUsersForStatistics": 2500
  },
  "WebrtcSettings": {
    "Enable": false,
    "GatewayWebsocketUrl": "",
    "GatewayAdminUrl": "",
    "GatewayAdminSecret": "",
    "StunURI": "",
    "TurnURI": "",
    "TurnUsername": "",
    "TurnSharedKey": ""
  },
  "DisplaySettings": {
    "CustomUrlSchemes": [],
    "ExperimentalTimezone": true
  },
  "TimezoneSettings": {
    "SupportedTimezonesPath": "timezones.json"
  },
  "PluginSettings": {
    "Enable": true,
    "EnableUploads": true,
    "Directory": "./plugins",
    "ClientDirectory": "./client/plugins",
    "Plugins": {},
    "PluginStates": {}
  }
}
