# Kubernetes YAML for Podman Kube Play
# Generated by Ansible role: nginx_podman
# Run with: podman kube play {{ nginx_kube_manifest_dest }}

---
# =============================================================================
# ConfigMap - Store nginx configuration
# =============================================================================
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ nginx_app_name }}-config
  labels:
    app: {{ nginx_app_name }}
data:
  nginx.conf: |
{{ lookup('template', 'nginx.conf.j2') | indent(4, first=true) }}
  index.html: |
{{ lookup('template', 'index.html.j2') | indent(4, first=true) }}

---
# =============================================================================
# PersistentVolumeClaim - Request persistent storage
# =============================================================================
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: {{ nginx_app_name }}-data-pvc
  labels:
    app: {{ nginx_app_name }}
spec:
  accessModes:
    - {{ nginx_pvc_access_mode }}
  resources:
    requests:
      storage: {{ nginx_pvc_storage_size }}

---
# =============================================================================
# Pod - Standalone nginx pod
# =============================================================================
apiVersion: v1
kind: Pod
metadata:
  name: {{ nginx_app_name }}
  labels:
    app: {{ nginx_app_name }}
spec:
  containers:
    - name: nginx
      image: {{ nginx_image }}
      ports:
        - containerPort: {{ nginx_container_port }}
          hostPort: {{ nginx_host_port }}
      volumeMounts:
        - name: config-volume
          mountPath: /etc/nginx/nginx.conf
          subPath: nginx.conf
        - name: html-volume
          mountPath: /usr/share/nginx/html/index.html
          subPath: index.html
        - name: data-volume
          mountPath: /var/log/nginx
      resources:
        limits:
          memory: "{{ nginx_memory_limit }}"
          cpu: "{{ nginx_cpu_limit }}"
        requests:
          memory: "{{ nginx_memory_request }}"
          cpu: "{{ nginx_cpu_request }}"
      livenessProbe:
        httpGet:
          path: {{ nginx_health_path }}
          port: {{ nginx_container_port }}
        initialDelaySeconds: {{ nginx_liveness_initial_delay }}
        periodSeconds: {{ nginx_liveness_period }}
      readinessProbe:
        httpGet:
          path: {{ nginx_health_path }}
          port: {{ nginx_container_port }}
        initialDelaySeconds: {{ nginx_readiness_initial_delay }}
        periodSeconds: {{ nginx_readiness_period }}
  volumes:
    - name: config-volume
      configMap:
        name: {{ nginx_app_name }}-config
    - name: html-volume
      configMap:
        name: {{ nginx_app_name }}-config
    - name: data-volume
      persistentVolumeClaim:
        claimName: {{ nginx_app_name }}-data-pvc
  restartPolicy: Always
