Eitan
Eitan

Reputation: 1386

k8s - use two siblings helm charts with common data and dynamic variables in values yaml file

I am using helm 3 with k8s, with two siblings charts on root folder: <my-folder>/<chart-1> and <my-folder>/<chart-2>.

The kubectl version:

Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.6", GitCommit:"d921bc6d1810da51177fbd0ed61dc811c5228097", GitTreeState:"clean", BuildDate:"2021-10-27T17:50:34Z", GoVersion:"go1.16.9", Compiler:"gc", Platform:"linux/amd64"} Server Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.6", GitCommit:"d921bc6d1810da51177fbd0ed61dc811c5228097", GitTreeState:"clean", BuildDate:"2021-10-27T17:44:26Z", GoVersion:"go1.16.9", Compiler:"gc", Platform:"linux/amd64"}

Helm version:

version.BuildInfo{Version:"v3.3.4", GitCommit:"a61ce5633af99708171414353ed49547cf05013d", GitTreeState:"clean", GoVersion:"go1.14.9"}

  1. I have some common data that is used for both charts.

I want to use common data for both of the charts, event they do do not participate the same folders.

In yaml files something like: `{{ include from specific common directory + file }}

  1. In values.yaml file I need to add a dynamic variable, that is used in different attributes.

i.e. in the file:

mybasevar: "text"
myvariable: {{mybasevar}}-test

myvalue: {{ myvariable }}-tag1
myvalue2: {{ myvariable }}-tag2

In general, I didn't see an option for variables in yaml (maybe some Go-Lang code, or maybe this is basic on yaml files).

How can I the above?

Thanks.

Upvotes: 0

Views: 363

Answers (1)

vsergi
vsergi

Reputation: 785

After reading your message carefully and trying to understand what you want to achieve, I would advice to use Helm Subcharts and Global Values

Let me explain. You could create your Chart (parent) which contains componentA and componentB as subcharts. In the Chart.yaml of the parent chart, you would define the next dependencies:

dependencies:
    - name: componentA 
      version: "0.0.1"
      repository: "file://../componentA"
      condition: componentA.enabled
    - name: componentB 
      version: "0.0.1"
      repository: "file://../componentB"
      condition: componentB .enabled

At this point, you can deploy both components as a whole by using

helm install test parent/

Going back to your specific case:

  1. I have some common data that is used for both charts.

Then, define it as global in the values.yaml of the parent chart. For example,

autoscaling:
  enabled: false
  1. In values.yaml file I need to add a dynamic variable, that is used in different attributes.

In this case, add the name of the component in the values.yaml of the parent in the next way:

componentA:
  service:
    port: 80
componentB:
  service:
    port: 90

At this point, the variables will be dynamically filled in the subchart level. I think this approach would cover your needs nicely.

Upvotes: 1

Related Questions