apiVersion: apps/v1
kind: Deployment
metadata:
  name: catalyst-api
  labels:
    app.kubernetes.io/name: catalyst-api
    app.kubernetes.io/component: api
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: catalyst-api
  template:
    metadata:
      labels:
        app.kubernetes.io/name: catalyst-api
    spec:
      imagePullSecrets:
        - name: ghcr-pull-secret
      containers:
        - name: catalyst-api
          image: ghcr.io/openova-io/openova/catalyst-api:2854d65
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8080
              protocol: TCP
          env:
            - name: PORT
              value: "8080"
            - name: CORS_ORIGIN
              value: "https://catalyst.openova.io"
            - name: DYNADOT_API_KEY
              valueFrom:
                secretKeyRef:
                  name: dynadot-api-credentials
                  key: api-key
            - name: DYNADOT_API_SECRET
              valueFrom:
                secretKeyRef:
                  name: dynadot-api-credentials
                  key: api-secret
            # DYNADOT_MANAGED_DOMAINS — comma-separated list of pool domains
            # the same Dynadot account manages. Per docs/INVIOLABLE-PRINCIPLES.md
            # #4, this is runtime configuration so adding a third pool domain
            # (e.g. acme.io) does NOT require a code change — only a secret
            # update. The Dynadot API is account-scoped (one api-key/api-secret
            # pair covers every domain owned by the account); this list scopes
            # which domains the catalyst-api is *allowed* to write records for,
            # defending against misconfiguration that would let a wizard-
            # supplied poolDomain trigger writes against an unrelated domain.
            - name: DYNADOT_MANAGED_DOMAINS
              valueFrom:
                secretKeyRef:
                  name: dynadot-api-credentials
                  key: domains
                  # optional=true so deployments using the legacy single-value
                  # `domain` key (pre-#108) keep working until the secret is
                  # migrated; the dynadot package falls through to DYNADOT_DOMAIN
                  # then to its built-in defaults if neither key is present.
                  optional: true
            - name: DYNADOT_DOMAIN
              valueFrom:
                secretKeyRef:
                  name: dynadot-api-credentials
                  key: domain
                  optional: true
          resources:
            requests:
              cpu: 10m
              memory: 16Mi
            limits:
              cpu: 100m
              memory: 64Mi
          livenessProbe:
            httpGet:
              path: /healthz
              port: 8080
            initialDelaySeconds: 3
            periodSeconds: 10
          readinessProbe:
            httpGet:
              path: /healthz
              port: 8080
            initialDelaySeconds: 2
            periodSeconds: 5
          securityContext:
            allowPrivilegeEscalation: false
            # readOnlyRootFilesystem deliberately false: the bootstrap installer
            # writes kubeconfig temp files (mode 0600) under /tmp and helm
            # downloads chart caches under $HOME. Per Catalyst security policy
            # these writes are scoped via emptyDir below, never to the image's
            # actual root FS.
            readOnlyRootFilesystem: false
            runAsNonRoot: true
            runAsUser: 65534
          volumeMounts:
            - name: tmp
              mountPath: /tmp
            - name: home
              mountPath: /home/nonroot
      volumes:
        - name: tmp
          emptyDir:
            sizeLimit: 256Mi
        - name: home
          emptyDir:
            sizeLimit: 256Mi
