apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "hami-webui.fullname" . }}
  namespace: {{ include "hami-webui.namespace" . }}
  labels:
    {{- include "hami-webui.labels" . | nindent 4 }}
    app.kubernetes.io/component: "hami-webui"
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      {{- include "hami-webui.selectorLabels" . | nindent 6 }}
      app.kubernetes.io/component: "hami-webui"
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "hami-webui.selectorLabels" . | nindent 8 }}
        app.kubernetes.io/component: "hami-webui"
    spec:
      serviceAccountName: {{ include "hami-webui.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}-fe-oss
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.frontend.repository }}:{{ .Values.image.frontend.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.frontend.pullPolicy }}
          env:
            {{- toYaml .Values.env.frontend | nindent 12 }}
          ports:
            - name: http
              containerPort: 3000
              protocol: TCP
          command:
            - "node"
          args:
            - "/apps/dist/main"
          resources:
            {{- toYaml .Values.resources.frontend | nindent 12 }}
        - name: {{ .Chart.Name }}-be-oss
          securityContext:
                  {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.backend.repository }}:{{ .Values.image.backend.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.backend.pullPolicy }}
          env:
            {{- toYaml .Values.env.backend | nindent 12 }}
          ports:
            - name: metrics
              containerPort: 8000
              protocol: TCP
          command:
            - "/apps/server"
          args:
            - "--conf"
            - "/apps/config/config.yaml"
          resources:
            {{- toYaml .Values.resources.backend | nindent 12 }}
          volumeMounts:
            - name: config
              mountPath: /apps/config/
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      volumes:
        - name: config
          configMap:
            name: {{ include "hami-webui.fullname" . }}-config