frappe / helm

Helm Chart Repository for Frappe/ERPNext
https://helm.erpnext.com
MIT License
138 stars 120 forks source link

create site job with in cluster mariadb doesn't set DB_ROOT_PASSWORD env var #173

Closed codezart closed 1 year ago

codezart commented 1 year ago

Description of the issue

I've setup erpnext's pre configured MariaDB config in k8s as follows:

                "mariadb":{
                    "enabled":True,
                    "auth": {
                        "rootPassword": "changeit",
                        "username": "erpnext",
                        "password": "changeit",
                        "replicationPassword": "changeit"
                    },
                    "primary": {
                        "service": {
                            "ports": {
                                "mysql": 3306
                            }
                        },
                        "configuration": "[mysqld]\nskip-name-resolve\nexplicit_defaults_for_timestamp\nbasedir=/opt/bitnami/mariadb\nplugin_dir=/opt/bitnami/mariadb/plugin\nport=3306\nsocket=/opt/bitnami/mariadb/tmp/mysql.sock\ntmpdir=/opt/bitnami/mariadb/tmp\nmax_allowed_packet=16M\nbind-address=*\npid-file=/opt/bitnami/mariadb/tmp/mysqld.pid\nlog-error=/opt/bitnami/mariadb/logs/mysqld.log\nslow_query_log=0\nslow_query_log_file=/opt/bitnami/mariadb/logs/mysqld.log\nlong_query_time=10.0\n\n# Frappe Specific Changes\ncharacter-set-client-handshake=FALSE\ncharacter-set-server=utf8mb4\ncollation-server=utf8mb4_unicode_ci\n\n[client]\nport=3306\nsocket=/opt/bitnami/mariadb/tmp/mysql.sock\nplugin_dir=/opt/bitnami/mariadb/plugin\n\n# Frappe Specific Changes\ndefault-character-set=utf8mb4\n\n[manager]\nport=3306\nsocket=/opt/bitnami/mariadb/tmp/mysql.sock\npid-file=/opt/bitnami/mariadb/tmp/mysqld.pid"
                    },
                },

when creating a new site I've passed all the required variables as follows:

                    "createSite": {
                        "enabled": True,
                        "siteName": "my_site",
                        "backoffLimit":3,
                        "adminPassword": "my_site_password",
                        "installApps": install_apps,
                        "dropSiteOnUninstall": True,
                        "dbRootUser": "root",
                        "dbRootPassword": "changit",
                    }

Observed result

The job fails due to error 2003 timeout when connecting with Mariadb

Expected result

Site creates normally

Stacktrace / full error message if available

Defaulted container "create-site" out of: create-site, validate-config (init)
Traceback (most recent call last):
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/pymysql/connections.py", line 613, in connect
    sock = socket.create_connection(
  File "/usr/local/lib/python3.10/socket.py", line 845, in create_connection
    raise err
  File "/usr/local/lib/python3.10/socket.py", line 833, in create_connection
    sock.connect(sa)
TimeoutError: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 109, in <module>
    main()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name="bench")
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 77, in new_site
    _new_site(
  File "/home/frappe/frappe-bench/apps/frappe/frappe/installer.py", line 80, in _new_site
    install_db(
  File "/home/frappe/frappe-bench/apps/frappe/frappe/installer.py", line 156, in install_db
    setup_database(force, source_sql, verbose, no_mariadb_socket)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/__init__.py", line 20, in setup_database
    return frappe.database.mariadb.setup_db.setup_database(
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/setup_db.py", line 36, in setup_database
    if force or (db_name not in dbman.get_database_list()):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/db_manager.py", line 49, in get_database_list
    return self.db.sql("SHOW DATABASES", pluck=True)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 200, in sql
    self.connect()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 114, in connect
    self._conn = self.get_connection()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/database.py", line 98, in get_connection
    conn = self._get_connection()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/database.py", line 104, in _get_connection
    return self.create_connection()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/database.py", line 107, in create_connection
    return pymysql.connect(**self.get_connection_settings())
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/pymysql/connections.py", line 353, in __init__
    self.connect()
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/pymysql/connections.py", line 664, in connect
    raise exc
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'site-name-mariadb' (timed out)")

Context information

When checking the site details it appears that the env variable for DB_ROOT_PASSWORD is not set properly.

      DB_ROOT_PASSWORD:  <set to the key 'mariadb-root-password' in secret 'site-name-mariadb'>  Optional: false

I've checked the secret and it is being created with the requried key as mentioned above.

Name:         site-name-mariadb
Namespace:    erpnext
Labels:       app.kubernetes.io/instance=site-name
              app.kubernetes.io/managed-by=Helm
              app.kubernetes.io/name=mariadb
              helm.sh/chart=mariadb-11.4.2
              helm.toolkit.fluxcd.io/name=site-name
              helm.toolkit.fluxcd.io/namespace=erpnext
Annotations:  meta.helm.sh/release-name: site-name
              meta.helm.sh/release-namespace: erpnext

Type:  Opaque

Data
====
mariadb-password:       13 bytes
mariadb-root-password:  13 bytes
revant commented 1 year ago

Following values worked for me:

mariadb:
  enabled: true
  auth:
    rootPassword: "changeit"
    username: "erpnext"
    password: "changeit"
    replicationPassword: "changeit"
  primary:
    extraFlags: --skip-character-set-client-handshake --skip-innodb-read-only-compressed --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

persistence:
  worker:
    storageClass: nfs
  logs:
    enabled: false

jobs:
  configure:
    fixVolume: false
  createSite:
    enabled: True
    siteName: "site.localhost"
    backoffLimit: 3
    adminPassword: "admin"
    installApps: []
    dbRootUser: "root"
    dbRootPassword: "changeit"

"rootPassword": "changeit", "username": "erpnext", "password": "changeit", "replicationPassword": "changeit"

passwords are changeit

"dbRootPassword": "changit",

site creating password is changit. e is missing in change.