apiVersion: v1
kind: Service
metadata:
  name: mdtodo-dev
  namespace: unidesk-dev
  labels:
    app.kubernetes.io/name: mdtodo
    app.kubernetes.io/part-of: unidesk
    app.kubernetes.io/component: mdtodo
    unidesk.ai/environment: dev
    unidesk.ai/deployment-mode: k3sctl-managed
    unidesk.ai/deploy-service-id: mdtodo
spec:
  type: ClusterIP
  selector:
    app.kubernetes.io/name: mdtodo
    app.kubernetes.io/part-of: unidesk
    app.kubernetes.io/component: mdtodo
    unidesk.ai/environment: dev
  ports:
    - name: http
      port: 4267
      targetPort: http
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mdtodo-dev
  namespace: unidesk-dev
  labels:
    app.kubernetes.io/name: mdtodo
    app.kubernetes.io/part-of: unidesk
    app.kubernetes.io/component: mdtodo
    unidesk.ai/environment: dev
    unidesk.ai/deployment-mode: k3sctl-managed
    unidesk.ai/deploy-service-id: mdtodo
  annotations:
    unidesk.ai/deploy-ref: deploy.json#environments.dev.services.mdtodo
    unidesk.ai/deploy-service-id: mdtodo
    unidesk.ai/image-source: deploy-env-commit
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app.kubernetes.io/name: mdtodo
      app.kubernetes.io/part-of: unidesk
      app.kubernetes.io/component: mdtodo
      unidesk.ai/environment: dev
  template:
    metadata:
      labels:
        app.kubernetes.io/name: mdtodo
        app.kubernetes.io/part-of: unidesk
        app.kubernetes.io/component: mdtodo
        unidesk.ai/environment: dev
        unidesk.ai/node-id: D601
        unidesk.ai/deploy-service-id: mdtodo
    spec:
      nodeSelector:
        unidesk.ai/node-id: D601
      terminationGracePeriodSeconds: 15
      initContainers:
        - name: seed-workspace
          image: rancher/mirrored-library-busybox:1.36.1
          imagePullPolicy: IfNotPresent
          command:
            - sh
            - -c
            - |
              set -eu
              mkdir -p /workspace
              if [ ! -f /workspace/dev-mdtodo.md ]; then
                cat > /workspace/dev-mdtodo.md <<'EOF'
# Dev MDTODO

## R1 Dev health seed

This seeded TODO file makes the dev health check prove readable hostPath storage.
EOF
              fi
          volumeMounts:
            - name: workspace
              mountPath: /workspace
      containers:
        - name: mdtodo
          image: unidesk-mdtodo:dev-placeholder
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              containerPort: 4267
          env:
            - name: HOST
              value: "0.0.0.0"
            - name: PORT
              value: "4267"
            - name: MDTODO_ROOT_DIR
              value: "/workspace"
            - name: LOG_FILE
              value: /var/log/unidesk-dev/mdtodo-dev.jsonl
            - name: UNIDESK_DEPLOY_SERVICE_ID
              value: mdtodo
            - name: UNIDESK_DEPLOY_REPO
              value: https://github.com/pikasTech/unidesk
            - name: UNIDESK_DEPLOY_COMMIT
              value: replace-with-deploy-env-commit
            - name: UNIDESK_DEPLOY_REQUESTED_COMMIT
              value: replace-with-deploy-env-commit
          volumeMounts:
            - name: workspace
              mountPath: /workspace
            - name: logs
              mountPath: /var/log/unidesk-dev
          readinessProbe:
            httpGet:
              path: /health
              port: http
            periodSeconds: 5
            timeoutSeconds: 3
            failureThreshold: 18
          livenessProbe:
            httpGet:
              path: /live
              port: http
            periodSeconds: 10
            timeoutSeconds: 3
            failureThreshold: 6
          startupProbe:
            httpGet:
              path: /live
              port: http
            periodSeconds: 5
            timeoutSeconds: 3
            failureThreshold: 30
          resources:
            requests:
              cpu: 50m
              memory: 96Mi
            limits:
              memory: 512Mi
      volumes:
        - name: workspace
          hostPath:
            path: /home/ubuntu/unidesk-dev-mdtodo-workspace
            type: DirectoryOrCreate
        - name: logs
          hostPath:
            path: /home/ubuntu/cq-deploy/.state/mdtodo-dev/logs
            type: DirectoryOrCreate
