# Kubernetes Service Specification template
# Renders form data into a Nickel service definition

{
  # Service Metadata
  metadata = {
    name | doc "Service name" : String = "{{ service_name }}",
    {%- if service_namespace is defined %}
    namespace | doc "Kubernetes namespace" : String = "{{ service_namespace }}",
    {%- else %}
    namespace : String = "default",
    {%- endif %}
    {%- if service_labels is defined %}
    labels = {
      app | doc "Application label" : String = "{{ service_labels }}",
    },
    {%- endif %}
  },

  # Service Specification
  spec = {
    type | doc "Service type (ClusterIP, NodePort, LoadBalancer)" : String = "{{ service_type | default('ClusterIP') }}",

    # Selector for matching pods
    selector = {
      app | doc "App selector" : String = "{{ service_app | default(service_name) }}",
    },

    # Port configuration
    ports = [
      {
        name | doc "Port name" : String = "{{ port_name | default('http') }}",
        protocol | doc "Protocol (TCP, UDP)" : String = "TCP",
        port | doc "Service port" : Number = {{ service_port | default(80) }},
        targetPort | doc "Target container port" : Number = {{ target_port | default(8080) }},
        {%- if node_port is defined %}
        nodePort | doc "Node port (for NodePort service)" : Number = {{ node_port }},
        {%- endif %}
      },
    ],

    {%- if session_affinity is defined %}
    # Session Affinity
    sessionAffinity | doc "Session affinity type" : String = "{{ session_affinity }}",
    {%- endif %}

    {%- if external_ips is defined %}
    # External IPs
    externalIPs = [
      "{{ external_ips }}",
    ],
    {%- endif %}
  },
}
