# Example Caddy Helm Chart

# Chart.yaml
apiVersion: v2
name: caddy
version: 0.1.0

# values.yaml
image:
  repository: caddy
  tag: 2.4.5
replicaCount: 1
port: 80
tls:
  email: your-email@example.com
  enabled: false
  staging: true
ingress:
  enabled: false
  annotations: {}

# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Chart.Name }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ .Chart.Name }}
  template:
    metadata:
      labels:
        app: {{ .Chart.Name }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
          ports:
            - containerPort: {{ .Values.port }}
          args: ["run", "--config", "/etc/caddy/Caddyfile"]
          volumeMounts:
            - name: config
              mountPath: /etc/caddy
      volumes:
        - name: config
          configMap:
            name: {{ .Chart.Name }}-config
      restartPolicy: Always

# service.yaml
apiVersion: v1
kind: Service
metadata:
  name: {{ .Chart.Name }}
spec:
  selector:
    app: {{ .Chart.Name }}
  ports:
    - protocol: TCP
      port: {{ .Values.port }}
      targetPort: {{ .Values.port }}
  type: LoadBalancer

# configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Chart.Name }}-config
data:
  Caddyfile: |
    example.com {
      reverse_proxy /api/* backend.example.com
      reverse_proxy /* frontend.example.com
    }
  tls.json: |
    {
      "email": "{{ .Values.tls.email }}",
      "enabled": {{ .Values.tls.enabled }},
      "staging": {{ .Values.tls.staging }}
    }

# ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ .Chart.Name }}
  annotations: {{ .Values.ingress.annotations }}
spec:
  rules:
    - host: example.com
      http:
        paths:
          - path: /api/*
            backend:
              serviceName: backend
              servicePort: 80
          - path: /*
            backend:
              serviceName: frontend
              servicePort: 80
