---
# Frontend Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
  name: frontend
  namespace: dating-app
  labels:
    app: frontend
spec:
  replicas: {{ .Values.frontend.replicas }}
  selector:
    matchLabels:
      app: frontend
  template:
    metadata:
      labels:
        app: frontend
    spec:
      containers:
      - name: frontend
        image: {{ .Values.frontend.image.repository }}:{{ .Values.frontend.image.tag }}
        imagePullPolicy: {{ .Values.frontend.image.pullPolicy }}
        ports:
        - containerPort: {{ .Values.frontend.service.targetPort }}
          name: http
        envFrom:
        - configMapRef:
            name: frontend-config
        resources:
          requests:
            memory: {{ .Values.frontend.resources.requests.memory }}
            cpu: {{ .Values.frontend.resources.requests.cpu }}
          limits:
            memory: {{ .Values.frontend.resources.limits.memory }}
            cpu: {{ .Values.frontend.resources.limits.cpu }}
        {{- if .Values.frontend.probes.readiness.enabled }}
        readinessProbe:
          httpGet:
            path: {{ .Values.frontend.probes.readiness.path }}
            port: {{ .Values.frontend.service.targetPort }}
          initialDelaySeconds: {{ .Values.frontend.probes.readiness.initialDelaySeconds }}
          periodSeconds: {{ .Values.frontend.probes.readiness.periodSeconds }}
        {{- end }}
        {{- if .Values.frontend.probes.liveness.enabled }}
        livenessProbe:
          httpGet:
            path: {{ .Values.frontend.probes.liveness.path }}
            port: {{ .Values.frontend.service.targetPort }}
          initialDelaySeconds: {{ .Values.frontend.probes.liveness.initialDelaySeconds }}
          periodSeconds: {{ .Values.frontend.probes.liveness.periodSeconds }}
        {{- end }}

---
# Frontend Service
apiVersion: v1
kind: Service
metadata:
  name: frontend
  namespace: dating-app
  labels:
    app: frontend
spec:
  type: {{ .Values.frontend.service.type }}
  selector:
    app: frontend
  ports:
  - port: {{ .Values.frontend.service.port }}
    targetPort: {{ .Values.frontend.service.targetPort }}
    protocol: TCP
    name: http
