Helm:如何在Umbrella Chart的ConfigMap中展示子Chart版本
Great question – I’ve run into this exact scenario before. The good news is you don’t need to duplicate version info in values files. You can access the actual version from each subchart’s Chart.yaml directly using Helm’s .Subcharts object.
Here’s what you need to replace those ??? with:
- For
microservice1Chart:{{ index .Subcharts "microservice1Chart".Chart.Version | default "unknown" }} - For
microservice2Chart:{{ index .Subcharts "microservice2Chart".Chart.Version | default "unknown" }}
Full Updated ConfigMap
apiVersion: v1 kind: ConfigMap metadata: name: versionInfo data: versionInfo.js: | window.versionInfo = { app: '{{ .Chart.Version | default "unknown" }}', service1: '{{ index .Subcharts "microservice1Chart".Chart.Version | default "unknown" }}', service2: '{{ index .Subcharts "microservice2Chart".Chart.Version | default "unknown" }}', };
Why This Works
Helm exposes all loaded subcharts through the .Subcharts object, which gives you full access to each subchart’s context – including its Chart.yaml values. The key here is using the exact name of the subchart as defined in your umbrella chart’s Chart.yaml dependencies list (case-sensitive).
You’re right that .Chart.Dependencies only gives you the version constraints you defined in the umbrella chart (like >=1.2.0), not the actual resolved version of the subchart. .Subcharts bypasses this by pulling the real version directly from the subchart’s own Chart.yaml.
Quick Notes
- Ensure the subchart name in the
indexcall matches exactly what’s defined in your umbrella chart’sdependenciessection (typos and case sensitivity matter). - The
default "unknown"fallback prevents rendering errors if a subchart is disabled or fails to load.
内容的提问来源于stack exchange,提问作者dargolith

