CrunchyData / crunchy-containers

Containers for Managing PostgreSQL on Kubernetes by Crunchy Data
https://www.crunchydata.com/
Apache License 2.0
1.01k stars 328 forks source link

/opt/crunchy/bin/postgres/start.sh: line 366: syntax error near unexpected token 'else' in 4.7.0 #1370

Closed posi74de closed 3 years ago

posi74de commented 3 years ago

Describe the bug Tried to run /examples/kube/primary (and primary-replica - same procedure/results there): Followed installation instructions but got error on run.sh:

error: unable to recognize "STDIN": no matches for kind "Deployment" in version "extensions/v1beta1"

Fixed this by changing deployment in primary.json: apiVersion to "apps/v1". Got another error:

error: error validating "STDIN": error validating data: ValidationError(Deployment.spec): missing required field "selector" in io.k8s.api.apps.v1.DeploymentSpec

Fixed by adding selector section after replicas: "spec": { "replicas": 1, "selector": { "matchLabels": { "name": "primary" } }, ...

Was able to execute run.sh successful but pod did not start properly: NAME READY STATUS RESTARTS AGE pod/primary-646f479566-kb47g 0/1 Error 2 46s

Checked logs: # kubectl -n pgsql logs pod/primary-646f479566-kb47g nss_wrapper: user exists nss_wrapper: group exists nss_wrapper: environment configured Fri Jun 18 18:47:21 UTC 2021 ERROR: MODE environment variable is not set, aborting.

Tried to add MODE variable to env section of deployment in primary.json: "env": [ { "name": "MODE", "value": "postgres" }, ...

Tried again but no success: NAME READY STATUS RESTARTS AGE pod/primary-5667889db5-lfg22 0/1 CrashLoopBackOff 1 45s

Checked logs again: # kubectl -n pgsql logs pod/primary-5667889db5-lfg22 nss_wrapper: user exists nss_wrapper: group exists nss_wrapper: environment configured Fri Jun 18 18:49:46 UTC 2021 INFO: Image mode found: postgres Fri Jun 18 18:49:46 UTC 2021 INFO: Starting in 'postgres' mode Fri Jun 18 18:49:46 UTC 2021 INFO: Setting PGROOT to /usr/pgsql-13. Fri Jun 18 18:49:46 UTC 2021 INFO: PG_CTL_START_TIMEOUT set at: 60 Fri Jun 18 18:49:46 UTC 2021 INFO: PG_CTL_STOP_TIMEOUT set at: 60 Fri Jun 18 18:49:46 UTC 2021 INFO: PG_CTL_PROMOTE_TIMEOUT set at: 60 /opt/crunchy/bin/postgres/start.sh: line 366: syntax error near unexpected token 'else' /opt/crunchy/bin/postgres/start.sh: line 366: ' else'

Could you please let me know if I was on the right track above and how to fix these issues?

Expected behavior pods are starting up

Please tell us about your environment:

posi74de commented 3 years ago

I have tried running on docker with similar results:

$ docker run -e MODE=postgres -e PG_MODE=primary -e PG_PRIMARY_USER=primaryuser -e PG_PRIMARY_PASSWORD=password -e PG_USER=testuser -e PG_PASSWORD=password -e PG_DATABASE=userdb -e PG_ROOT_PASSWORD=password -e PG_PRIMARY_PORT=5432 crunchydata/crunchy-postgres:centos8-13.3-4.7.0 nss_wrapper: user exists nss_wrapper: group exists nss_wrapper: environment configured Fri Jun 18 19:27:16 UTC 2021 INFO: Image mode found: postgres Fri Jun 18 19:27:16 UTC 2021 INFO: Starting in 'postgres' mode Fri Jun 18 19:27:16 UTC 2021 INFO: Setting PGROOT to /usr/pgsql-13. Fri Jun 18 19:27:16 UTC 2021 INFO: PG_CTL_START_TIMEOUT set at: 60 Fri Jun 18 19:27:16 UTC 2021 INFO: PG_CTL_STOP_TIMEOUT set at: 60 Fri Jun 18 19:27:16 UTC 2021 INFO: PG_CTL_PROMOTE_TIMEOUT set at: 60 /opt/crunchy/bin/postgres/start.sh: line 366: syntax error near unexpected token 'else' /opt/crunchy/bin/postgres/start.sh: line 366: ' else'

(tested on debian 10 and windows 10)

posi74de commented 3 years ago

OK, this happens in 4.7.0 only - tried 4.6.3 in docker and k8s and the error does not happen here.

posi74de commented 3 years ago

Another issue: path to readyness and liveness probes seems to be different (/opt/crunchy/bin/postgres/readiness.sh) and wrong in k8s .json file(s).

iboates commented 3 years ago

Can confirm that 4.6.3 is working - thank you for the tip @posi74de!

I think it is also worth pointing out that the MODE environment variable still needs to be set to postgres in 4.6.3, but it is missing from the "Download PostGIS Cotnainer" page instructions.

And despite the guide claiming that you can connect with PGPASSWORD=datalake psql -h localhost -p 5432 -U hippo hippo, I was only able to connect to it from inside the OpenShift pod by using -h 127.0.0.1 due to the UNIX domain socket being disallowed in `pg_hba.conf``

schewara commented 3 years ago

Just ran into the same problem and based on https://github.com/CrunchyData/crunchy-containers/commit/e126ec981b59267608821e61040ab574c799aa68 this should be already fixed by @jkatz , but the Images for 4.7.0 are still broken.

jkatz commented 3 years ago

This was resolved in https://github.com/CrunchyData/crunchy-containers/commit/e126ec981b59267608821e61040ab574c799aa68 -- 4.7.1 is released with the fix.