apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

transformers:
  - |-
    apiVersion: builtin
    kind: NamespaceTransformer
    metadata:
      name: notImportantHere
      namespace: apps
    unsetOnly: true

namePrefix: mealie-
resources:
  - ../../../kustomize/bases/public-oidc/
  - extra/gatus-endpoints.yaml

replacements:
  - source:
      kind: Service
      name: svc
    targets:
      - select:
          kind: HTTPRoute
        options:
          create: true
        fieldPaths:
          - spec.rules.0.backendRefs.0.name
  - source:
      kind: Deployment
      fieldPath: metadata.labels.[app.kubernetes.io/appName]
    targets:
      - select:
          kind: HTTPRoute
        options:
          create: true
          delimiter: "."
          index: 0
        fieldPaths:
          - spec.hostnames.0
      - select:
          kind: InfisicalSecret
        options:
          delimiter: "-"
          index: 0
        fieldPaths:
          - spec.managedSecretReference.secretName
      - select:
          kind: InfisicalSecret
        options:
          delimiter: "/"
          index: 2
        fieldPaths:
          - spec.authentication.universalAuth.secretsScope.secretsPath
      - select:
          kind: Service
        fieldPaths:
          - spec.ports.0.name
          - spec.ports.0.targetPort
  - source:
      kind: Deployment
      fieldPath: metadata.labels.[app.kubernetes.io/appNamespace]
    targets:
      - select:
          kind: InfisicalSecret
        fieldPaths:
          - spec.managedSecretReference.secretNamespace

patches:
  - path: patches/deployment.yaml
    target:
      kind: Deployment

labels:
  - includeSelectors: true
    pairs:
      app.kubernetes.io/appName: mealie
  - pairs:
      app.kubernetes.io/appNamespace: apps

configMapGenerator:
  - name: config
    literals:
      - ALLOW_SIGNUP="false"
      - PUID=1000
      - PGID=1000
      - TZ=America/New_York
      - BASE_URL=https://mealie.leechpepin.com
      # Database Settings
      - DB_ENGINE=postgres
      - POSTGRES_USER=mealie
      - POSTGRES_SERVER=postgres-svc.core.svc.cluster.local
      - POSTGRES_PORT=5432
      - POSTGRES_DB=mealie
      # Use Ollama
      - OPENAI_BASE_URL=https://ollama.leechpepin.com:11434/v1
      - OPENAI_MODEL=llama3.2:latest
      - OPENAI_API_KEY=gibberish
      # Use Authentik OIDC
      - OIDC_AUTH_ENABLED=true
      - OIDC_CONFIGURATION_URL=https://auth.leechpepin.com/application/o/mealie/.well-known/openid-configuration
      - OIDC_CLIENT_ID=tkLxhniR4IluqtYhMU4tz1vOUzS71kwxFr5gui7m
      - OIDC_AUTO_REDIRECT=true
      - OIDC_PROVIDER_NAME=Authentik
      - OIDC_REMEMBER_ME=true