docker-alerta
docker-alerta copied to clipboard
ERROR: duplicate key value violates unique constraint "keys_key_key"
Issue Summary
Alerta container fails to start (when restarted/redeployed) due to error:
# Create user-defined admin API key.
ERROR: duplicate key value violates unique constraint "keys_key_key"
DETAIL: Key (key)=(*********secret*********) already exists.
Environment
-
OS: container image alerta/alerta-web:8.7.0
-
Deployment: Helm Chart deployment to Kubernetes
-
For self-hosted, WSGI environment: nginx/uwsgi
-
Database: Postgres, separate data persistent instance, outside of Alerta POD
-
Server config: Auth enabled? Yes Auth provider? Basic Customer views? Yes
-
web UI version: 8.7.0
-
CLI version: 8.7.0
To Reproduce Steps to reproduce the behavior:
- Set values or statically defined matching ENV vars (lookup deployment.yaml)
- .Values.alertaAdminUsers
- .Values.alertaAdminKey
-
Deploy helm chart
-
restart Alerta POD/Container only. Do not restart Postgres.
Expected behavior Code should accept the desired idempotent result whereby same admin user is being assigned same key. Container should be able to recover on restart.
Additional context Issue is at the https://github.com/alerta/docker-alerta/blob/master/docker-entrypoint.sh
# Create user-defined API key, if required
if [ -n "${ADMIN_KEY}" ]; then
echo "# Create user-defined admin API key."
alertad key --username "${ADMIN_USER}" --key "${ADMIN_KEY}" --duration "${MAXAGE}"
fi
the exact syntax of the error seems to originate from psql when trying to insert a record manually
ERROR: duplicate key value violates unique constraint "keys_key_key"
whilst debugging, I tried adding --force flag to alertad command but it made no difference
alerta@alerta-6cd7bc66d8-2lpmn:/$ alertad key --username "${ADMIN_USER}" --key "${ADMIN_KEY}" --force
ERROR: duplicate key value violates unique constraint "keys_key_key"
DETAIL: Key (key)=(*********secret*********) already exists.
Have a same issue, when launch new container with same db
i had this when i after the first start decided to change the email address from the example. it tried to create the admin user again and somehow this was triggering the duplicate key. (insert vs. update vs. upsert I guess)