---
apiVersion: v1
kind: Service
metadata:
  name: '{{ meta.name }}-service'
  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") }}'
    {{ service_labels | indent(width=4) }}
{% if service_type | lower == 'loadbalancer' and loadbalancer_annotations %}
  annotations:
    {{ loadbalancer_annotations | indent(width=4) }}
{% endif %}
spec:
  ports:
{% if service_type | lower != 'loadbalancer' and loadbalancer_protocol | lower != 'https' %}
    - port: 80
      protocol: TCP
      targetPort: 8052
      name: http
{% endif %}
{% if ingress_type | lower == 'route' and route_tls_termination_mechanism | lower == 'passthrough' %}
    - port: 443
      protocol: TCP
      targetPort: 8053
      name: https
{% endif %}
{% if service_type | lower == 'loadbalancer' and loadbalancer_protocol | lower == 'https' %}
    - port: {{ loadbalancer_port }}
      protocol: TCP
      targetPort: 8052
      name: https
{% elif service_type | lower == 'loadbalancer' and loadbalancer_protocol | lower != 'https' %}
    - port: {{ loadbalancer_port }}
      protocol: TCP
      targetPort: 8052
      name: http
{% endif %}
  selector:
    app.kubernetes.io/name: '{{ meta.name }}'
    app.kubernetes.io/managed-by: '{{ deployment_type }}-operator'
    app.kubernetes.io/component: '{{ deployment_type }}'
{% if service_type | lower == "loadbalancer" %}
  type: LoadBalancer
{% elif service_type | lower == "nodeport" %}
  type: NodePort
{% else %}
  type: ClusterIP
{% endif %}
