Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(helm): database name as an environment variable #76

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

nlamirault
Copy link
Contributor

@nlamirault nlamirault commented Nov 16, 2024

close #77

Signed-off-by: Nicolas Lamirault <[email protected]>
@nlamirault nlamirault requested a review from talboren as a code owner November 16, 2024 13:34
@shahargl
Copy link
Member

hey @nlamirault, thanks for your contribution!

can I ask you to bump the version on Chart.yaml?

@shahargl shahargl self-requested a review November 16, 2024 17:46
Copy link
Member

@shahargl shahargl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please update the version too? to 0.1.41

@shahargl shahargl self-requested a review November 16, 2024 17:46
Signed-off-by: Nicolas Lamirault <[email protected]>
Signed-off-by: Nicolas Lamirault <[email protected]>
Copy link
Member

@shahargl shahargl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @nlamirault - e2e tests are failing.

I think you need to change

command: ['sh', '-c', 'until nc -z ${DATABASE_NAME} 3306; do sleep 1; done;']

to

command: ['sh', '-c', 'until nc -z {{ include "keep.findEnvVar" (list "DATABASE_NAME" .) | default "keep-database" }} 3306; do sleep 1; done;']

@shahargl shahargl self-requested a review November 17, 2024 13:54
Copy link
Member

@shahargl shahargl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests failing, need to change the env var to be from .Values

@shahargl
Copy link
Member

hey @nlamirault , is it still an issue?

@nlamirault
Copy link
Contributor Author

i've got this error now:

