{% if ingress_type|lower == "ingress" %}
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: '{{ meta.name }}-ingress'
  namespace: '{{ meta.namespace }}'
  labels:
    app.kubernetes.io/name: '{{ meta.name }}'
    app.kubernetes.io/part-of: '{{ meta.name }}'
    app.kubernetes.io/managed-by: '{{ deployment_type }}-operator'
    app.kubernetes.io/component: '{{ deployment_type }}'
    app.kubernetes.io/operator-version: '{{ lookup("env", "OPERATOR_VERSION") }}'
{% if ingress_annotations %}
  annotations:
    {{ ingress_annotations | indent(width=4) }}
{% endif %}
spec:
  rules:
    - host: '{{ hostname }}'
      http:
        paths:
          - path: /
            backend:
              serviceName: '{{ meta.name }}-service'
              servicePort: 80
{% if ingress_tls_secret %}
  tls:
    - hosts:
        - {{ hostname }}
      secretName: {{ ingress_tls_secret }}
{% endif %}
{% endif %}

{% if ingress_type|lower == "route" %}
---
apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: '{{ meta.name }}'
  namespace: '{{ meta.namespace }}'
  labels:
    app.kubernetes.io/name: '{{ meta.name }}'
    app.kubernetes.io/part-of: '{{ meta.name }}'
    app.kubernetes.io/managed-by: '{{ deployment_type }}-operator'
    app.kubernetes.io/component: '{{ deployment_type }}'
    app.kubernetes.io/operator-version: '{{ lookup("env", "OPERATOR_VERSION") }}'
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, indentfirst=True) }}
    certificate: |-
{{ route_tls_crt | indent(width=6, indentfirst=True) }}
{% if route_ca_crt is defined %}
    caCertificate: |-
{{ route_ca_crt | indent(width=6, indentfirst=True) }}
{% endif %}
{% endif %}
  to:
    kind: Service
    name: {{ meta.name }}-service
    weight: 100
  wildcardPolicy: None
{% endif %}
