apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "openviking.fullname" . }}
  labels:
    {{- include "openviking.labels" . | nindent 4 }}
spec:
  replicas: 1
  selector:
    matchLabels:
      {{- include "openviking.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        {{- include "openviking.labels" . | nindent 8 }}
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          command:
            - /bin/sh
            - -c
            - |
              exec uv run --with openviking openviking-server \
                --host {{ .Values.server.host }} \
                --port {{ .Values.server.port }} \
                --config /etc/openviking/ov.conf
          ports:
            - name: http
              containerPort: {{ .Values.server.port }}
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /health
              port: http
            initialDelaySeconds: 120
            periodSeconds: 15
            failureThreshold: 5
          readinessProbe:
            httpGet:
              path: /health
              port: http
            initialDelaySeconds: 60
            periodSeconds: 10
            failureThreshold: 5
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          volumeMounts:
            - name: config
              mountPath: /etc/openviking
              readOnly: true
      volumes:
        - name: config
          secret:
            secretName: {{ include "openviking.fullname" . }}-config
