apiVersion: apps/v1
kind: Deployment
metadata:
  name: craftlings-steam
  namespace: {{ .Values.namespaceName }}
  labels:
    app: craftlings-gaming
spec:
  replicas: {{ .Values.replicaCount }}
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: craftlings-gaming
  template:
    metadata:
      labels:
        app: craftlings-gaming
    spec:
      nodeSelector:
        {{ toYaml .Values.nodeSelector | nindent 8 }}
      securityContext:
        {{ toYaml .Values.securityContext | nindent 8 }}

      hostIPC: true
      hostPID: false

      containers:
      - name: steam
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}

        ports:
        - name: http
          containerPort: {{ .Values.service.targetPort }}
          protocol: TCP

        env:
        {{- range $key, $value := .Values.environment }}
        - name: {{ $key }}
          value: "{{ $value }}"
        {{- end }}

        resources:
          {{ toYaml .Values.resources | nindent 10 }}

        volumeMounts:
        {{- if .Values.persistence.config.enabled }}
        - name: steam-config
          mountPath: {{ .Values.persistence.config.mountPath }}
        {{- end }}
        - name: shm
          mountPath: /dev/shm
        - name: dri
          mountPath: /dev/dri
        - name: pulse
          mountPath: /run/pulse
          readOnly: true

        {{- if .Values.containerSecurityContext }}
        securityContext:
          {{ toYaml .Values.containerSecurityContext | nindent 10 }}
        {{- end }}

      volumes:
      {{- if .Values.persistence.config.enabled }}
      - name: steam-config
        persistentVolumeClaim:
          claimName: steam-config
      {{- end }}
      - name: shm
        emptyDir:
          medium: Memory
          sizeLimit: 512Mi
      - name: dri
        hostPath:
          path: /dev/dri
      - name: pulse
        hostPath:
          path: /run/pulse
