{{- if .Values.ingress.enabled }}
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
  name: axon-strip-prefix
  labels:
    {{- include "axon.labels" . | nindent 4 }}
spec:
  stripPrefix:
    prefixes:
      - {{ .Values.ingress.path }}
---
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
  name: axon-redirect-https
  labels:
    {{- include "axon.labels" . | nindent 4 }}
spec:
  redirectScheme:
    scheme: https
    permanent: true
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: axon
  labels:
    {{- include "axon.labels" . | nindent 4 }}
  annotations:
    cert-manager.io/cluster-issuer: {{ .Values.ingress.tls.clusterIssuer }}
    traefik.ingress.kubernetes.io/router.middlewares: {{ .Release.Namespace }}-axon-strip-prefix@kubernetescrd,{{ .Release.Namespace }}-axon-redirect-https@kubernetescrd
spec:
  ingressClassName: {{ .Values.ingress.className }}
  {{- if .Values.ingress.tls.enabled }}
  tls:
    - hosts:
        - {{ .Values.ingress.host }}
      secretName: {{ .Values.ingress.tls.secretName }}
  {{- end }}
  rules:
    - host: {{ .Values.ingress.host }}
      http:
        paths:
          - path: {{ .Values.ingress.path }}
            pathType: Prefix
            backend:
              service:
                name: axon
                port:
                  number: 80
{{- end }}
