Reputation: 173
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.
Upvotes: 0
Views: 1059
Reputation: 37994
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 }}
Upvotes: 1
Reputation: 11193
You can use the index
function
{{ index .Values.selectorLabels "app.kubernetes.io/name" }}
Upvotes: 0