{{- include "openwork-ee.customCa.validate" . }}
apiVersion: v1
kind: Service
metadata:
  name: {{ include "openwork-ee.denWebServiceName" . }}
  labels:
    {{- include "openwork-ee.componentLabels" (dict "root" . "component" "den-web") | nindent 4 }}
  {{- with .Values.denWeb.service.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  type: {{ .Values.denWeb.service.type }}
  {{- with .Values.denWeb.service.loadBalancerClass }}
  loadBalancerClass: {{ . | quote }}
  {{- end }}
  {{- with .Values.denWeb.service.loadBalancerSourceRanges }}
  loadBalancerSourceRanges:
    {{- toYaml . | nindent 4 }}
  {{- end }}
  ports:
    - name: http
      port: {{ .Values.denWeb.service.port }}
      targetPort: http
  selector:
    {{- include "openwork-ee.componentSelectorLabels" (dict "root" . "component" "den-web") | nindent 4 }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "openwork-ee.fullname" . }}-den-web
  labels:
    {{- include "openwork-ee.componentLabels" (dict "root" . "component" "den-web") | nindent 4 }}
spec:
  replicas: {{ .Values.denWeb.replicaCount }}
  selector:
    matchLabels:
      {{- include "openwork-ee.componentSelectorLabels" (dict "root" . "component" "den-web") | nindent 6 }}
  template:
    metadata:
      labels:
        {{- include "openwork-ee.componentSelectorLabels" (dict "root" . "component" "den-web") | nindent 8 }}
        {{- with .Values.denWeb.podLabels }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
        checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
        {{- with .Values.denWeb.podAnnotations }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- if .Values.customCa.enabled }}
      volumes:
        {{- include "openwork-ee.customCa.volume" . | nindent 8 }}
      {{- end }}
      containers:
        - name: den-web
          image: "{{ .Values.denWeb.image.repository }}:{{ default .Values.image.tag .Values.denWeb.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: {{ .Values.denWeb.containerPort }}
          {{- if .Values.customCa.enabled }}
          volumeMounts:
            {{- include "openwork-ee.customCa.volumeMount" . | nindent 12 }}
          {{- end }}
          envFrom:
            - configMapRef:
                name: {{ include "openwork-ee.configName" . }}
            - secretRef:
                name: {{ include "openwork-ee.secretName" . }}
          env:
            - name: PORT
              value: {{ .Values.denWeb.containerPort | quote }}
            {{- if .Values.customCa.enabled }}
            {{- include "openwork-ee.customCa.env" . | nindent 12 }}
            {{- end }}
            {{- include "openwork-ee.observabilityEnv" (dict "root" . "serviceName" .Values.observability.serviceNames.denWeb) | nindent 12 }}
            {{- range $key, $value := .Values.denWeb.env }}
            - name: {{ $key }}
              value: {{ $value | quote }}
            {{- end }}
          livenessProbe:
            httpGet:
              path: /api/health
              port: http
            {{- toYaml .Values.denWeb.probes.liveness | nindent 12 }}
          readinessProbe:
            httpGet:
              path: /api/ready
              port: http
            {{- toYaml .Values.denWeb.probes.readiness | nindent 12 }}
          {{- with .Values.denWeb.resources }}
          resources:
            {{- toYaml . | nindent 12 }}
          {{- end }}
