{{- define "ingress.install" -}}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: kibana-main
  namespace: {{ .Values.logging.namespace | default "btrix-admin" }}
  annotations:
    kubernetes.io/ingress.class: "{{ .Values.logging.ingress.class | default "nginx" }}"
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/enable-cors: "true"
    nginx.ingress.kubernetes.io/cors-allow-origin: "*"
    {{ if .Values.logging.ingress.tls }}
    cert-manager.io/cluster-issuer: "cert-main"
    {{ end }}
    nginx.ingress.kubernetes.io/proxy-connect-timeout: "30"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "1800"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "1800"
    nginx.ingress.kubernetes.io/upstream-vhost: "{{ .Values.logging.ingress.host | default "localhost" }}"
    nginx.ingress.kubernetes.io/backend-protocol: "https"
    nginx.ingress.kubernetes.io/configuration-snippet: |
      proxy_set_header X-Forwarded-Proto "https";
spec:
  {{ if .Values.logging.ingress.tls }}
  tls:
    - hosts:
      - {{ .Values.logging.ingress.host | default "localhost" }}
      secretName: cert-main
  {{ end }}
  rules:
  - host: {{ .Values.logging.ingress.host | default "localhost" }}
    http:
      paths:
      - path: {{ .Values.logging.ingress.path | default "/kibana" }}/(.*)
        pathType: Prefix
        backend:
          service:
            name: btrixlog-kb-http
            port:
              number: 5601
{{- end -}}
