# Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

apiVersion: apps/v1
kind: Deployment
metadata:
  name: splitwell-web-ui
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "splice-util-lib.default-labels" (set . "app" "splitwell-web-ui") | nindent 4 }}
spec:
  replicas: 1
  selector:
    matchLabels:
      app: splitwell-web-ui
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        {{- include "splice-util-lib.default-labels" (set . "app" "splitwell-web-ui") | nindent 8 }}
    spec:
      {{- include "splice-util-lib.service-account" .Values | nindent 6 }}
      containers:
      - name: splitwell-web-ui
        image: "{{ .Values.imageRepo }}/splitwell-web-ui:{{ .Chart.AppVersion }}{{ ((.Values.imageDigests).splitwell_web_ui) }}"
        {{- with .Values.imagePullPolicy }}
        imagePullPolicy: {{ . }}
        {{- end }}
        env:
        - name: SPLICE_APP_UI_AUTH_CLIENT_ID
          valueFrom:
            secretKeyRef:
              key: client-id
              name: splice-app-splitwell-ui-auth
              optional: false
        - name: SPLICE_APP_UI_AUTH_URL
          valueFrom:
            secretKeyRef:
              key: url
              name: splice-app-splitwell-ui-auth
              optional: false
        - name: SPLICE_APP_UI_AUTH_AUDIENCE
          value: {{ .Values.auth.audience | quote }}
        - name: SPLICE_APP_UI_CLUSTER
          value: {{ .Values.clusterUrl | quote }}
        - name: SPLICE_APP_UI_NETWORK_NAME
          value: {{ .Values.spliceInstanceNames.networkName | quote }}
        - name: SPLICE_APP_UI_NETWORK_FAVICON_URL
          value: {{ .Values.spliceInstanceNames.networkFaviconUrl | quote }}
        - name: SPLICE_APP_UI_AMULET_NAME
          value: {{ .Values.spliceInstanceNames.amuletName | quote }}
        - name: SPLICE_APP_UI_AMULET_NAME_ACRONYM
          value: {{ .Values.spliceInstanceNames.amuletNameAcronym | quote }}
        - name: SPLICE_APP_UI_NAME_SERVICE_NAME
          value: {{ .Values.spliceInstanceNames.nameServiceName | quote }}
        - name: SPLICE_APP_UI_NAME_SERVICE_NAME_ACRONYM
          value: {{ .Values.spliceInstanceNames.nameServiceNameAcronym | quote }}
        ports:
        - containerPort: 8080
          name: val1-sw-ui
          protocol: TCP
        {{- with .Values.resources }}
        resources: {{- toYaml . | nindent 10 }}
        {{- 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 }}
---
apiVersion: v1
kind: Service
metadata:
  name: splitwell-web-ui
  namespace: {{ .Release.Namespace }}
spec:
  selector:
    app: splitwell-web-ui
  ports:
  - name: val1-sw-ui
    port: 80
    targetPort: val1-sw-ui
    protocol: TCP
