3
votes

I'm trying to figure out how to share data between two charts in helm.

I've set up a chart with a sole YAML for a configmap in one chart. Let's call the chart cm1. It defines it's name like so:

name:  {{ .Release.Name }}-maps

Then I set up two charts that deploy containers that would want to access the data in the configmap in c1. Let's call them c1 and c2. c1 has a requirements.yaml that references the chart for cm1, and likewise for c2. Now I have a parent chart that tries to bring it all together, let's call it p1. p1 defines c1 and c2 in requirements.yaml. The I helm install --name k1 p1 and I get an error:

Error: release k1 failed: configmaps "k1-maps" already exists.

I thought that when helm builds its dependency tree that it would see that the k1-maps was already defined when chart cm1 was first loaded.

What's the best practice to share a configmap between two charts?

1
I agree with @Michael Pratt - you want to ensure the configmap is only in one chart, preferably at a common level. For an example see github.com/ryandawsonuk/configmaps-transformers/tree/master/… (the example comes from dzone.com/articles/… ) Happy to help further if I can - Ryan Dawson
One thing I would like to be able to do is individually and cleanly install c1 or c2, which works now because release names are different. but when the parent does it the release name is the same. - harschware
I tried to make a short example of the problem here: github.com/harschware/shared-config-maps - harschware
I see @Michael Pratt has answered that in a comment too. You can wrap the content of the configmap template in an if block and use a flag that you can set so that only one instance in the umbrella chart deploys it. - Ryan Dawson

1 Answers

3
votes

You haven't given a ton of information about the contents of your charts, but it sounds like both c1 and c2 are defining and attempting to install the configmap. Helm doesn't really know anything special about the dependencies, it just knows to also install them. It will happily attempt (and fail) to install the chart a second time if told to.

The configmap should be created and installed only as part of the parent chart. C1 and C2 should be able to reference it by name even though it isn't defined in either of them.