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

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

namePrefix: healthchecks-
resources:
  - ../../../kustomize/public-oidc/

replacements:
  - source:
      kind: Service
      name: svc
    targets:
      - select:
          kind: HTTPRoute
        options:
          create: true
        fieldPaths:
          - spec.rules.0.backendRefs.0.name
  - source:
      kind: Deployment
      name: app
      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
      name: app
      fieldPath: metadata.labels.[app.kubernetes.io/appNamespace]
    targets:
      - select:
          kind: InfisicalSecret
        fieldPaths:
          - spec.managedSecretReference.secretNamespace
      - select:
          kind: InfisicalSecret
        options:
          delimiter: "/"
          index: 1
        fieldPaths:
          - spec.authentication.universalAuth.secretsScope.secretsPath

patches:
  - path: patches/deployment.yaml
    target:
      kind: Deployment
      name: app
  - path: patches/delete-pvc.yaml
    target:
      kind: PersistentVolumeClaim
      name: pvc

labels:
  - includeSelectors: true
    pairs:
      app.kubernetes.io/appName: healthchecks
  - pairs:
      app.kubernetes.io/appNamespace: monitoring

configMapGenerator:
  - name: config
    literals:
      - ADMINS=jonathan@leechpepin.com
      - DB=postgres
      - DB_HOST=postgres-svc.core.svc.cluster.local
      - DB_NAME=hc
      - DB_PORT=5432
      - DB_USER=hc
      - DEFAULT_FROM_EMAIL=homelab@leechpepin.com
      - EMAIL_HOST=blizzard.mxrouting.net
      - EMAIL_HOST_USER=homelab@leechpepin.com
      - EMAIL_PORT=465
      - EMAIL_USE_SSL=True
      - EMAIL_USE_TLS=False
      - INTEGRATION_ALLOW_PRIVATE_IPS=True
      - SITE_NAME=JLP Healthchecks
      - SITE_ROOT=https://healthchecks.leechpepin.com
      - DEBUG=False
      - REGISTRATION_OPEN=False