## Bitnami PostgreSQL image version
## ref: https://hub.docker.com/r/bitnami/postgresql/tags/
##
image:
  registry: quay.io
  repository: bitnami/postgresql
  tag: "{{ version }}"
  ## Specify a imagePullPolicy
  ## Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent'
  ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images
  ##
  pullPolicy: IfNotPresent
  ## Optionally specify an array of imagePullSecrets.
  ## Secrets must be manually created in the namespace.
  ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
  ##
  # pullSecrets:
  #   - myRegistryKeySecretName

  ## Set to true if you would like to see extra information on logs
  ## It turns BASH and NAMI debugging in minideb
  ## ref:  https://github.com/bitnami/minideb-extras/#turn-on-bash-debugging
  debug: false

## String to partially override postgresql.fullname template (will maintain the release name)
##
nameOverride: '{{ sanitized_name }}'

## String to fully override postgresql.fullname template
##
fullnameOverride: '{{ sanitized_name }}'

##
## Init containers parameters:
## volumePermissions: Change the owner of the persist volume mountpoint to RunAsUser:fsGroup
##
volumePermissions:
  enabled: true
  image:
    registry: docker.io
    repository: bitnami/minideb
    tag: buster
    ## Specify a imagePullPolicy
    ## Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent'
    ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images
    ##
    pullPolicy: IfNotPresent
    ## Optionally specify an array of imagePullSecrets.
    ## Secrets must be manually created in the namespace.
    ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
    ##
    # pullSecrets:
    #   - myRegistryKeySecretName
  ## Init container Security Context
  ## Note: the chown of the data folder is done to securityContext.runAsUser
  ## and not the below volumePermissions.securityContext.runAsUser
  ## When runAsUser is set to special value "auto", init container will try to chwon the
  ## data folder to autodetermined user&group, using commands: `id -u`:`id -G | cut -d" " -f2`
  ## "auto" is especially useful for OpenShift which has scc with dynamic userids (and 0 is not allowed).
  ## You may want to use this volumePermissions.securityContext.runAsUser="auto" in combination with
  ## pod securityContext.enabled=false and shmVolume.chmod.enabled=false
  ##
  securityContext:
    runAsUser: 0

## Use an alternate scheduler, e.g. "stork".
## ref: https://kubernetes.io/docs/tasks/administer-cluster/configure-multiple-schedulers/
##
# schedulerName:


## Pod Security Context
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/
##
securityContext:
  enabled: true
  fsGroup: 1001
  runAsUser: 1001

## Pod Service Account
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/
serviceAccount:
  enabled: false
  ## sanitized_name of an already existing service account. Setting this value disables the automatic service account creation.
  # name:

## Pod Security Policy
## ref: https://kubernetes.io/docs/concepts/policy/pod-security-policy/
psp:
  create: false

## Creates role for ServiceAccount
## Required for PSP
rbac:
  create: true

## PostgreSQL admin password (used when `postgresqlUsername` is not `postgres`)
## ref: https://github.com/bitnami/bitnami-docker-postgresql/blob/master/README.md#creating-a-database-user-on-first-run (see note!)
postgresqlPostgresPassword: '{{ database_password }}'

## PostgreSQL user (has superuser privileges if username is `postgres`)
## ref: https://github.com/bitnami/bitnami-docker-postgresql/blob/master/README.md#setting-the-root-password-on-first-run
postgresqlUsername: '{{ database_login }}'

## PostgreSQL password
## ref: https://github.com/bitnami/bitnami-docker-postgresql/blob/master/README.md#setting-the-root-password-on-first-run
##
postgresqlPassword: '{{ database_password }}'

## Create a database
## ref: https://github.com/bitnami/bitnami-docker-postgresql/blob/master/README.md#creating-a-database-on-first-run
##
postgresqlDatabase: '{{ database_db_name }}'

## Specify the PostgreSQL username and password to execute the initdb scripts
initdbUser: postgres
initdbPassword: '{{ database_password }}'

## PostgreSQL service configuration
service:
  ## PosgresSQL service type

  type: {% if publicly_accessible -%} LoadBalancer {% else -%} ClusterIP {% endif %}
  # clusterIP: None
  port: 5432
  name: {{ service_name }}

  ## Provide any additional annotations which may be required. Evaluated as a template.
  ##
  {% if publicly_accessible %}
  annotations:
    service.beta.kubernetes.io/scw-loadbalancer-forward-port-algorithm: "leastconn"
    service.beta.kubernetes.io/scw-loadbalancer-protocol-http: "false"
    service.beta.kubernetes.io/scw-loadbalancer-proxy-protocol-v1: "false"
    service.beta.kubernetes.io/scw-loadbalancer-proxy-protocol-v2: "false"
    service.beta.kubernetes.io/scw-loadbalancer-health-check-type: tcp
    service.beta.kubernetes.io/scw-loadbalancer-use-hostname: "false"
    external-dns.alpha.kubernetes.io/hostname: "{{ fqdn }}"
    external-dns.alpha.kubernetes.io/ttl: "300"
  {% endif %}

## PostgreSQL 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)
##
persistence:
  enabled: true
  ## A manually managed Persistent Volume and Claim
  ## If defined, PVC must be created manually before volume will be bound
  ## The value is evaluated as a template, so, for example, the name can depend on .Release or .Chart
  ##
  # existingClaim:

  ## The path the volume will be mounted at, useful when using different
  ## PostgreSQL images.
  ##
  mountPath: /bitnami/postgresql

  ## The subdirectory of the volume to mount to, useful in dev environments
  ## and one PV for multiple services.
  ##
  subPath: ""

  storageClass: {{ database_disk_type }}
  accessModes:
    - ReadWriteOnce
  size: {{ database_disk_size_in_gib }}Gi
  annotations:
    ownerId: {{ owner_id }}
    envId: {{ environment_id }}
    databaseId: {{ id }}
    databaseName: '{{ sanitized_name }}'

##
## PostgreSQL Master parameters
##
master:
  ## Node, affinity, tolerations, and priorityclass settings for pod assignment
  ## ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector
  ## ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity
  ## ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#taints-and-tolerations-beta-feature
  ## ref: https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption
  nodeSelector: {}
  affinity: {}
  tolerations: []
  labels:
    ownerId: {{ owner_id }}
    envId: {{ environment_id }}
    databaseId: {{ id }}
  annotations: {}
  podLabels:
    ownerId: {{ owner_id }}
    envId: {{ environment_id }}
    databaseId: {{ id }}
  podAnnotations: {}
  priorityClassName: ""
  ## Extra init containers
  ## Example
  ##
  ## extraInitContainers:
  ##   - name: do-something
  ##     image: busybox
  ##     command: ['do', 'something']
  extraInitContainers: []

  ## Additional PostgreSQL Master Volume mounts
  ##
  extraVolumeMounts: []
  ## Additional PostgreSQL Master Volumes
  ##
  extraVolumes: []
  ## Add sidecars to the pod
  ##
  ## For example:
  ## sidecars:
  ##   - name: your-image-name
  ##     image: your-image
  ##     imagePullPolicy: Always
  ##     ports:
  ##       - name: portname
  ##         containerPort: 1234
  sidecars: []

  ## Override the service configuration for master
  ##
  service: {}
  # type:
  # nodePort:
  # clusterIP:

## Configure resource requests and limits
## ref: http://kubernetes.io/docs/user-guide/compute-resources/
##
resources:
  requests:
    memory: "{{ database_ram_size_in_mib }}Mi" # TODO customizable?
    cpu: "{{ database_total_cpus }}"
