apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "openclaw-mission-control.fullname" . }}
  labels:
    {{- include "openclaw-mission-control.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  strategy:
    type: Recreate
  selector:
    matchLabels:
      {{- include "openclaw-mission-control.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- if .Values.envSecret.create }}
      annotations:
        checksum/env-secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
      {{- end }}
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "openclaw-mission-control.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "openclaw-mission-control.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: mission-control
          image: {{ include "openclaw-mission-control.image" . }}
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          env:
            {{- range $key, $value := .Values.env }}
            - name: {{ $key }}
              value: {{ $value | quote }}
            {{- end }}
            {{- with .Values.extraEnv }}
            {{- toYaml . | nindent 12 }}
            {{- end }}
          {{- if or .Values.envSecret.create .Values.envSecret.existingSecret }}
          envFrom:
            - secretRef:
                name: {{ include "openclaw-mission-control.envSecretName" . }}
          {{- end }}
          ports:
            - name: http
              containerPort: 4000
              protocol: TCP
          volumeMounts:
            - name: data
              mountPath: /app/data
            - name: workspace
              mountPath: /app/workspace
          {{- if .Values.livenessProbe.enabled }}
          livenessProbe:
            {{- omit .Values.livenessProbe "enabled" | toYaml | nindent 12 }}
          {{- end }}
          {{- if .Values.readinessProbe.enabled }}
          readinessProbe:
            {{- omit .Values.readinessProbe "enabled" | toYaml | nindent 12 }}
          {{- end }}
          {{- if .Values.startupProbe.enabled }}
          startupProbe:
            {{- omit .Values.startupProbe "enabled" | toYaml | nindent 12 }}
          {{- end }}
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
      volumes:
        - name: data
          {{- if .Values.persistence.data.enabled }}
          persistentVolumeClaim:
            claimName: {{ include "openclaw-mission-control.fullname" . }}-data
          {{- else }}
          emptyDir: {}
          {{- end }}
        - name: workspace
          {{- if .Values.persistence.workspace.enabled }}
          persistentVolumeClaim:
            claimName: {{ include "openclaw-mission-control.fullname" . }}-workspace
          {{- else }}
          emptyDir: {}
          {{- end }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
