Sample Header Ad - 728x90

HELM get first element from a helpers template

0 votes
1 answer
1343 views
I have some template inside _helpers.tpl file like this {{- define "clusterNodes" }} - ip: "192.168.7.10" hostnames: - "m1" - ip: "192.168.7.20" hostnames: - "w1" - ip: "192.168.7.30" hostnames: - "w2" {{- end }} and I want to fetch hostnames of first element in above for following yaml apiVersion: apps/v1 kind: Deployment metadata: name: nginx2 spec: replicas: 1 selector: matchLabels: app: nginx2 template: metadata: labels: app: nginx2 spec: nodeName: "{{ (index (index $clusterNodes "clusterNodes") 0).hostnames.0 }}" containers: - name: nginx2 image: nginx:alpine imagePullPolicy: IfNotPresent so that this entry look like below nodeName: m1
Asked by Sollosa (1993 rep)
Jul 6, 2023, 06:47 PM
Last activity: Sep 20, 2023, 07:58 AM