Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
362 views
in Technique[技术] by (71.8m points)

json - How to read value from yaml file which are in dictionary and need to use in helm

This is my string in values.yaml: selectorLabels: { app.kubernetes.io/name: tinyurl }

Yaml file looks like below:

name: test-dj-service
environment: prod
namespace: test-service
labels: { app.kubernetes.io/name: test-dj-service, environment: prod }
replicaCount: 1
selectorLabels: { app.kubernetes.io/name: tinyurl } <---

I need to use tinyurl in the below code under values.

Note:- tinyurl is variable, it will keep changing with other names.


{?{ - if .Values.affinity.podAntiAffinity.preferred == true }}
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 100
            podAffinityTerm:
              labelSelector:
                 matchExpressions:
                 - key: app.kubernetes.io/name
                   operator: In
                   values: {?{ ---------- }} # need to pull the selectorLabels values here.
              topologyKey: "kubernetes.io/hostname"
{?{- end }}

So how I can pull this variable into values.

question from:https://stackoverflow.com/questions/65918338/how-to-read-value-from-yaml-file-which-are-in-dictionary-and-need-to-use-in-helm

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In addition to @ShashankV's answer, you should also be able to construct your label selector using a range expression (in case you want to support arbitrary label selectors, with multiple labels that are read from your Values file):

labelSelector:
  matchExpressions:
  {{- range $key, $value := .Values.selectorLabels }}
  - key: {{ $key | quote }}
    operator: In
    values: {?{ $value | quote }}
  {{- end }}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...