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

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

namePrefix: dolibarr-
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
  - path: patches/pvc.yaml
    target:
      kind: PersistentVolumeClaim

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

configMapGenerator:
  - name: config
    literals:
      - PHP_INI_DATE_TIMEZONE=America/New_York
      - DOLI_INSTALL_AUTO=0
      - DOLI_DB_TYPE=pgsql
      - DOLI_DB_HOST=postgres-svc.core.svc.cluster.local
      - DOLI_DB_HOST_PORT=5432
      - DOLI_DB_USER=dolidbuser
      - DOLI_COMPANY_NAME="JLP Tech Consulting, LLC"
      - DOLI_COMPANY_COUNTRYCODE="US"
      - DOLI_URL_ROOT=https://dolibarr.leechpepin.com