Files
awx-operator/roles/installer/templates/networking/ingress.yaml.j2
Guillaume Lefevre 07427be0b7 Allow multiple ingress hosts to be defined when using ingress (#1377)
* Replace api version for deployment kind to apps/v1

* Add new multiple ingress spec and deprecate hostname and ingress_tls_secret

* Manage new ingress_hosts.tls_secret backup separately

* Fix ci molecule lint warnings and error

* Fix documentation

* Fix ingress_hosts tls_secret key being optional

* Remove fieldDependency:ingress_type:Ingress for Ingress Hosts

* Fix scenario when neither hostname or ingress_hosts is defined

---------

Co-authored-by: Guillaume Lefevre <guillaume.lefevre@agoda.com>
Co-authored-by: Seth Foster <fosterseth@users.noreply.github.com>
Co-authored-by: Christian Adams <chadams@redhat.com>
2024-01-05 10:15:04 -05:00

125 lines
3.6 KiB
Django/Jinja

{% if ingress_type|lower == "ingress" %}
---
{% if ingress_api_version is defined %}
apiVersion: '{{ ingress_api_version }}'
{% endif %}
kind: Ingress
metadata:
name: '{{ ansible_operator_meta.name }}-ingress'
namespace: '{{ ansible_operator_meta.namespace }}'
labels:
{{ lookup("template", "../common/templates/labels/common.yaml.j2") | indent(width=4) | trim }}
{% if ingress_annotations or ingress_controller|lower == "contour" %}
annotations:
{% if ingress_annotations %}
{{ ingress_annotations | indent(width=4) }}
{%- endif %}
{% if ingress_controller|lower == "contour" %}
projectcontour.io/websocket-routes: "/websocket"
kubernetes.io/ingress.class: contour
{% endif %}
{% endif %}
spec:
{% if ingress_class_name %}
ingressClassName: '{{ ingress_class_name }}'
{% endif %}
rules:
{% if not ingress_hosts %}
- http:
paths:
- path: '{{ ingress_path }}'
pathType: '{{ ingress_path_type }}'
backend:
service:
name: '{{ ansible_operator_meta.name }}-service'
port:
number: 80
{% if hostname %}
host: {{ hostname }}
{% endif %}
{% if ingress_controller|lower == "contour" %}
- path: '{{ ingress_path.rstrip("/") }}/websocket'
pathType: '{{ ingress_path_type }}'
backend:
service:
name: '{{ ansible_operator_meta.name }}-service'
port:
number: 80
{% endif %}
{% if ingress_tls_secret %}
tls:
- hosts:
- {{ hostname }}
secretName: {{ ingress_tls_secret }}
{% endif %}
{% endif %}
{% if ingress_hosts %}
{% for item in ingress_hosts %}
- host: {{ item.hostname }}
http:
paths:
- path: '{{ ingress_path }}'
pathType: '{{ ingress_path_type }}'
backend:
service:
name: '{{ ansible_operator_meta.name }}-service'
port:
number: 80
{% if ingress_controller|lower == "contour" %}
- path: '{{ ingress_path.rstrip("/") }}/websocket'
pathType: '{{ ingress_path_type }}'
backend:
service:
name: '{{ ansible_operator_meta.name }}-service'
port:
number: 80
{% endif %}
{% endfor %}
tls:
{% for item in ingress_hosts %}
{% if 'tls_secret' in item %}
- hosts:
- {{ item.hostname }}
secretName: {{ item.tls_secret }}
{% endif %}
{% endfor %}
{% endif %}
{% endif %}
{% if ingress_type|lower == "route" %}
---
{% if route_api_version is defined %}
apiVersion: '{{ route_api_version }}'
{% endif %}
kind: Route
metadata:
name: '{{ ansible_operator_meta.name }}'
namespace: '{{ ansible_operator_meta.namespace }}'
labels:
{{ lookup("template", "../common/templates/labels/common.yaml.j2") | indent(width=4) | trim }}
spec:
{% if route_host != '' %}
host: {{ route_host }}
{% endif %}
port:
targetPort: '{{ (route_tls_termination_mechanism | lower == "passthrough") | ternary("https", "http") }}'
tls:
insecureEdgeTerminationPolicy: Redirect
termination: {{ route_tls_termination_mechanism | lower }}
{% if route_tls_termination_mechanism | lower == 'edge' and route_tls_secret != '' %}
key: |-
{{ route_tls_key | indent(width=6, first=True) }}
certificate: |-
{{ route_tls_crt | indent(width=6, first=True) }}
{% if route_ca_crt is defined %}
caCertificate: |-
{{ route_ca_crt | indent(width=6, first=True) }}
{% endif %}
{% endif %}
to:
kind: Service
name: {{ ansible_operator_meta.name }}-service
weight: 100
wildcardPolicy: None
{% endif %}