---
apiVersion: batch/v1
kind: Job
metadata:
  name: reset-oidc-config
spec:
  template:
    spec:
      volumes:
        - name: tmp
          emptyDir: {}
      initContainers:
        - name: jq
          image: alpine/k8s:1.24.16@sha256:06f8942d87fa17b40795bb9a8eff029a9be3fc3c9bcc13d62071de4cc3324153
          imagePullPolicy: IfNotPresent
          volumeMounts:
            - mountPath: /tmp
              name: tmp
          envFrom:
            - secretRef:
                name: oidc-client-wiki-owner-secrets
          command:
            - /bin/bash
            - -c
            - jq '{"strategyKey":"oidc","config":{"clientId":$ENV.OIDC_CLIENT_ID,"clientSecret":$ENV.OIDC_CLIENT_SECRET,"authorizationURL":$ENV.OIDC_GATEWAY_AUTH_URI,"tokenURL":$ENV.OIDC_GATEWAY_TOKEN_URI,"userInfoURL":$ENV.OIDC_GATEWAY_USERINFO_URI,"skipUserProfile":false,"issuer":$ENV.OIDC_GATEWAY_URI,"emailClaim":"email","displayNameClaim":"name","mapGroups":false,"groupsClaim":"groups","logoutURL":$ENV.OIDC_GATEWAY_URI,"acrValues":""}} | "UPDATE authentication SET config=\(.config|tostring|@sh) WHERE strategyKey=\(.strategyKey|tostring|@sh) LIMIT 1"' -n -r > /tmp/update.sql
      containers:
        - name: mysql
          image: mysql
          imagePullPolicy: IfNotPresent
          volumeMounts:
            - mountPath: /tmp
              name: tmp
          env:
            - name: MYSQL_PWD
              valueFrom:
                secretKeyRef:
                  name: wikijs-secrets
                  key: DB_PASS
          command:
            - /bin/bash
            - -c
            - mysql -u kspace_wiki kspace_wiki -h 172.20.36.1 -p${MYSQL_PWD} < /tmp/update.sql
      restartPolicy: OnFailure
  backoffLimit: 4