---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Chart.Name }}-{{ .Values.search.serviceName }}
spec:
  selector:
    matchLabels:
      run: {{ .Chart.Name }}-{{ .Values.search.serviceName }}
  replicas: {{ default 1 .Values.search.replicas }}
  template:
    metadata:
      labels:
        run: {{ .Chart.Name }}-{{ .Values.search.serviceName }}
    spec:
      {{- with default .Values.nodeSelector .Values.search.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
      {{- end }}
      {{- with default .Values.affinity .Values.search.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
      {{- end }}
      {{- with default .Values.tolerations .Values.search.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
      {{- end }}
      containers:
      - name: {{ .Chart.Name }}-{{ .Values.search.serviceName }}
        image: {{ .Values.dockerhubImagePath }}/{{ .Chart.Name }}-{{ .Values.search.serviceName }}:{{ .Values.search.imageVersion }}
        ports:
        - containerPort: 5000  
        env:
        - name: PROXY_ENDPOINT
          value: {{ if .Values.search.elasticsearchEndpoint }}{{ .Values.search.elasticsearchEndpoint }}{{ else }}{{ .Release.Namespace }}-elasticsearch-client.{{ .Release.Namespace }}.svc.cluster.local{{ end }}
        {{- with .Values.search.resources }}
        resources:
{{ toYaml . | indent 10 }}
        {{- end }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Chart.Name }}-{{ .Values.metadata.serviceName }}
spec:
  selector:
    matchLabels:
      run: {{ .Chart.Name }}-{{ .Values.metadata.serviceName }}
  replicas: {{ default 1 .Values.metadataReplicas }}
  template:
    metadata:
      labels:
        run: {{ .Chart.Name }}-{{ .Values.metadata.serviceName }}
    spec:
      {{- with default .Values.nodeSelector .Values.metadata.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
      {{- end }}
      {{- with default .Values.affinity .Values.metadata.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
      {{- end }}
      {{- with default .Values.tolerations .Values.metadata.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
      {{- end }}
      volumes:
      {{- if .Values.frontEnd.oidcEnabled }}
        - name: oidc-config
          secret:
            secretName: oidc-config
      {{- end }}
      containers:
      - name: {{ .Chart.Name }}-{{ .Values.metadata.serviceName }}
        {{- with .Values.metadataServiceImage }}
        image: {{ . }}
        {{- else }}
        image: {{ .Values.dockerhubImagePath }}/{{ .Chart.Name }}-{{ .Values.metadata.serviceName }}{{ if .Values.frontEnd.oidcEnabled }}-oidc{{ end }}:{{ .Values.metadata.imageVersion }}
        {{- end }}
        ports:
        - containerPort: 5000
        env:
        - name: PROXY_HOST
          value: {{ if .Values.metadata.neo4jEndpoint }}{{ .Values.metadata.neo4jEndpoint }}{{ else }}bolt://neo4j.{{ .Release.Namespace }}.svc.cluster.local{{ end }}
        {{- if .Values.frontEnd.oidcEnabled }}
        - name: FLASK_OIDC_CLIENT_SECRETS
          value: /etc/client_secrets.json
        - name: FLASK_OIDC_SECRET_KEY
          valueFrom:
            secretKeyRef:
              name: oidc-config
              key: OIDC_CLIENT_SECRET
        {{- end }}
        volumeMounts:
        {{- if .Values.frontEnd.oidcEnabled }}
          - name: oidc-config
            mountPath: /etc/client_secrets.json
            subPath: client_secrets.json
        {{- end }}
        {{- with .Values.metadata.resources }}
        resources:
{{ toYaml . | indent 10 }}
        {{- end }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Chart.Name }}-{{ .Values.frontEnd.serviceName }}
spec:
  selector:
    matchLabels:
      run: {{ .Chart.Name }}-{{ .Values.frontEnd.serviceName }}
  replicas: {{ default 1 .Values.frontEnd.replicas }}
  template:
    metadata:
      labels:
        run: {{ .Chart.Name }}-{{ .Values.frontEnd.serviceName }}
    spec:
      {{- with default .Values.nodeSelector .Values.frontEnd.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
      {{- end }}
      {{- with default .Values.affinity .Values.frontEnd.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
      {{- end }}
      {{- with default .Values.tolerations .Values.frontEnd.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
      {{- end }}
      volumes:
      {{- if .Values.frontEnd.oidcEnabled }}
        - name: oidc-config
          secret:
            secretName: oidc-config
      {{- end }}
      containers:
      - name: {{ .Chart.Name }}-{{ .Values.frontEnd.serviceName }}
        {{- with .Values.frontEnd.serviceImage }}
        image: {{ . }}
        {{- else }}
        image: {{ .Values.dockerhubImagePath }}/{{ .Chart.Name }}-{{ .Values.frontEnd.serviceName }}{{ if .Values.frontEnd.oidcEnabled }}-oidc{{ end }}:{{ .Values.frontEnd.imageVersion }}
        {{- end }}
        ports:
          - containerPort: 5000
        env:
          # FRONTEND_BASE is used by notifications util to provide links to amundsen pages in emails. If its not set, it will default to localhost.
          {{ if .Values.frontEnd.FRONTEND_BASE }}
          - name: FRONTEND_BASE
            value: http://{{ .Values.frontEnd.FRONTEND_BASE }}
          {{ end }}
          - name: SEARCHSERVICE_BASE
            value: http://{{ .Chart.Name }}-{{ .Values.search.serviceName }}:5001
          - name: METADATASERVICE_BASE
            value: http://{{ .Chart.Name }}-{{ .Values.metadata.serviceName }}:5002
          - name: LONG_RANDOM_STRING
            value: {{ quote .Values.LONG_RANDOM_STRING }}
        {{- if .Values.frontEnd.oidcEnabled }}
          - name: FLASK_OIDC_CLIENT_SECRETS
            value: /etc/client_secrets.json
          - name: FLASK_OIDC_SECRET_KEY
            valueFrom:
              secretKeyRef:
                name: oidc-config
                key: OIDC_CLIENT_SECRET
        {{- end }}
        volumeMounts:
        {{- if .Values.frontEnd.oidcEnabled }}
          - name: oidc-config
            mountPath: /etc/client_secrets.json
            subPath: client_secrets.json
        {{- end }}
