Overwrite referenced files (in .Files) in a Subchart or insert mariadb initial files from a main chart

12/19/2018

So I have a mariadb subchart. The mariadb charts fills a config map from diffrent init files with:

{{ (.Files.Glob "files/docker-entrypoint-initdb.d/*[sh|sql|sql.gz]").AsConfig | indent 2 }}

So is there anyway I can inject the init files ?

Is it possible to overwrite the context of .Files.Glob so it access my parent directory ? or is there another recommended way to create initial sql files ?

the maridb subchart is implented like this in the requirements.yaml:

dependencies:
- name: mariadb
  version: 5.x.x
  repository: https://kubernetes-charts.storage.googleapis.com/
  condition: mariadb.enabled
-- fehrlich
initialization
kubernetes
kubernetes-helm
mariadb

1 Answer

12/19/2018

Since your mariadb is a subchart managed by third party, .Files.Glob refers only to files inside mariadb directory.

If you want to place any startup scripts inside subchart, you have to unarchive it.

Let's say you have custom-init-scripts directory with all init scripts in your parent chart.

$ ls custom-init-scripts/
init.sh  insert.sql

# download mariadb chart package in charts directory
$ helm dependency update

# unarchive and delete package
$ tar -xvf charts/mariadb-5.*.tgz -C charts && rm charts/mariadb-5.*.tgz

# copy init scripts to mariadb subchart
$ cp -a custom-init-scripts/. charts/mariadb/files/docker-entrypoint-initdb.d/

Now your init files are present in mariadb subchart

helm install --debug --dry-run --set mariadb.enabled=true .

...
---
# Source: mychart/charts/mariadb/templates/initialization-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: elevated-dragonfly-mariadb-master-init-scripts
  labels:
    app: mariadb
    component: "master"
    chart: mariadb-5.2.5
    release: "elevated-dragonfly"
    heritage: "Tiller"
binaryData:
data:
  init.sh: "echo \"hi\"\r\n"
  insert.sql: INSERT INT Users (FirstName, LastName) VALUES ('A', 'B');
-- edbighead
Source: StackOverflow