#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: {{ .Release.Namespace | quote }}
  name: {{ include "seata-server.name" . }}
  labels:
{{ include "seata-server.labels" . | indent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "seata-server.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ include "seata-server.name" . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 8091
              protocol: TCP
          {{- if .Values.volume }}
          volumeMounts:
            {{- range .Values.volume }}
            - name: {{ .name }}
              mountPath: {{ .mountPath }}
            {{- end}}
          {{- end}}
        {{- if .Values.env }}
          env:
          {{- if .Values.env.seataIp }}
            - name: SEATA_IP
              value: {{ .Values.env.seataIp  | quote }}
          {{- end }}
          {{- if .Values.env.seataPort }}
            - name: SEATA_PORT
              value: {{ .Values.env.seataPort | quote }}
          {{- end }}
          {{- if .Values.env.seataEnv }}
            - name: SEATA_ENV
              value: {{ .Values.env.seataEnv }}
          {{- end }}
          {{- if .Values.env.seataConfigName }}
            - name: SEATA_CONFIG_NAME
              value: {{ .Values.env.seataConfigName }}
          {{- end }}
          {{- if .Values.env.serverNode }}
            - name: SERVER_NODE
              value: {{ .Values.env.serverNode | quote }}
          {{- end }}
          {{- if .Values.env.storeMode }}
            - name: STORE_MODE
              value: {{ .Values.env.storeMode }}
          {{- end }}
        {{- end }}
     {{- if .Values.volume }}
      volumes:
        {{- range .Values.volume }}
        - name: {{ .name }}
          hostPath:
            path: {{ .hostPath}}
        {{- end}}
     {{- end}}