I'm developing helm parent and sub charts but have difficulty sharing particular (unique) hash values.
I have a parent chart P, and two sub charts: one configs chart C and one worker chart W. For simplicity, here assume C only contain one configmap, W only contain one deployment. When deploy P, C and W are deployed automatically, just working as expected.
Now think of we need generate one unique string value id (hash in particular) in C, based on the actual config files' contents.
id: {{ $.Files.Get "some config files in chart" | sha256sum }}
id will later be used by other components not mentioned here at runtime, so moving the value out of C is not an option.
Now the goal is set the same unique id as some part of deployment in W, particularlly, as volumeMounts.subPath.
Have tried following deployment syntax to include the configmap value as environement variable, then set as subPath. Some unrelated yaml sections omitted.
apiVersion: apps/v1
kind: Deployment
spec:
template:
spec:
containers:
- env:
- name: SUBPATH
valueFrom:
configMapKeyRef:
key: THEKEY
name: theconfigmap
command:
- /bin/bash
- args ["-c", "echo $(SUBPATH)"]
image: thedockerimagename
volumeMounts:
- mountPath: /somepath
name: volumnname
subPath: $(SUBPATH)
But seems environement variable only work for the process in container (echo $(SUBPATH) can show the id), not work for templating the deployment yaml(of course this is reasonable, but I'm seeking some ways to accomplish).
Also tried subPath: ${SUBPATH}, neither not work.
Even thought of ways such as in P package pipeline, use some scripts to pull C down and extract the id and replace it into W. but prefer if there exists more elegant built in mechanism.