Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

helm variables in .Values

I want to dynamically generate my template file, here is my case:

{{- $v := (.Files.Get "values-deployment-nginx.yaml") | fromYaml }}
spec:
  {{- range $key, $value := $v.containers }}
  containers:
  - name: {{ $value.name }}
    image: {{ .Values.{{ $value.name }}-image }}:{{ .Values.{{ $value.name }}--tag }}

I want to first get the {{ $value.name }}, it maybe a string like "nginx", then I would like to use the {{ .Values.nginx-image }} to get the right image value in values file.
Is there a way can do this? Thank you very much!


I have many deployment template dynamically generated, but only want to expose the image and tag to values file , so that we can pass different image informations when install chart. Other variables are in (.Files.Get "values-deployment-nginx.yaml") , like this(is also generated dynamically). So when generate the template, I want to match the image and tag in value file.

values file like this:

deployment-nginx-imagerepo: nginx
deployment-nginx-imagetag: latest

values-deployment-nginx.yaml like this(generated by other project):

autoscale: []
containers:
- envs: []
  imagerepository: nginx
  imagetag: latest
  itemid: n79fecd51_6716_fa65_5e64_aeed8ed6ab7e
  name: nginx
  resource:
    maxcpu: ""
    maxmemory: ""
    mincpu: "0.5"
    minmemory: 512m
  volumemounts: []
name: details
replicas: 1
schedulpolicy: []
storages: []
type: deployment
like image 774
yangyang Avatar asked Nov 23 '25 12:11

yangyang


1 Answers

In the Go text/template language I believe the index function will do this. (.Values is typically a map, and YAML maps and lists convert to Go maps and slices.) (Also remember almost everything in the sprig library is available.)

image: {{ index .Values (printf "%s-image" $value.name) }}:{{ index .Values (printf "%s-tag" $value.name) }}
like image 139
David Maze Avatar answered Nov 25 '25 09:11

David Maze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!