{{ if .Values.packman.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: packman
spec:
  replicas: 1
  selector:
    matchLabels:
      app: packman
  template:
    metadata:
      name: packman
      labels:
        app: packman
    spec:
      terminationGracePeriodSeconds: 1
      containers:
      - name: packman
        image: docker.io/goalprofit/packman:{{.Values.packman.version}}
        imagePullPolicy: Always
#        command:
#          - sleep
#          - "inf"
        volumeMounts:
        - mountPath: /data
          name: customer
          subPath: data
        - mountPath: /packman
          name: customer
          subPath: data/packman
        ports:
          - containerPort: 9091
#        readinessProbe:
#          tcpSocket:
#            port: 9091
#          initialDelaySeconds: 5
#          periodSeconds: 10
#        livenessProbe:
#          tcpSocket:
#            port: 9091
#          initialDelaySeconds: 10
#          periodSeconds: 20
        env:
        - name: SERVICE_LOGIN
          valueFrom:
            secretKeyRef:
              name: secret-admin
              key: username
              optional: false
        - name: SERVICE_PASSWORD
          valueFrom:
            secretKeyRef:
              name: secret-admin
              key: password
              optional: false
        - name: PACKS_REPO_URL
          valueFrom:
            secretKeyRef:
              name: packs-repo
              key: url
              optional: true
        - name: PACKS_REPO_PRIVATE_KEY
          valueFrom:
            secretKeyRef:
              name: packs-repo
              key: private-key
              optional: true
        - name: PACKS_REPO_PUBLIC_KEY
          valueFrom:
            secretKeyRef:
              name: packs-repo
              key: public-key
              optional: true
        - name: GH_TOKEN
          valueFrom:
            secretKeyRef:
              name: packs-repo
              key: github-token
              optional: true
        - name: CUSTOMER
          value: {{ .Values.customer }}

{{ 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: packman
spec:
  type: ClusterIP
  selector:
    app: packman
  ports:
    - name: http
      protocol: TCP
      port: 9091
      targetPort: 5004
{{ end }}