Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL in Helm: initdbScripts Parameter

The default Helm Chart for PostgreSQL (i.e. stable/postgresql) defines an initdbScripts parameter that allows initialization scripts to be run. However, I can't seem to get the format correct on how to issue it via the command line.

Could someone provide an example of how to populate this command line parameter?

Here's what I'm issuing, minus a working version of the initdbScripts parameter.

helm install stable/postgresql -n testpg \
    --set global.postgresql.postgresqlDatabase=testpg \
    --set global.postgresql.postgresqlUsername=testpg \
    --set global.postgresql.postgresqlPassword=testpg \
    --set global.postgresql.servicePort=5432 \
    --set initdbScripts=(WHAT GOES HERE TO RUN "sql/init.sql"??) \
    --set service.type=LoadBalancer
like image 345
jeffmaher Avatar asked Apr 03 '19 16:04

jeffmaher


1 Answers

According to stable/postgresql helm chart, initdbScripts is a dictionary of init script names which are multi-line variables:

## initdb scripts
## Specify dictionary of scripts to be run at first boot
## Alternatively, you can put your scripts under the files/docker-entrypoint-initdb.d directory
##
# initdbScripts:
#   my_init_script.sh:|
#      #!/bin/sh
#      echo "Do something."

Let's assume that we have the following init.sql script:

CREATE USER helm;
CREATE DATABASE helm;
GRANT ALL PRIVILEGES ON DATABASE helm TO helm;

When we are going to inject a multi-line text into values we need to deal with indentation in YAML.

For above particular case it is:

helm install stable/postgresql -n testpg \
--set global.postgresql.postgresqlDatabase=testpg \
--set global.postgresql.postgresqlUsername=testpg \
--set global.postgresql.postgresqlPassword=testpg \
--set global.postgresql.servicePort=5432 \
--set initdbScripts."init\.sql"="CREATE USER helm;
CREATE DATABASE helm;
GRANT ALL PRIVILEGES ON DATABASE helm TO helm;" \
--set service.type=LoadBalancer

There is some explanation to above example:

  1. If script's name has . it should be escaped, like "init\.sql".
  2. Script's content is in double quotes, because it's multi-line string variable.
like image 179
nickgryg Avatar answered Nov 05 '22 09:11

nickgryg