Skip to content

ERROR: duplicate key value violates unique constraint "keys_key_key" #379

@PowerSurj

Description

@PowerSurj

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:

  1. Set values or statically defined matching ENV vars (lookup deployment.yaml)
  • .Values.alertaAdminUsers
  • .Values.alertaAdminKey
  1. Deploy helm chart

  2. 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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions