apiVersion: v1
kind: Namespace
metadata:
  name: container-mom-system
  labels:
    app.kubernetes.io/name: container-mom-operator
    app.kubernetes.io/part-of: container-mom
---
apiVersion: v1
kind: Secret
metadata:
  name: container-mom-secrets
  namespace: container-mom-system
  labels:
    app.kubernetes.io/name: container-mom-operator
    app.kubernetes.io/part-of: container-mom
type: Opaque
data:
  # These will be replaced during deployment
  STRIPE_API_KEY: ""
  CLOUDFLARE_API_TOKEN: ""
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: container-mom-config
  namespace: container-mom-system
  labels:
    app.kubernetes.io/name: container-mom-operator
    app.kubernetes.io/part-of: container-mom
data:
  controller_manager_config.yaml: |
    log_level: info
    cert_issuer:
      name: letsencrypt-prod
      kind: ClusterIssuer
    ingress:
      class_name: nginx
    dns:
      base_domain: container.mom
      provider: cloudflare
    billing:
      stripe:
        webhook_secret: ${STRIPE_WEBHOOK_SECRET}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: container-mom-operator
  namespace: container-mom-system
  labels:
    app.kubernetes.io/name: container-mom-operator
    app.kubernetes.io/part-of: container-mom
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: container-mom-operator
  template:
    metadata:
      labels:
        app.kubernetes.io/name: container-mom-operator
        app.kubernetes.io/part-of: container-mom
    spec:
      serviceAccountName: container-mom-operator
      containers:
      - name: manager
        image: container-mom-operator:latest
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 3000
          name: http
        env:
        - name: KEMAL_ENV
          value: production
        - name: PORT
          value: "3000"
        - name: STRIPE_API_KEY
          valueFrom:
            secretKeyRef:
              name: container-mom-secrets
              key: STRIPE_API_KEY
        - name: CLOUDFLARE_API_TOKEN
          valueFrom:
            secretKeyRef:
              name: container-mom-secrets
              key: CLOUDFLARE_API_TOKEN
        volumeMounts:
        - name: config
          mountPath: /app/config
        resources:
          limits:
            cpu: 500m
            memory: 512Mi
          requests:
            cpu: 100m
            memory: 256Mi
        livenessProbe:
          httpGet:
            path: /health
            port: http
          initialDelaySeconds: 15
          periodSeconds: 20
        readinessProbe:
          httpGet:
            path: /health
            port: http
          initialDelaySeconds: 5
          periodSeconds: 10
      volumes:
      - name: config
        configMap:
          name: container-mom-config
---
apiVersion: v1
kind: Service
metadata:
  name: container-mom-operator
  namespace: container-mom-system
  labels:
    app.kubernetes.io/name: container-mom-operator
    app.kubernetes.io/part-of: container-mom
spec:
  type: ClusterIP
  ports:
  - port: 80
    targetPort: http
    protocol: TCP
    name: http
  selector:
    app.kubernetes.io/name: container-mom-operator
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: container-mom-operator
  namespace: container-mom-system
  labels:
    app.kubernetes.io/name: container-mom-operator
    app.kubernetes.io/part-of: container-mom
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
  ingressClassName: nginx
  tls:
  - hosts:
    - portal.container.mom
    secretName: container-mom-tls
  rules:
  - host: portal.container.mom
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: container-mom-operator
            port:
              name: http
