{{ if .Values.coder.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sync-coder-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: sync-coder-deployment
  template:
    metadata:
      labels:
        app: sync-coder-deployment
    spec:
      volumes:
        - name: secret-github-tokens
          secret:
            secretName: github-tokens
            defaultMode: 420
            optional: true
      serviceAccountName: coder
      containers:
        - name: sync-coder-deployment
          image: {{ .Values.coder.sync_coder.image }}:{{ .Values.coder.sync_coder.version }}
          imagePullPolicy: Always
          resources:
            limits:
              cpu: "1"
              memory: "1Gi"
            requests:
              cpu: "200m"
              memory: "256Mi"
          livenessProbe:
            httpGet:
              path: /coder/health
              port: 8082
            initialDelaySeconds: 30
            periodSeconds: 300
          volumeMounts:
            - name: secret-github-tokens
              mountPath: /secret/tokens
              mountPropagation: None
          env:
            - name: LOG_LEVEL
              value: info
            - name: CODER_APP_VERSION
              value: {{ .Values.coder.sync_coder.version }}
            - name: CODER_USER_CREDS_PATH
              value: /secret/tokens
            - name: CODER_GIT_REPO
              valueFrom:
                secretKeyRef:
                  name: coder-sync
                  key: coder_git_repo
            - name: CODER_GIT_TOKEN
              valueFrom:
                secretKeyRef:
                  name: coder-sync
                  key: coder_git_token
            - name: CODER_ADMIN_USERNAME
              valueFrom:
                secretKeyRef:
                  name: coder-sync
                  key: coder_user
                  optional: true
            - name: CODER_ADMIN_TOKEN
              valueFrom:
                secretKeyRef:
                  name: coder-sync
                  key: coder_token
      imagePullSecrets:
        - name: regcred

---
apiVersion: v1
kind: Service
metadata:
  name: sync-coder-service
spec:
  type: ClusterIP
  selector:
    app: sync-coder-deployment
  ports:
    - name: http
      protocol: TCP
      port: 8082
      targetPort: 8082
{{ end }}