{{ if .Values.webjobs.enabled }}
apiVersion: v1
kind: ServiceAccount
metadata:
  name: webjobs
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: app-rolebinding
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: admin
subjects:
- kind: ServiceAccount
  namespace: merkal
  name: webjobs
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: webjobs
spec:
  replicas: 1
  selector:
    matchLabels:
      app: webjobs
  template:
    metadata:
      name: webjobs
      labels:
        app: webjobs
    spec:
      serviceAccountName: webjobs
      terminationGracePeriodSeconds: 1
      containers:
      - name: webjobs
        image: docker.io/goalprofit/webjobs:{{.Values.webjobs.version}}
        imagePullPolicy: Always
        args:
          - bash
          - /app/run.sh
          - {{ .Values.webjobs.config | toJson | quote }}
        volumeMounts:
        - mountPath: /work
          name: work
        env:
        - name: ADMIN_LOGIN
          valueFrom:
            secretKeyRef:
              name: secret-admin
              key: username
              optional: false
        - name: ADMIN_PASSWORD
          valueFrom:
            secretKeyRef:
              name: secret-admin
              key: password
              optional: false
{{ 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: work
        hostPath:
          path: /data/{{.Values.customer}}/data/webjobs
          type: Directory
      {{ include "app.affinity" . | nindent 6}}
---
apiVersion: v1
kind: Service
metadata:
  name: webjobs
spec:
  type: ClusterIP
  selector:
    app: webjobs
  ports:
    - name: http
      protocol: TCP
      port: 8082
      targetPort: 8082
{{ end }}