How can a templatize subchart values?

7/14/2020

For context I have an application, and it depends on the mysql chart. I've set up the mysql stable chart as a dependent chart in myapp chart.

I have a very large set of sql files, and due to their size, I need to pack them into a specialized seed container. Using the standard helm chart, I can pass in a seed container to init my database as shown in the below values.yaml snippet.

Are there any strategies to get subchart values created at runtime into my values.yaml?

mysql:
  extraInitContainers: |
    - name: init-seed
      image: foobar/seed:0.1.0
      env: 
      - name: MYSQL_HOSTNAME
        value: foobar-mysql
      - name: MYSQL_USER
        value: foo
      - name: MYSQL_PASS
        value: bar

I've tried ways to do the below, but to no avail.

a. Templatize and pass a service name into the MYSQL_HOSTNAME env var

b. Pass the {{ include "mangos_zero.fullname" . }} helper into this value

c. Find the name of the other container within the mysql pod at runtime?

How can I get the service name of the mysql-chart or it's container name passed into my init pod?

-- thisguy123
kubernetes
kubernetes-helm
mysql

1 Answer

7/14/2020

Not into your values.yaml but yes into your templates. Assuming you are using Helm v3 you can use the lookup function. For example, wherever you need the service name from your MySQL DB to create your seed data.

(lookup "v1" "Service" "mynamespace" "mysql-chart").metadata.name
-- Rico
Source: StackOverflow