Örnek - Modifying scope using “with”
Söz dizimi şöyle
{{ with PIPELINE }}
{{- toYaml . | nindent 2 }}
{{ end }}values.yaml şöyle olsun
configMap:
data:
env: test
platfrom:
- java
- python
- golangŞöyle yaparız
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
env: {{ .Values.configMap.data.env }}
{{- with .Values.configMap.data.platfrom }}
platfrom: {{- toYaml . | nindent 2 | upper }}
{{- end }}Çıktısı şöyle
>> helm template ~/webserver --- # Source: webserver/templates/configmap.yaml apiVersion: v1 kind: ConfigMap metadata: name: release-name-configmap data: env: test platfrom: - JAVA - PYTHON - GOLANG
Örnek
values.yaml şöyle olsun
configMap:
data:
env: test
platfrom:
- java
- python
- golang
conf:
os: linux
database: mongoŞöyle yaparız
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
env: {{ .Values.configMap.data.env }}
{{- with .Values.configMap.data.platfrom }}
platfrom: {{- toYaml . | nindent 2 | upper }}
{{- end }}
{{- with .Values.configMap.data.conf }}
operating-system: {{ .os }}
database-name: {{ .database }}
{{- end }} Çıktısı şöyle
>> helm template ~/webserver # Source: webserver/templates/configmap.yaml apiVersion: v1 kind: ConfigMap metadata: name: release-name-configmap data: env: test platfrom: - JAVA - PYTHON - GOLANG operating-system: linux database-name: mongo
Açıklaması şöyle
As we discussed earlier, within a with block .referred to a particular object. But there may be cases where we might have a requirement to access root objects or other objects, which are not a part of the current scope.
Şu kod hata verir
{{- with .Values.configMap.data.conf }}
operating-system: {{ .os }}
database-name: {{ .database }}
k8s-namespace: {{ .Release.Namespace }}
{{- end }}
Error: template: webserver/templates/configmap.yaml:14:28:
executing "webserver/templates/configmap.yaml" at
<.Release.Namespace>: nil pointer evaluating interface {}.NamespaceRoot scope olduğunu belirtmek için $ karakteri kullanılır. Şöyle yaparız
{{- with .Values.configMap.data.conf }}
operating-system: {{ .os }}
database-name: {{ .database }}
k8s-namespace: {{ $.Release.Namespace }}
{{- end }}
Hiç yorum yok:
Yorum Gönder