dargolith
dargolith

Reputation: 311

Helm: Show subchart version in parent chart configmap

I wish to create a configmap in my umbrella chart including the versions of all my dependency charts.

UmbrellaChart (version: 1.0.0-rc.0)
|
|--- microservice1Chart (1.2.3-rc.1)
|--- microservice2Chart (3.2.1-rc.2)

ConfigMap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: versionInfo
data:
  versionInfo.js: |
    window.versionInfo = {
      app: '{{ .Chart.Version | default "unknown" }}',
      service1: '{{ ??? }}',
      service2: '{{ ??? }}',
    };

What should I have instead of ??? to be able to include the version of my sub-charts. I wish to keep the version definition for my charts only in Chart.yaml to not have to change it in more places (otherwise I could just duplicate the information in the sub-charts' values files).

It doesn't seem possible to reference .Chart.Dependencies (otherwise they are specified there in the main chart). I don't know if it is possible to reference the sub-chart Chart.yaml info.

Upvotes: 1

Views: 1073

Answers (1)

z.x
z.x

Reputation: 2527

Look carefully at the official documentation, there is a method for using the built-in object Chart helm, pay attention here:

The built-in values always begin with a CAPITAL letter.

So the correct usage is as follows:

Chart.yaml

apiVersion: v2
name: UmbrellaChart
description: A Helm chart for Kubernetes
type: application
version: 1.0.0-rc.0
appVersion: "1.16.0"

dependencies:
  - name: microservice1Chart
    repository: xxx
    version: 1.2.3-rc.1
  - name: microservice2Chart
    repository: xxx
    version: 3.2.1-rc.2

templates/configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: versionInfo
data:
  versionInfo.js: |
    window.versionInfo = {
      app: '{{ .Chart.Version | default "unknown" }}',
      {{- range $i, $dep := .Chart.Dependencies }}
      {{- if eq $dep.Name "microservice1Chart" }}
      service1: '{{ $dep.Version }}',
      {{- end }}
      {{- if eq $dep.Name "microservice2Chart" }}
      service2: '{{ $dep.Version }}',
      {{- end }}
      {{- end }}
    };

output:

apiVersion: v1
kind: ConfigMap
metadata:
  name: versionInfo
data:
  versionInfo.js: |
    window.versionInfo = {
      app: '1.0.0-rc.0',
      service1: '1.2.3-rc.1',
      service2: '3.2.1-rc.2',
    };

Upvotes: 1

Related Questions