0

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
Sollosa
  • 1,887
  • 4
  • 19
  • 32

0 Answers0