# helm_charts_ambassador-pro-service.yaml
{{ if and .Values.pro.enabled (not .Values.crds.enabled) }}
---
apiVersion: v1
kind: Service
metadata:
  name: {{ include "ambassador.fullname" . }}-pro
  labels:
    service: ambassador-pro
    app.kubernetes.io/name: {{ include "ambassador.name" . }}
    app.kubernetes.io/part-of: {{ .Release.Name }}
    helm.sh/chart: {{ include "ambassador.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    {{- if .Values.extraLabels }}
      {{- toYaml .Values.extraLabels | nindent 4 }}
    {{- end }}
  annotations:
    getambassador.io/config: |
      {{- if .Values.pro.authService.enabled }}
      ---
      apiVersion: ambassador/v1
      kind: AuthService
      name: {{ include "ambassador.fullname" . }}-pro-auth
      proto: grpc
      {{- if hasKey .Values.env "AMBASSADOR_ID" }}
      ambassador_id: {{ .Values.env.AMBASSADOR_ID | quote }}
      {{- end }}
      auth_service: 127.0.0.1:{{ .Values.pro.ports.auth }}
      {{- toYaml .Values.pro.authService.optional_configurations | nindent 6}}
      ---
      # This mapping needs to exist, but is never actually followed.
      apiVersion: ambassador/v1
      kind: Mapping
      name: {{ include "ambassador.fullname" . }}-pro-callback_mapping
      {{- if hasKey .Values.env "AMBASSADOR_ID" }}
      ambassador_id: {{ .Values.env.AMBASSADOR_ID | quote }}
      {{- end }}
      prefix: /callback
      service: NoTaReAlSeRvIcE
      {{- end }}
      {{- if .Values.pro.rateLimit.enabled }}
      ---
      apiVersion: ambassador/v1
      kind: RateLimitService
      name: {{ include "ambassador.fullname" . }}-pro-ratelimit
      {{- if hasKey .Values.env "AMBASSADOR_ID" }}
      ambassador_id: {{ .Values.env.AMBASSADOR_ID | quote }}
      {{- end }}
      service: 127.0.0.1:{{ .Values.pro.ports.ratelimit }}
      {{- end }}
      {{- if .Values.pro.devPortal.enabled }}
      ---
      apiVersion: ambassador/v1
      kind: Mapping
      name: {{ include "ambassador.fullname" . }}-pro-devportal
      {{- if hasKey .Values.env "AMBASSADOR_ID" }}
      ambassador_id: {{ .Values.env.AMBASSADOR_ID | quote }}
      {{- end }}
      prefix: /docs/
      rewrite: ""
      service: 127.0.0.1:{{ .Values.pro.ports.auth }}
      ---
      apiVersion: ambassador/v1
      kind: Mapping
      name: {{ include "ambassador.fullname" . }}-pro-devportal-api
      {{- if hasKey .Values.env "AMBASSADOR_ID" }}
      ambassador_id: {{ .Values.env.AMBASSADOR_ID | quote }}
      {{- end }}
      prefix: /openapi/
      rewrite: ""
      service: 127.0.0.1:{{ .Values.pro.ports.auth }}
      {{- end }}
spec:
  ports:
  - name: http
    port: 80
{{ end }}