---
# Kubernetes Deployment generated by Vibe Infra
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ name }}
  namespace: {{ namespace }}
  {% if labels %}
  labels:
    {% for key, value in labels.items() %}
    {{ key }}: {{ value }}
    {% endfor %}
    managed-by: athena
  {% endif %}
spec:
  replicas: {{ spec.get('replicas', 1) }}
  selector:
    matchLabels:
      app: {{ name }}
      {% for key, value in labels.items() %}
      {{ key }}: {{ value }}
      {% endfor %}
  template:
    metadata:
      labels:
        app: {{ name }}
        {% for key, value in labels.items() %}
        {{ key }}: {{ value }}
        {% endfor %}
    spec:
      containers:
      - name: {{ name }}
        image: {{ spec.get('image', 'nginx:latest') }}
        {% if spec.get('ports') %}
        ports:
        {% for port in spec.ports %}
        - containerPort: {{ port }}
        {% endfor %}
        {% endif %}
        {% if spec.get('env') %}
        env:
        {% for env_var in spec.env %}
        - name: {{ env_var.name }}
          value: "{{ env_var.value }}"
        {% endfor %}
        {% endif %}
        {% if spec.get('resources') %}
        resources:
          {% if spec.resources.get('limits') %}
          limits:
            {% for key, value in spec.resources.limits.items() %}
            {{ key }}: {{ value }}
            {% endfor %}
          {% endif %}
          {% if spec.resources.get('requests') %}
          requests:
            {% for key, value in spec.resources.requests.items() %}
            {{ key }}: {{ value }}
            {% endfor %}
          {% endif %}
        {% endif %}
