{{ if .Values.retail.enabled }}
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: retail
spec:
  replicas: 1
  serviceName: retail
  selector:
    matchLabels:
      app: retail
  template:
    metadata:
      name: retail
      labels:
        app: retail
    spec:
      terminationGracePeriodSeconds: 1
      containers:
      - name: retail
        image: {{.Values.retail.image}}:{{.Values.retail.version}}
        imagePullPolicy: Always
        volumeMounts:
        - mountPath: /work
          name: customer
          subPath: in/int/retail
        - mountPath: /storage
          name: customer
          subPath: data/storage
        - mountPath: /in
          name: customer
          subPath: in
#        - mountPath: /home
#          name: home
        ports:
          - containerPort: 9090
        readinessProbe:
          tcpSocket:
            port: 9090
          initialDelaySeconds: 5
          periodSeconds: 10
        livenessProbe:
          tcpSocket:
            port: 9090
          initialDelaySeconds: 10
          periodSeconds: 20
        env:
        - name: TZ
          value: {{ .Values.timeZone }}
        - name: SERVER_SERVICE
          value: http://server:8080
        - name: OPTIMIZATION_SERVICE
          value: {{ .Values.retail.optimization_url }}
        - name: OPTIMIZATIONMD_SERVICE
          value: {{ .Values.retail.optimizationmd_url }}
        - name: OPTIMIZATION_TEST_SERVICE
          value: {{ .Values.retail.optimization_test_url }}
        - name: OPTIMIZATIONMD_TEST_SERVICE
          value: {{ .Values.retail.optimizationmd_test_url }}
        - name: RSA_PRIVATE_KEY
          valueFrom:
            secretKeyRef:
              name: retail-key
              key: private-key
              optional: true
        - name: RSA_PUBLIC_KEY
          valueFrom:
            secretKeyRef:
              name: retail-key
              key: public-key
              optional: true          
        - name: CONFIG
          valueFrom:
            secretKeyRef:
              name: retail-key
              key: config
              optional: true
{{ if .Values.local_user_id }}
        - name: LOCAL_USER_ID
          value: "{{.Values.local_user_id}}"
{{ end }}
{{ if .Values.local_user_name }}
        - name: LOCAL_USER_NAME
          value: "{{.Values.local_user_name}}"
{{ end }}

      imagePullSecrets:
      - name: regcred

      volumes:
      - name: customer
       {{ include "app.customer_volume" . | nindent 8}}

      {{ include "app.affinity" . | nindent 6}}
---
apiVersion: v1
kind: Service
metadata:
  name: retail
spec:
  type: ClusterIP
  selector:
    app: retail
  ports:
    - name: http
      protocol: TCP
      port: 9090
      targetPort: 9090
{{ end }}