helmfile.yaml 4.45 KB
environments:
  default:
    values:
      - namespace: postgresql
        namePrefix: "test-"
        restoreFromEmpty:
          enabled: true
        postgresqlServer:
          jsonPatches: []
          strategicMergePatches: []
          postgresPassword: CHANGEME
          users:
            - name: CHANGEME
              password: CHANGEME
          databases:
            - name: CHANGEME
              users:
                - CHANGEME
        images:
          debian: "debian:bullseye-20211220"
          postgresql: "bitnami/postgresql:14.1.0-debian-10-r66"

---
releases:

  - name: {{ .Values.namePrefix }}postgresql-restore-from-empty
    namespace: {{ .Values.namespace }}
    chart: charts/restore-from-empty
    condition: restoreFromEmpty.enabled
    values:
      - set-common-values.yaml.gotmpl
    strategicMergePatches:
      - apiVersion: batch/v1
        kind: Job
        metadata:
          name: {{ .Values.namePrefix }}postgresql-restore-from-empty
          namespace: {{ .Values.namespace }}
        spec:
          template:
            spec:
              volumes:
                - name: postgresql-entrypoint-initdb
                  persistentVolumeClaim:
                    claimName: {{ .Values.namePrefix }}postgresql-entrypoint-initdb
                - name: postgresql-scripts
                  configMap:
                    name: {{ .Values.namePrefix }}postgresql-scripts

  - name: {{ .Values.namePrefix }}postgresql-server
    namespace: {{ .Values.namespace }}
    chart: .
    values:
      - set-common-values.yaml.gotmpl
    jsonPatches:
      {{- if not (empty (.Values.postgresqlServer.jsonPatches)) }}
      {{- .Values.postgresqlServer.jsonPatches | toYaml | indent 6 }}
      {{- end }}
    strategicMergePatches:
      - apiVersion: apps/v1
        kind: Deployment
        metadata:
          name: {{ .Values.namePrefix }}postgresql-server
          namespace: {{ .Values.namespace }}
        spec:
          selector:
            matchLabels:
              app: {{ .Values.namePrefix }}postgresql-server
          template:
            metadata:
              labels:
                app: {{ .Values.namePrefix }}postgresql-server
            spec:
              volumes:
                - name: postgresql-data
                  persistentVolumeClaim:
                    claimName: {{ .Values.namePrefix }}postgresql-data
                - name: postgresql-config
                  configMap:
                    name: {{ .Values.namePrefix }}postgresql-config
                - name: postgresql-scripts
                  configMap:
                    name: {{ .Values.namePrefix }}postgresql-scripts
                - name: postgresql-preinit-scripts
                  configMap:
                    name: {{ .Values.namePrefix }}postgresql-preinit-scripts
                - name: postgresql-secret
                  secret:
                    secretName: {{ .Values.namePrefix }}postgresql-secret
      - apiVersion: v1
        kind: Service
        metadata:
          name: {{ .Values.namePrefix }}postgresql
          namespace: {{ .Values.namespace }}
        spec:
          selector:
            app: {{ .Values.namePrefix }}postgresql-server
      - apiVersion: v1
        kind: ConfigMap
        metadata:
          name: {{ .Values.namePrefix }}postgresql-config
          namespace: {{ .Values.namespace }}
        data:
          {{- range $user_index, $user := .Values.postgresqlServer.users }}
          POSTGRESQL_USER_{{ $user_index }}_NAME: {{ $user.name | quote }}
          {{- end }}
          {{- range $db_index, $database := .Values.postgresqlServer.databases }}
          POSTGRESQL_DATABASE_{{ $db_index }}_NAME: {{ $database.name | quote }}
            {{- range $user_index, $user := $database.users }}
          POSTGRESQL_DATABASE_{{ $db_index }}_USER_{{ $user_index }}: {{ $user | quote }}
            {{- end }}
          {{- end }}
      - apiVersion: v1
        kind: Secret
        metadata:
          name: {{ .Values.namePrefix }}postgresql-secret
          namespace: {{ .Values.namespace }}
        stringData:
          POSTGRESQL_POSTGRES_PASSWORD: {{ .Values.postgresqlServer.postgresPassword }}
          {{- range $user_index, $user := .Values.postgresqlServer.users }}
          POSTGRESQL_USER_{{ $user_index }}_PASSWORD: {{ $user.password | quote }}
          {{- end }}
      {{- if not (empty (.Values.postgresqlServer.strategicMergePatches)) }}
      {{- .Values.postgresqlServer.strategicMergePatches | toYaml | indent 6 }}
      {{- end }}