moqui.yaml 6.4 KB
apiVersion: apps/v1
kind: {{ .Values.kind }}
metadata:
  name: {{ include "moqui.fullname" . }}
  labels:
    {{- include "moqui.labels" . | nindent 4 }}
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
  {{- end }}
  {{- if (eq "StatefulSet" .Values.kind) }}
  serviceName: {{ include "moqui.fullname" . }}
  {{- end }}
  selector:
    matchLabels:
      {{- include "moqui.selectorLabels" . | nindent 6 }}
  {{- if (eq "StatefulSet" .Values.kind) }}
  volumeClaimTemplates:
    {{- include "moqui.storage-volumeClaimTemplate" (list . "db") | nindent 4 }}
    {{- include "moqui.storage-volumeClaimTemplate" (list . "log") | nindent 4 }}
    {{- include "moqui.storage-volumeClaimTemplate" (list . "sessions") | nindent 4 }}
    {{- include "moqui.storage-volumeClaimTemplate" (list . "txlog") | nindent 4 }}
  {{- end }}
  template:
    metadata:
      {{- $checksums := (dict
        "checksum/config-map" (include (print .Template.BasePath "/config-map.yaml") . | sha256sum | trunc 63)
        "checksum/secret" (include (print .Template.BasePath "/secret.yaml") . | sha256sum | trunc 63)
      ) }}
      annotations: {{ merge (dict) .Values.podAnnotations $checksums | toYaml | nindent 8 }}
      labels:
        {{- include "moqui.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "moqui.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      volumes:
        - name: runtime-lib
          emptyDir: {}
        - name: disable-elasticsearch
          emptyDir: {}
        {{- include "moqui.storage-pvc-volume" (list . "db") | nindent 8 }}
        {{- include "moqui.storage-pvc-volume" (list . "log") | nindent 8 }}
        {{- include "moqui.storage-pvc-volume" (list . "sessions") | nindent 8 }}
        {{- include "moqui.storage-pvc-volume" (list . "txlog") | nindent 8 }}
      initContainers:
        {{- if (eq .Values.configMap.entity_ds_db_conf "postgres") }}
        {{-   if .Values.postgresql.jdbcImage.enabled }}
        - name: postgresql-copy-jdbc
          {{ include "moqui.image-helper" .Values.postgresql.jdbcImage | nindent 10 }}
          command:
            - bash
            - -cx
            - cp -a /usr/share/java/*.jar /tmp/runtime-lib
          volumeMounts:
            - mountPath: /tmp/runtime-lib
              name: runtime-lib

        {{-   end }}
        {{-   if (.Values.checkDsConnection.enabled) }}
        - name: postgresql-check-connection
          {{ include "moqui.image-helper" (coalesce .Values.postgresql.image .Values.checkImage) | nindent 10 }}
          env:
            - name: POSTGRES_HOST
              value: {{ include "moqui.entity_ds_host" . }}
            - name: POSTGRES_USER
              value: {{ include "moqui.entity_ds_user" . }}
            - name: POSTGRES_PORT
              value: {{ include "moqui.entity_ds_port" . | quote }}
          command:
            - bash
            - -cx
            - |-
              until pg_isready -h "${POSTGRES_HOST}" -U "${POSTGRES_USER}" -p ${POSTGRES_PORT}; do
                 sleep 5
              done

        {{-   end }}
        {{- end }}

          {{- define "moqui-container-pod" }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          {{ include "moqui.image-helper" .Values.image | nindent 10 }}
          command: ["java", "-server", "-XX:-OmitStackTraceInFastThrow", "-cp", ".", "MoquiStart"]
          envFrom:
            - configMapRef:
                name: {{ include "moqui.fullname" . }}
            - secretRef:
                name: {{ include "moqui.fullname" . }}-opensearch
          env:
            - name: entity_ds_db_conf
              value: 'postgres'
            - name: entity_ds_database
              value: {{ include "moqui.entity_ds_database" . }}
            - name: entity_ds_host
              value: {{ include "moqui.entity_ds_host" . }}
            - name: entity_ds_port
              value: {{ include "moqui.entity_ds_port" . | quote }}
            - name: entity_ds_user
              value: {{ include "moqui.entity_ds_user" . }}
            - name: entity_ds_password
              valueFrom:
                secretKeyRef:
                  name: {{ include "moqui.entity_ds_password.secret.name" . }}
                  key: {{ include "moqui.entity_ds_password.secret.key" . }}
                  optional: false
            - name: elasticsearch_url
              value: {{ include "moqui.opensearch-url" . }}
            {{- include "moqui.extraEnvs" . | nindent 12 }}
          volumeMounts:
            - mountPath: /opt/moqui/runtime/lib
              name: runtime-lib
            - mountPath: /opt/moqui/runtime/elasticsearch
              name: disable-elasticsearch
            {{- include "moqui.storage-mount" (list . "db" "/opt/moqui/runtime/db") | nindent 12 }}
            {{- include "moqui.storage-mount" (list . "log" "/opt/moqui/runtime/log") | nindent 12 }}
            {{- include "moqui.storage-mount" (list . "sessions" "/opt/moqui/runtime/sessions") | nindent 12 }}
            {{- include "moqui.storage-mount" (list . "txlog" "/opt/moqui/runtime/txlog") | nindent 12 }}
          {{- end }}

        - name: load
          {{ include "moqui-container-pod" . }}
          args:
            - "load"
            - -types=$(moqui_load_types)
            - -check-empty-types=$(entity_empty_db_load)

      containers:
        - name: {{ .Chart.Name }}
          {{ include "moqui-container-pod" . }}
          args: ["run"]

          ports:
            - name: http-moqui
              containerPort: 8080
              protocol: TCP
          {{ include "moqui.health-probe" (list "livenessProbe" .Values.health.liveness) | nindent 10 }}
          {{ include "moqui.health-probe" (list "readinessProbe" .Values.health.readiness) | nindent 10 }}
          {{ include "moqui.health-probe" (list "startupProbe" .Values.health.startup) | nindent 10 }}
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      itolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}