{{ if .Values.pim20_data_loader.enabled }}
apiVersion: v1
kind: Service
metadata:
  name: pim20-data-loader
spec:
  type: ClusterIP
  selector:
    app: pim20-data-loader
  ports:
    - name: http
      protocol: TCP
      port: 8080
      targetPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: pim20-data-loader
spec:
  replicas: 1
  selector:
    matchLabels:
      app: pim20-data-loader
  template:
    metadata:
      name: pim20-data-loader
      labels:
        app: pim20-data-loader
    spec:
      containers:
        - name: pim20-data-loader
          image: goalprofit/pim20-data-loader:{{.Values.pim20_data_loader.version}}
          imagePullPolicy: Always
          ports:
            - containerPort: 8080
          env:
            - name: API_SERVICE
              value: {{.Values.pim20_data_loader.api_service}}
            - name: PORT
              value: "8080"
            - name: DATA_PATH
              value: /tmp
            - name: TEMP_DATA_PATH
              value: /tmp
            - name: STORAGE_DATA_PATH
              value: /data_storage
            - name: BASE_URL
              value: /data_loader
            - name: SERVICE_LOGIN
              valueFrom:
                secretKeyRef:
                  name: secret-admin
                  key: username
            - name: SERVICE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: secret-admin
                  key: password
{{ if .Values.pim20_data_loader.codes_generator_version }}
            - name: CODES_GENERATOR_SERVICE
              value: http://pim20-codes-generator:8080/codes_generator
{{ end }}
          volumeMounts:
            - mountPath: /data_storage
              name: data-loader-results-storage
      imagePullSecrets:
      - name: regcred
      volumes:
        - name: data-loader-results-storage
          hostPath:
            path: /data/{{.Values.customer}}/out/ext
            type: Directory
{{ if .Values.pim20_data_loader.codes_generator_version }}
---
apiVersion: v1
kind: Service
metadata:
  name: pim20-codes-generator
spec:
  type: ClusterIP
  selector:
    app: pim20-codes-generator
  ports:
    - name: http
      protocol: TCP
      port: 8080
      targetPort: 8080
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: pim20-codes-generator
spec:
  replicas: 1
  serviceName: pim20-codes-generator
  selector:
    matchLabels:
      app: pim20-codes-generator
  template:
    metadata:
      name: pim20-codes-generator
      labels:
        app: pim20-codes-generator
    spec:
      containers:
        - name: pim20-codes-generator
          image: goalprofit/pim20-codes-generator:{{.Values.pim20_data_loader.codes_generator_version}}
          imagePullPolicy: Always
          ports:
            - containerPort: 8080
          env:
            - name: API_SERVICE
              value: {{.Values.pim20_data_loader.api_service}}
            - name: PORT
              value: "8080"
            - name: BASE_URL
              value: /codes_generator
            - name: SERVICE_LOGIN
              valueFrom:
                secretKeyRef:
                  name: secret-admin
                  key: username
            - name: SERVICE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: secret-admin
                  key: password
      imagePullSecrets:
      - name: regcred
{{ end }}
{{ end }}