{{- if .Values.ingress.enabled -}}
{{- $fullName := include "openstack-api-simulator.fullname" . -}}
{{- $gatewayEnabled := .Values.gateway.enabled -}}
{{- $svcName := ternary (printf "%s-gateway" $fullName) $fullName $gatewayEnabled -}}
{{- $svcPort := ternary 5000 .Values.service.port $gatewayEnabled -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ $fullName }}
  labels:
    {{- include "openstack-api-simulator.labels" . | nindent 4 }}
  annotations:
    {{- if .Values.certManager.enabled }}
    cert-manager.io/cluster-issuer: {{ include "openstack-api-simulator.clusterIssuer" . | quote }}
    {{- end }}
    {{- with .Values.ingress.annotations }}
    {{- toYaml . | nindent 4 }}
    {{- end }}
spec:
  {{- with .Values.ingress.className }}
  ingressClassName: {{ . }}
  {{- end }}
  {{- if .Values.ingress.tls }}
  tls:
    {{- range .Values.ingress.tls }}
    - hosts:
        {{- range .hosts }}
        - {{ . | quote }}
        {{- end }}
      secretName: {{ .secretName }}
    {{- end }}
  {{- end }}
  rules:
    {{- range .Values.ingress.hosts }}
    - host: {{ .host | quote }}
      http:
        paths:
          {{- range .paths }}
          - path: {{ .path }}
            pathType: {{ .pathType }}
            backend:
              service:
                name: {{ $svcName }}
                port:
                  number: {{ $svcPort }}
          {{- end }}
    {{- end }}
{{- end }}
