# services/keycloak/bootstrap-jobs/hermes-dashboard-oidc-client-job.yaml
# Purpose: ensure the Hermes dashboard public OIDC client exists in Keycloak.
# Bump the suffix if the immutable Job needs to be rerun after it completes.
apiVersion: batch/v1
kind: Job
metadata:
  name: hermes-dashboard-oidc-client-ensure-1
  namespace: sso
spec:
  backoffLimit: 3
  template:
    metadata:
      annotations:
        vault.hashicorp.com/agent-inject: "true"
        vault.hashicorp.com/agent-pre-populate-only: "true"
        vault.hashicorp.com/role: "sso-secrets"
        vault.hashicorp.com/agent-inject-secret-keycloak-admin-env.sh: "kv/data/atlas/shared/keycloak-admin"
        vault.hashicorp.com/agent-inject-template-keycloak-admin-env.sh: |
          {{ with secret "kv/data/atlas/shared/keycloak-admin" }}
          export KEYCLOAK_ADMIN="{{ .Data.data.username }}"
          export KEYCLOAK_ADMIN_USER="{{ .Data.data.username }}"
          export KEYCLOAK_ADMIN_PASSWORD="{{ .Data.data.password }}"
          {{ end }}
    spec:
      serviceAccountName: mas-secrets-ensure
      restartPolicy: Never
      volumes:
        - name: hermes-dashboard-oidc-client-script
          configMap:
            name: hermes-dashboard-oidc-client-script
            defaultMode: 0555
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: kubernetes.io/arch
                    operator: In
                    values: ["arm64"]
                  - key: node-role.kubernetes.io/worker
                    operator: Exists
      containers:
        - name: apply
          image: bitnami/kubectl@sha256:554ab88b1858e8424c55de37ad417b16f2a0e65d1607aa0f3fe3ce9b9f10b131
          command: ["/scripts/hermes_dashboard_oidc_client_ensure.sh"]
          volumeMounts:
            - name: hermes-dashboard-oidc-client-script
              mountPath: /scripts
              readOnly: true
