Home > Back-end >  Access helm context of dependencies
Access helm context of dependencies

Time:05-26

We are using this chart:

apiVersion: v2
appVersion: 1.0
version: 0.0.1
description: Helm chart for setting up Kafka platform (Kafka, Zookeeper, Kafka Rest, Kafka Schema Registry, Kafka Connect, KSQL Server)
name: kafka-platform

dependencies:
  - name: cp-helm-charts
    version: 0.6.0
    repository: "https://confluentinc.github.io/cp-helm-charts"

We need to create new local template that does not exist in the public chart, and this new template should access built-in variables as defined in the public chart. For example, the .Chart.Name

apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Confluent Kafka on Kubernetes
name: cp-kafka
version: 0.1.0

How could we access "cp-kafka" from a local .tpl named template or template? All I manage to access right now is either an error of type " at <.Chart.Name>: can't evaluate field Chart in type int" or the value of the local Chart "kafka-platform".

I've searched for this question/answer but although I see things that look alike, I did not find one that fully fits or answers this exact question.

CodePudding user response:

You can use the subcharts list.

{{ $sub := index .Subcharts "cp-kafka" }}

This will give you all built in variables and even the .Values from the values file.

For example, I create a chart and a subchart:

helm create foo
helm create foo/charts/bar
rm -rf foo/templates/*
rm -rf foo/charts/bar/templates/*

In bar values I put this:

some:
  values: from
  this: subchart

In foo templates I put this configmap:

kind: ConfigMap
apiVersion: v1
metadata:
  name: example
data:
  bar-chart: |
    {{- .Subcharts.bar | toYaml | nindent 4 }}

Now when I render the chart with helm template foo I get the below output:

---
# Source: foo/templates/cm.yaml
kind: ConfigMap
apiVersion: v1
metadata:
  name: example
data:
  bar-chart: |
    Capabilities:
      APIVersions:
      - v1
      - admissionregistration.k8s.io/v1
      - admissionregistration.k8s.io/v1beta1
      - internal.apiserver.k8s.io/v1alpha1
      - apps/v1
      - apps/v1beta1
      - apps/v1beta2
      - authentication.k8s.io/v1
      - authentication.k8s.io/v1beta1
      - authorization.k8s.io/v1
      - authorization.k8s.io/v1beta1
      - autoscaling/v1
      - autoscaling/v2
      - autoscaling/v2beta1
      - autoscaling/v2beta2
      - batch/v1
      - batch/v1beta1
      - certificates.k8s.io/v1
      - certificates.k8s.io/v1beta1
      - coordination.k8s.io/v1beta1
      - coordination.k8s.io/v1
      - discovery.k8s.io/v1
      - discovery.k8s.io/v1beta1
      - events.k8s.io/v1
      - events.k8s.io/v1beta1
      - extensions/v1beta1
      - flowcontrol.apiserver.k8s.io/v1alpha1
      - flowcontrol.apiserver.k8s.io/v1beta1
      - flowcontrol.apiserver.k8s.io/v1beta2
      - networking.k8s.io/v1
      - networking.k8s.io/v1beta1
      - node.k8s.io/v1
      - node.k8s.io/v1alpha1
      - node.k8s.io/v1beta1
      - policy/v1
      - policy/v1beta1
      - rbac.authorization.k8s.io/v1
      - rbac.authorization.k8s.io/v1beta1
      - rbac.authorization.k8s.io/v1alpha1
      - scheduling.k8s.io/v1alpha1
      - scheduling.k8s.io/v1beta1
      - scheduling.k8s.io/v1
      - storage.k8s.io/v1beta1
      - storage.k8s.io/v1
      - storage.k8s.io/v1alpha1
      - apiextensions.k8s.io/v1beta1
      - apiextensions.k8s.io/v1
      HelmVersion:
        git_commit: 6e3701edea09e5d55a8ca2aae03a68917630e91b
        git_tree_state: clean
        go_version: go1.17.5
        version: v3.8.2
      KubeVersion:
        Major: "1"
        Minor: "23"
        Version: v1.23.0
    Chart:
      IsRoot: false
      apiVersion: v2
      appVersion: 1.16.0
      description: A Helm chart for Kubernetes
      name: bar
      type: application
      version: 0.1.0
    Files:
      .helmignore: IyBQYXR0ZXJucyB0byBpZ25vcmUgd2hlbiBidWlsZGluZyBwYWNrYWdlcy4KIyBUaGlzIHN1cHBvcnRzIHNoZWxsIGdsb2IgbWF0Y2hpbmcsIHJlbGF0aXZlIHBhdGggbWF0Y2hpbmcsIGFuZAojIG5lZ2F0aW9uIChwcmVmaXhlZCB3aXRoICEpLiBPbmx5IG9uZSBwYXR0ZXJuIHBlciBsaW5lLgouRFNfU3RvcmUKIyBDb21tb24gVkNTIGRpcnMKLmdpdC8KLmdpdGlnbm9yZQouYnpyLwouYnpyaWdub3JlCi5oZy8KLmhnaWdub3JlCi5zdm4vCiMgQ29tbW9uIGJhY2t1cCBmaWxlcwoqLnN3cAoqLmJhawoqLnRtcAoqLm9yaWcKKn4KIyBWYXJpb3VzIElERXMKLnByb2plY3QKLmlkZWEvCioudG1wcm9qCi52c2NvZGUvCg==
    Release:
      IsInstall: true
      IsUpgrade: false
      Name: release-name
      Namespace: default
      Revision: 1
      Service: Helm
    Subcharts: {}
    Values:
      global: {}
      some:
        this: subchart
        values: from
  • Related