# SPDX-FileCopyrightText: 2021-present Open Networking Foundation <info@opennetworking.org>
#
# SPDX-License-Identifier: Apache-2.0

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "aether-enterprise-portal.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "aether-enterprise-portal.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      name: {{ template "aether-enterprise-portal.fullname" . }}
      app: aether
      type: arg
      resource: {{ template "aether-enterprise-portal.fullname" . }}
      {{- include "aether-enterprise-portal.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        name: {{ template "aether-enterprise-portal.fullname" . }}
        app: aether
        type: arg
        resource: {{ template "aether-enterprise-portal.fullname" . }}
        {{- include "aether-enterprise-portal.selectorLabels" . | nindent 8 }}
    spec:
    {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
    {{- end }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          env:
            - name: NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: OPENIDCISSUER
              value: {{ .Values.openidc.issuer }}
            - name: ONFLOGIN
              valueFrom:
                secretKeyRef:
                  name: aether-enterprise-portal-api
                  key: credentials
          stdin : true
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          ports:
            {{- with .Values.ports }}
            {{- range $key, $port := . }}
            - name: {{ $key }}
              {{ toYaml $port | nindent 14 }}
            {{- end }}
            {{- end }}
          livenessProbe:
            tcpSocket:
              port: web
            initialDelaySeconds: 30
          readinessProbe:
            tcpSocket:
              port: web
            initialDelaySeconds: 30
          volumeMounts:
            - name: config
              mountPath: /etc/nginx/conf.d
            - name: secret
              mountPath: /usr/share/certs
              readOnly: true
      volumes:
        - name: config
          configMap:
            name: {{ template "aether-enterprise-portal.fullname" . }}
        - name: secret
          secret:
            secretName: {{ template "aether-enterprise-portal.fullname" . }}-secret
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
    {{- end }}
