[bitnami/wordpress] Deploying helm chart to existing database without user id = 1 fails to stabilize
Which chart:
[bitnami/wordpress] 12.1.14
Describe the bug
When deploying the helm chart to an existing database, without an entry in the ${wordpressTablePrefix}_users table with id = 1, the wordpress container will fail to stabilize.
To Reproduce Steps to reproduce the behavior:
- Create an external database, with user and password.
- Deploy the helm chart with the following values.yaml (use created database, user, and password from step 1):
mariadb:
enabled: false
externalDatabase:
host: $database_host_endpoint
port: 3306
user: testuser
password: testpassword
database: testdb
helm install test-wordpress -f values.yaml bitnami/wordpress
-
Verify that the install works as expected (it should).
-
Uninstall the helm chart:
helm uninstall test-wordpress -
Verify that the chart was uninstalled.
-
Login to the database and update the ${wordpressTablePrefix}_users table and set the id of the first row to 2 (or the next available number):
update wp_users set id = 2 where id = 1;
- Re-deploy the helm chart:
helm install test-wordpress -f values.yaml bitnami/wordpress
- Note that the wordpress container never stabilizes.
NAME READY STATUS RESTARTS AGE
pod/test-wordpress-6ff7676477-j6qfb 0/1 CrashLoopBackOff 3 115s
Expected behavior
The helm chart should not rely on a user with id = 1 in the ${wordpressTablePrefix}_users table.
Version of Helm and Kubernetes:
- Output of
helm version:
version.BuildInfo{Version:"v3.6.1", GitCommit:"61d8e8c4a6f95540c15c6a65f36a6dd0a45e7a2f", GitTreeState:"dirty", GoVersion:"go1.16.5"}
- Output of
kubectl version:
Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.3", GitCommit:"ca643a4d1f7bfe34773c74f79527be4afd95bf39", GitTreeState:"clean", BuildDate:"2021-07-15T20:58:09Z", GoVersion:"go1.16.5", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"21+", GitVersion:"v1.21.2-eks-0389ca3", GitCommit:"8a4e27b9d88142bbdd21b997b532eb6d493df6d2", GitTreeState:"clean", BuildDate:"2021-07-31T01:34:46Z", GoVersion:"go1.16.5", Compiler:"gc", Platform:"linux/amd64"}
Additional context
Setting the ID of the user in the ${wordpressTablePrefix}_users table back to 1 resolves the issue.
Note that I had a number of other error outputs that could mislead a user to believe that the issue was with a dynamic PVC or EFS or other storage issue that were not problems or related, ie, I had the following when using EFS with dynamic PVCs:
Output: Could not start amazon-efs-mount-watchdog, unrecognized init system "aws-efs-csi-dri"
b'mount.nfs4: access denied by server while mounting 127.0.0.1:/'
hi @itsecureadmin
Let me reproduce the issue. I will come back as soon as possible with some information.
Until I try to reproduce the problem, could you share with me pod logs, please?
Thanks a lot
Álvaro
hi @itsecureadmin
I reproduced the problem including the environment variable BITNAMI_DEBUG=true to see more logs. The error that I am reproducing:
WordPress is already installed.
Error: Invalid user ID, email or login: '1'
Comes from:
File: libwordpress.sh
314 # Post installation steps
315 local -r default_user_id="1"
316 wp_execute user meta set "$default_user_id" first_name "$WORDPRESS_FIRST_NAME"
317 wp_execute user meta set "$default_user_id" last_name "$WORDPRESS_LAST_NAME"
And this is the problem that you are reproducing. I created an internal issue to try to find a solution for this and added it to the backlog. I am not able to give you an ETA. We will update this thread once we have news. Until we try to find a possible solution, we are open to receive PR in case that you find a possible solution to this.
Thanks a lot
Álvaro
Hi @itsecureadmin,
After digging a bit on this I think that the issue you are facing is not related to user_id=1 but instead with the parameter wordpressSkipInstall. If you have an empty external MySQL instance and install the chart for the first time everything works because it initializes Wordpress configuration and creates the database tables. Then, when running the installation for the second time, it tries again to initialize everything but in this case there's no need for it and enters in CrashLoopBackOff. Setting wordpressSkipInstall solves the issue:
https://github.com/bitnami/charts/blob/615e0363212f9f6753d6812fc6251473379cada8/bitnami/wordpress/values.yaml#L124-L128
Hi @pablogalegoc,
I can confirm that setting the user_id back to 1 in the repro steps that I listed resolves the issue, without setting wordpressSkipInstall to false.
To your point though, I would also agree that my method is not standard and probably should not be supported.
I have used this method to migrate sites from ECS clusters into a kubernetes cluster where I move the database, and then deploy the helm chart to initialize the wordpress filesystem to generate a dynamic PV on EFS before syncing the site's files to the new filesystem. I would note also that this only impacted me on a single migration (of many) that happened to not have a user_id of 1 in the database.
Thanks! Josh
Awesome, happy to hear that!
In my case, I received the same error as:
Error: Invalid user ID, email or login: '1'
But in contrast, the user_id in my wp_users table was 4, and when I changed it back to 1, it started working again.
No solution permits fully automated deployment, so I had to implement a very ugly hack in values.yaml:
command:
- /bin/sh
- -c
- |
DB_NAME=xxxxxxxxxxxxx
DB_USER=xxxxxxxxxxx
DB_PASS=xxxxxxxxxxxxx
DB_HOST=xxxxxxxxxx
# If there is just one user, set id=1
userCount=$(mysql -h $DB_HOST -u $DB_USER -p$DB_PASS $DB_NAME -e "SELECT COUNT(*) FROM wp_users;" -s)
echo "User Count: $userCount"
if [ "$userCount" -eq 1 ]; then
userID=$(mysql -h $DB_HOST -u $DB_USER -p$DB_PASS $DB_NAME -e "SELECT ID FROM wp_users LIMIT 1;" -s)
echo "User ID: $userID"
mysql -h $DB_HOST -u $DB_USER -p$DB_PASS $DB_NAME -e "UPDATE wp_users SET ID = 1 WHERE ID = $userID;"
echo "Updated user id"
fi
# launch the bitnami entrypoint
/opt/bitnami/scripts/wordpress/entrypoint.sh /opt/bitnami/scripts/apache/run.sh
I know it is horrible. Please, fix this bug to make this hack unnecessary.