kind: Ingress
{{- if $.Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" }}
apiVersion: networking.k8s.io/v1beta1
{{- else }}
apiVersion: extensions/v1beta1
{{- end }}

metadata:
  name: nova-console
  labels:
    system: openstack
    type: backend
    component: nova
  annotations:
    ingress.kubernetes.io/rewrite-target: /
    {{- if .Values.vice_president }}
    vice-president: "true"
    {{- end }}
spec:
  tls:
  - secretName: tls-{{include "nova_console_endpoint_host_public" . | replace "." "-" }}
    hosts: [{{include "nova_console_endpoint_host_public" .}}]
  rules:
  - host: {{include "nova_console_endpoint_host_public" .}}
    http:
      paths:
      {{- range $name, $config := .Values.consoles }}
      - path: /{{ $name }}
        backend:
          serviceName: nova-console-{{ $name }}
          servicePort: {{ $name }}
      {{- end }}

{{ $envAll := . }}
{{- range $name, $config := .Values.consoles }}
---
{{ tuple $envAll $name $config | include "nova.console_service"  }}
{{- end }}

kind: Ingress
{{- if $.Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" }}
apiVersion: networking.k8s.io/v1beta1
{{- else }}
apiVersion: extensions/v1beta1
{{- end }}

metadata:
  name: nova-console
  labels:
    system: openstack
    type: backend
    component: nova
  annotations:
    ingress.kubernetes.io/use-regex: "true"
    ingress.kubernetes.io/configuration-snippet: |
      {{- range $name, $config := .Values.consoles }}
      rewrite "(?i)/{{ $name }}/(.*)" /$1 break;
      rewrite "(?i)/{{ $name }}$" / break;
      {{- end }}
    {{- if .Values.vice_president }}
    vice-president: "true"
    {{- end }}
spec:
  tls:
  - secretName: tls-{{include "nova_console_endpoint_host_public" . | replace "." "-" }}
    hosts: [{{include "nova_console_endpoint_host_public" .}}]
  rules:
  - host: {{include "nova_console_endpoint_host_public" .}}
    http:
      paths:
      {{- range $name, $config := .Values.consoles }}
      - path: /{{ $name }}/?(.*)
        backend:
          serviceName: nova-console-{{ $name }}
          servicePort: {{ $name }}
      {{- end }}

{{ $envAll := . }}
{{- range $name, $config := .Values.consoles }}
---
{{ tuple $envAll $name $config | include "nova.console_service"  }}
{{- end }}

Use Nginx ingress 0.22 compatible syntax
[nova] Use Nginx ingress 0.22 compatible syntax

Nginx ingress 0.21 is the last Nginx ingress version supporting the old
way of rewriting URLs for nova-console. With all regions already on
0.21, we can start using the syntax available in both 0.21 and 0.22 so
we can update to Nginx ingress 0.22.

The plan is to afterwards change to the new syntax without using
`configuration-snippet`, which is only supported starting with 0.22.