kubectl -n alerting logs keep-backend-7fbb7f8c44-mg72t
Defaulted container "keep" out of: keep, wait-for-database (init)
+ dirname /venv/lib/python3.11/site-packages/keep/entrypoint.sh
+ SCRIPT_DIR=/venv/lib/python3.11/site-packages/keep
+ exec gunicorn keep.api.api:get_app --bind 0.0.0.0:8080 --workers 4 -k uvicorn.workers.UvicornWorker -c /venv/lib/python3.11/site-packages/keep/api/config.py --preload
+ python /venv/lib/python3.11/site-packages/keep/server_jobs_bg.py
{"asctime": "2024-12-11 06:07:33,772", "message": "Starting background server jobs.", "levelname": "INFO", "name": "__main__", "filename": "server_jobs_bg.py", "otelTraceID": null, "otelSpanID": null, "otelServiceName": null, "threadName": "MainThread", "process": 8, "module": "server_jobs_bg"}
{"asctime": "2024-12-11 06:07:33,772", "message": "Checking if server is up at http://localhost:8080...", "levelname": "INFO", "name": "__main__", "filename": "server_jobs_bg.py", "otelTraceID": null, "otelSpanID": null, "otelServiceName": null, "threadName": "MainThread", "process": 8, "module": "server_jobs_bg"}
{"asctime": "2024-12-11 06:07:33,774", "message": "API is not up yet. Waiting...", "levelname": "INFO", "name": "__main__", "filename": "server_jobs_bg.py", "otelTraceID": null, "otelSpanID": null, "otelServiceName": null, "threadName": "MainThread", "process": 8, "module": "server_jobs_bg"}
{"asctime": "2024-12-11 06:07:34,855", "message": "Creating a connection pool with size 5", "levelname": "INFO", "name": "keep.api.core.db_utils", "filename": "db_utils.py", "otelTraceID": null, "otelSpanID": null, "otelServiceName": null, "threadName": "MainThread", "process": 1, "module": "db_utils"}
[2024-12-11 06:07:34 +0000] [1] [INFO] Starting gunicorn 22.0.0
{"asctime": "2024-12-11 06:07:34,874", "message": "Keep server starting", "levelname": "INFO", "name": "__config__", "filename": "config.py", "otelTraceID": null, "otelSpanID": null, "otelServiceName": null, "threadName": "MainThread", "process": 1, "module": "config"}
{"asctime": "2024-12-11 06:07:34,875", "message": "Running migrations...", "levelname": "INFO", "name": "keep.api.core.db_on_start", "filename": "db_on_start.py", "otelTraceID": null, "otelSpanID": null, "otelServiceName": null, "threadName": "MainThread", "process": 1, "module": "db_on_start"}
Traceback (most recent call last):
Traceback (most recent call last):
  File "/venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 3361, in _wrap_pool_connect
    return fn()
           ^^^^
  File "/venv/lib/python3.11/site-packages/sqlalchemy/pool/base.py", line 320, in connect
    return _ConnectionFairy._checkout(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/sqlalchemy/pool/base.py", line 884, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/sqlalchemy/pool/base.py", line 486, in checkout
    rec = pool._do_get()
          ^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/sqlalchemy/pool/impl.py", line 145, in _do_get
    with util.safe_reraise():
  File "/venv/lib/python3.11/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/venv/lib/python3.11/site-packages/sqlalchemy/util/compat.py", line 208, in raise_
    raise exception
  File "/venv/lib/python3.11/site-packages/sqlalchemy/pool/impl.py", line 143, in _do_get
    return self._create_connection()
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/sqlalchemy/pool/base.py", line 266, in _create_connection
    return _ConnectionRecord(self)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/sqlalchemy/pool/base.py", line 381, in __init__
    self.__connect()
  File "/venv/lib/python3.11/site-packages/sqlalchemy/pool/base.py", line 677, in __connect
    with util.safe_reraise():
  File "/venv/lib/python3.11/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/venv/lib/python3.11/site-packages/sqlalchemy/util/compat.py", line 208, in raise_
    raise exception
  File "/venv/lib/python3.11/site-packages/sqlalchemy/pool/base.py", line 673, in __connect
    self.dbapi_connection = connection = pool._invoke_creator(self)
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/sqlalchemy/engine/create.py", line 578, in connect
    return dialect.connect(*cargs, **cparams)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/sqlalchemy/engine/default.py", line 598, in connect
    return self.dbapi.connect(*cargs, **cparams)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/pymysql/connections.py", line 361, in __init__
    self.connect()
  File "/venv/lib/python3.11/site-packages/pymysql/connections.py", line 669, in connect
    self._request_authentication()
  File "/venv/lib/python3.11/site-packages/pymysql/connections.py", line 957, in _request_authentication
    auth_packet = self._read_packet()
                  ^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/pymysql/connections.py", line 775, in _read_packet
    packet.raise_for_error()
  File "/venv/lib/python3.11/site-packages/pymysql/protocol.py", line 219, in raise_for_error
    err.raise_mysql_exception(self._data)
  File "/venv/lib/python3.11/site-packages/pymysql/err.py", line 150, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.OperationalError: (1524, "Plugin 'mysql_native_password' is not loaded")

using this environment variable in the deployment:

            - name: DATABASE_CONNECTION_STRING
              value: 'mysql+pymysql://keep:xxxxx@moco-keep-db-primary:3306/keep'

@nlamirault
Copy link
Contributor Author

i change my Helm settings and use an external Postgres database, managed by the CloudNativePG Operator.
It works now.
but I made some changes in the deployment of the backend (and not use the backend manifest generated by the Helm chart)

- name: DATABASE_CONNECTION_STRING
   value: "postgresql://keep:xxxxxx@keep-rw:5432/keep"

and also:

initContainers:
        - command:
            - sh
            - '-c'
            - until nc -z keep-rw 5432; do sleep 1; done;

@shahargl
Copy link
Member

@nlamirault

pymysql.err.OperationalError: (1524, "Plugin 'mysql_native_password' is not loaded")

this is because your MySQL server doesn't support password authentication - you should enable it for Keep to authenticate with user/password

@shahargl
Copy link
Member

i change my Helm settings and use an external Postgres database, managed by the CloudNativePG Operator. It works now. but I made some changes in the deployment of the backend (and not use the backend manifest generated by the Helm chart)

- name: DATABASE_CONNECTION_STRING
   value: "postgresql://keep:xxxxxx@keep-rw:5432/keep"

and also:

initContainers:
        - command:
            - sh
            - '-c'
            - until nc -z keep-rw 5432; do sleep 1; done;

cool. would be happy to merge your changes to the helm repo if you want

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT]: Keep database not const
2 participants