apiVersion: v1
kind: Service
metadata:
  name: ui
  namespace: {{ .Release.Namespace }}
spec:
  type: ClusterIP
  selector:
    app: ui
  ports:
  - name: http
    port: 80
    targetPort: http
    protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
  name: api
  namespace: {{ .Release.Namespace }}
spec:
  type: ClusterIP
  selector:
    app: ui
  ports:
  - name: http
    port: 80
    targetPort: api
    protocol: TCP
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ui
  namespace: {{ .Release.Namespace }}
  annotations:
    acme.cert-manager.io/http01-edit-in-place: "true"
    cert-manager.io/cluster-issuer: {{ .Values.ui.certificateIssuer }}
spec:
  ingressClassName: {{ .Values.ui.ingressClassName }}
  tls:
  - hosts:
    - accounts-ui.{{ .Values.ui.domain }}
    secretName: cert-accounts-ui.{{ .Values.ui.domain }}
  rules:
  - host: accounts-ui.{{ .Values.ui.domain }}
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: ui
            port:
              name: http
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ui
  namespace: {{ .Release.Namespace }}
spec:
  selector:
    matchLabels:
      app: ui
  replicas: 1
  template:
    metadata:
      labels:
        app: ui
    spec:
      containers:
      - name: server
        image: {{ .Values.ui.image.repository }}:{{ .Values.ui.image.tag }}
        imagePullPolicy: {{ .Values.ui.image.pullPolicy }}
        env:
        - name: KRATOS_PUBLIC_URL
          value: "https://accounts.{{ .Values.ui.domain }}"
        ports:
        - name: http
          containerPort: 8080
          protocol: TCP
        - name: api
          containerPort: 8081
          protocol: TCP
        command:
        - server
        - --port=8080
        - --kratos=https://accounts.{{ .Values.ui.domain }}
        - --hydra={{ .Values.ui.hydra }}
        - --email-domain={{ .Values.ui.domain }}
        - --api-port=8081
        - --kratos-api=http://kratos-admin.{{ .Release.Namespace }}.svc.cluster.local
        - --enable-registration={{ .Values.ui.enableRegistration }}
