helm chart函数

发布一个k8s部署视频:https://edu.csdn.net/course/detail/26967

课程内容:各种k8s部署方式。包括minikube部署,kubeadm部署,kubeasz部署,rancher部署,k3s部署。包括开发测试环境部署k8s,和生产环境部署k8s。

腾讯课堂连接地址https://ke.qq.com/course/478827?taid=4373109931462251&tuin=ba64518

第二个视频发布  https://edu.csdn.net/course/detail/27109

腾讯课堂连接地址https://ke.qq.com/course/484107?tuin=ba64518

介绍主要的k8s资源的使用配置和命令。包括configmap,pod,service,replicaset,namespace,deployment,daemonset,ingress,pv,pvc,sc,role,rolebinding,clusterrole,clusterrolebinding,secret,serviceaccount,statefulset,job,cronjob,podDisruptionbudget,podSecurityPolicy,networkPolicy,resourceQuota,limitrange,endpoint,event,conponentstatus,node,apiservice,controllerRevision等。

第三个视频发布:https://edu.csdn.net/course/detail/27574

详细介绍helm命令,学习helm chart语法,编写helm chart。深入分析各项目源码,学习编写helm插件

第四个课程发布:https://edu.csdn.net/course/detail/28488

本课程将详细介绍k8s所有命令,以及命令的go源码分析,学习知其然,知其所以然


————————————————

_helper.tpl:

[root@master01 test]# cat templates/_helpers.tpl 
{{- define "mychart.labels" }}
  labels:
    generator: helm
    date: {{ now | htmlDate }}
{{- end }}
{{- define "mychart.app" -}}
app_name: {{ .Chart.Name }}
app_version: "{{.Chart.Version}}+{{now|htmlDate}}"
{{- end -}}
{{- define "namespace" -}}
    namespace: {{.Release.Namespace}}
{{- end -}}

{{- define "harbor.tplValue" -}}
    {{- if typeIs "string" .value -}}
        {{- tpl .value .context -}}
    {{- else -}}
        {{- tpl (.value | toYaml) .context -}}
    {{- end -}}
{{- end -}}

values.yaml

[root@master01 test]# cat values.yaml 
favorite:
  food: rice
  drink: coffee
  fruit:  
pizzaToppings:
  - mushrooms
  - cheese
  - peppers
  - onions 
global:
  salad: caesar
resources:
  resources:
    limits:
      cpu: 100m
      memory: 128Mi
    requests:
      cpu: 100m
hostPorts:
  http: 10
  https: 11
containerPort:
  http: 80
  https: 81
minReplicas: "1"
maxReplicas: 5
rules:
- rule1: aa
- rule2: bb
tcp: "{{.Values.maxReplicas}}"
template: "{{ .Values.name }}"
name: "Tom"
password: http://a.com/?id=123456
tag: 1.10.0-debiansha256:sss
tag2: 1.10.0-debian-9-r30
url: http://www.baidu.com
debug: true
snake: sharedBuffers
path: /etc/fstable/aa
json:
  aa: bb
  cc: dd
testYaml: | 
  containers:
    name: a
    image: b
jsonTemp: |
  {"aa":"bb","cc":"dd"}
html: |
    段落
camel: my_name_is_mark 
shuffle: mynameismark
[root@master01 test]# cat templates/if.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-configmap
data:
  myvalue: "Hello World"
  {{- if eq .Values.favorite.drink "coffee"}}
  mug: true
  {{- end}}

[root@master01 test]# helm template . --show-only templates/if.yaml
---
# Source: test/templates/if.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: RELEASE-NAME-configmap
data:
  myvalue: "Hello World"
  mug: true
[root@master01 test]# cat templates/ifelse.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-configmap
data:
  myvalue: "Hello World"
  {{- if eq .Values.favorite.drink "tea"}}
  mug: true
  {{- else}}
  mug: false
  {{- end}}

[root@master01 test]# helm template . --show-only templates/ifelse.yaml
---
# Source: test/templates/ifelse.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: RELEASE-NAME-configmap
data:
  myvalue: "Hello World"
  mug: false
[root@master01 test]# cat templates/with.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-configmap
data:
  myvalue: "Hello World"
  {{- with .Values.favorite }}
  drink: {{ .drink | default "tea" | quote }}
  food: {{ .food | upper | quote }}
  {{- end }}

[root@master01 test]# helm template . --show-only templates/with.yaml
---
# Source: test/templates/with.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: RELEASE-NAME-configmap
data:
  myvalue: "Hello World"
  drink: "coffee"
  food: "RICE"
[root@master01 test]# cat templates/range.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-configmap
data:
  myvalue: "Hello World"
  toppings: |-
    {{- range .Values.pizzaToppings }}
    - {{ . }}
    {{- end }}
    {{- range $key, $val := .Values.favorite }}
    {{ $key }}: {{ $val | quote }}
    {{- end}}

[root@master01 test]# helm template . --show-only templates/range.yaml
---
# Source: test/templates/range.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: RELEASE-NAME-configmap
data:
  myvalue: "Hello World"
  toppings: |-
    - mushrooms
    - cheese
    - peppers
    - onions
    drink: "coffee"
    food: "rice"
    fruit:
[root@master01 test]# cat templates/and.yaml 
{{- if and (gt 5 1)  (lt 3 10)}}
and: true
{{- end}}

[root@master01 test]# helm template . --show-only templates/and.yaml
---
# Source: test/templates/and.yaml
and: true
[root@master01 test]# cat templates/html.yaml 
html: |
  {{html "<html><head><title>title</title></head></html>"}}
[root@master01 test]# helm template . --show-only templates/html.yaml
---
# Source: test/templates/html.yaml
html: |
  &lt;html&gt;&lt;head&gt;&lt;title&gt;title&lt;/title&gt;&lt;/head&gt;&lt;/html&gt;
[root@master01 test]# cat templates/index.yaml 
{{- $hostPorts:=.Values.hostPorts -}}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{.Release.Name}}-configmap
data:
  {{- range $name,$value := .Values.containerPort }}
  {{$name}}: {{index $hostPorts $name|default $value}}
  {{- end}}
[root@master01 test]# helm template . --show-only templates/index.yaml
---
# Source: test/templates/index.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: RELEASE-NAME-configmap
data:
  http: 10
  https: 11
[root@master01 test]# cat templates/slice.yaml 
{{$li:=list 1 2 4}}
slice: {{slice $li 0 1}}
[root@master01 test]# helm template . --show-only templates/slice.yaml
---
# Source: test/templates/slice.yaml
slice: [1]
[root@master01 test]# cat templates/js.yaml 
js: {{js "<script>var a=1;var b=a+1;</script>"}}
[root@master01 test]# helm template . --show-only templates/js.yaml
---
# Source: test/templates/js.yaml
js: \x3Cscript\x3Evar a=1;var b=a+1;\x3C/script\x3E
[root@master01 test]# cat templates/len.yaml 
len: {{len .Values.name}}
[root@master01 test]# helm template . --show-only templates/len.yaml
---
# Source: test/templates/len.yaml
len: 3
[root@master01 test]# cat templates/not.yaml 
{{- if not (gt 1 2)}}
not: true
{{- end}}
[root@master01 test]# helm template . --show-only templates/not.yaml
---
# Source: test/templates/not.yaml
not: true
[root@master01 test]# cat templates/or.yaml 
{{- if or (gt 1 2) (lt 1 2)}}
or: true
{{- end}}
[root@master01 test]# helm template . --show-only templates/or.yaml
---
# Source: test/templates/or.yaml
or: true
[root@master01 test]# cat templates/print.yaml 
apiVersion: v1
kind: ConfigMap
matadata:
  name: {{.Release.Name}}-configMap
data:
  {{- $name:=.Release.Name}}
  name: {{- print $name| trimSuffix "-" -}}
[root@master01 test]# helm template . --show-only templates/print.yaml
---
# Source: test/templates/print.yaml
apiVersion: v1
kind: ConfigMap
matadata:
  name: RELEASE-NAME-configMap
data:
  name:RELEASE-NAME
[root@master01 test]# cat templates/printf.yaml 
apiVersion: v1
kind: ConfigMap
matadata:
  name: {{.Release.Name}}-configmap
data:
  food: {{- printf "%s-%s" .Release.Name .Values.favorite.food|indent 1}}
[root@master01 test]# helm template . --show-only templates/printf.yaml
---
# Source: test/templates/printf.yaml
apiVersion: v1
kind: ConfigMap
matadata:
  name: RELEASE-NAME-configmap
data:
  food: RELEASE-NAME-rice
[root@master01 test]# cat templates/println.yaml 
println: |
  {{println "aaa"}}
bb: cc
[root@master01 test]# helm template . --show-only templates/println.yaml
---
# Source: test/templates/println.yaml
println: |
  aaa

bb: cc
[root@master01 test]# cat templates/urlquery.yaml 
apiVersion: v1
kind: ConfigMap
matadata: 
  name: {{.Release.Name}}-configmap
data:
  password: {{.Values.password|urlquery}}
[root@master01 test]# helm template . --show-only templates/urlquery.yaml
---
# Source: test/templates/urlquery.yaml
apiVersion: v1
kind: ConfigMap
matadata: 
  name: RELEASE-NAME-configmap
data:
  password: http%3A%2F%2Fa.com%2F%3Fid%3D123456
[root@master01 test]# cat templates/eq.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{.Release.Name}}-configmap
data:
  {{- if eq .Values.favorite.food "rice"}}
  like:|
    i like rice.
  {{- end}}
[root@master01 test]# helm template . --show-only templates/eq.yaml
---
# Source: test/templates/eq.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: RELEASE-NAME-configmap
data:
  like:|
    i like rice.
[root@master01 test]# cat templates/ge.yaml 
ge: {{ge 1 2}}
[root@master01 test]# helm template . --show-only templates/ge.yaml
---
# Source: test/templates/ge.yaml
ge: false
[root@master01 test]# cat templates/gt.yaml 
gt: {{gt 4 1}}
[root@master01 test]# helm template . --show-only templates/gt.yaml
---
# Source: test/templates/gt.yaml
gt: true
[root@master01 test]# cat templates/le.yaml 
le: {{le 1 3}}
[root@master01 test]# helm template . --show-only templates/le.yaml
---
# Source: test/templates/le.yaml
le: true
[root@master01 test]# cat templates/lt.yaml 
lt: {{lt  1 3}}
[root@master01 test]# helm template . --show-only templates/lt.yaml
---
# Source: test/templates/lt.yaml
lt: true
[root@master01 test]# cat templates/ne.yaml 
ne: {{ne 1 3}}
[root@master01 test]# helm template . --show-only templates/ne.yaml
---
# Source: test/templates/ne.yaml
ne: true
[root@master01 test]# cat templates/hello.yaml 
hello: {{hello}}
[root@master01 test]# helm template . --show-only templates/hello.yaml
---
# Source: test/templates/hello.yaml
hello: Hello!
[root@master01 test]# cat templates/ago.yaml 
ago: {{ago now}}
[root@master01 test]# helm template . --show-only templates/ago.yaml
---
# Source: test/templates/ago.yaml
ago: 0s
[root@master01 test]# cat templates/date.yaml 
date: {{date "2006-01-02 03:04:05Z" (now) }}
[root@master01 test]# helm template . --show-only templates/date.yaml
---
# Source: test/templates/date.yaml
date: 2020-04-06 11:58:38Z
[root@master01 test]# cat templates/dateInZone.yaml 
dateInZone: {{dateInZone "2006-01-02-03:04:05Z" (now) "UTC"| quote }}
[root@master01 test]# helm template . --show-only templates/dateInZone.yaml
---
# Source: test/templates/dateInZone.yaml
dateInZone: "2020-04-06-03:59:32Z"
[root@master01 test]# cat templates/dateModify.yaml 
dateModify: {{now | date_modify "-1.5h"}}
[root@master01 test]# helm template . --show-only templates/dateModify.yaml
---
# Source: test/templates/dateModify.yaml
dateModify: 2020-04-06 10:30:31.147844281 +0800 CST m=-5397.099595550
[root@master01 test]# cat templates/durationRound.yaml 
durationRound: {{durationRound "200s"}}
[root@master01 test]# helm template . --show-only templates/durationRound.yaml
---
# Source: test/templates/durationRound.yaml
durationRound: 3m
[root@master01 test]# cat templates/htmlDate.yaml 
htmlDate: {{now|htmlDate}}
[root@master01 test]# helm template . --show-only templates/htmlDate.yaml
---
# Source: test/templates/htmlDate.yaml
htmlDate: 2020-04-06
[root@master01 test]# cat templates/htmlDateInZone.yaml 
htmlDateInZone: {{htmlDateInZone now "UTC"}}
[root@master01 test]# helm template . --show-only templates/htmlDateInZone.yaml
---
# Source: test/templates/htmlDateInZone.yaml
htmlDateInZone: 2020-04-06
[root@master01 test]# cat templates/mustDateModify.yaml 
mustDateModify: {{mustDateModify "100s" now}}
[root@master01 test]# helm template . --show-only templates/mustDateModify.yaml
---
# Source: test/templates/mustDateModify.yaml
mustDateModify: 2020-04-06 12:05:50.552467524 +0800 CST m=+100.080912388
[root@master01 test]# cat templates/mustToDate.yaml 
mustToDate: {{mustToDate "2006-01-02 03:04:05" "2020-03-20 12:16:10" }}
[root@master01 test]# helm template . --show-only templates/mustToDate.yaml
---
# Source: test/templates/mustToDate.yaml
mustToDate: 2020-03-20 12:16:10 +0800 CST
[root@master01 test]# cat templates/now.yaml 
now: {{now}}
[root@master01 test]# helm template . --show-only templates/now.yaml
---
# Source: test/templates/now.yaml
now: 2020-04-06 12:06:25.914297532 +0800 CST m=+0.098940471
[root@master01 test]# cat templates/toDate.yaml 
toDate: {{toDate "2006-01-02 03:04:05" "2020-03-20 12:16:10" }}
[root@master01 test]# helm template . --show-only templates/toDate.yaml
---
# Source: test/templates/toDate.yaml
toDate: 2020-03-20 12:16:10 +0800 CST
[root@master01 test]# cat templates/unixEpoch.yaml 
unixEpoch: {{unixEpoch now}}
[root@master01 test]# helm template . --show-only templates/unixEpoch.yaml
---
# Source: test/templates/unixEpoch.yaml
unixEpoch: 1586146082
[root@master01 test]# cat templates/abbrev.yaml 
abbrev: {{"thisismark"|abbrev 5}}
[root@master01 test]# helm template . --show-only templates/abbrev.yaml
---
# Source: test/templates/abbrev.yaml
abbrev: th...
[root@master01 test]# cat templates/abbrevboth.yaml 
abbrevboth: {{"mynameismarkhimarkhowareyou"|abbrevboth 5 10}}
[root@master01 test]# helm template . --show-only templates/abbrevboth.yaml
---
# Source: test/templates/abbrevboth.yaml
abbrevboth: ...eism...
[root@master01 test]# cat templates/trunc.yaml 
apiVersion: v1
kind: ConfigMap
matadata:
  name: {{.Release.Name|trunc 2}}-configmap

[root@master01 test]# helm template . --show-only templates/trunc.yaml
---
# Source: test/templates/trunc.yaml
apiVersion: v1
kind: ConfigMap
matadata:
  name: RE-configmap
[root@master01 test]# cat templates/trim.yaml 
trim: {{"   a b c "|trim}}
[root@master01 test]# helm template . --show-only templates/trim.yaml
---
# Source: test/templates/trim.yaml
trim: a b c
[root@master01 test]# cat templates/upper.yaml 
name: {{.Values.name|upper}}
[root@master01 test]# helm template . --show-only templates/upper.yaml
---
# Source: test/templates/upper.yaml
name: TOM
[root@master01 test]# cat templates/lower.yaml 
lower: {{lower "ABC"}}
[root@master01 test]# helm template . --show-only templates/lower.yaml
---
# Source: test/templates/lower.yaml
lower: abc
[root@master01 test]# cat templates/title.yaml 
title: {{"my name is mark"|title}}
[root@master01 test]# helm template . --show-only templates/title.yaml
---
# Source: test/templates/title.yaml
title: My Name Is Mark
[root@master01 test]# cat templates/untitle.yaml 
untitle: {{"My Name is mark"|untitle}}
[root@master01 test]# helm template . --show-only templates/untitle.yaml
---
# Source: test/templates/untitle.yaml
untitle: my name is mark
[root@master01 test]# cat templates/substr.yaml 
substr: {{"thisisastring"|substr 1 10 }}
[root@master01 test]# helm template . --show-only templates/substr.yaml
---
# Source: test/templates/substr.yaml
substr: hisisastr
[root@master01 test]# cat templates/repeat.yaml 
repeat: {{"mark"|repeat 5}}
[root@master01 test]# helm template . --show-only templates/repeat.yaml
---
# Source: test/templates/repeat.yaml
repeat: markmarkmarkmarkmark
[root@master01 test]# cat templates/trimAll.yaml 
trimAll: {{"_markhuang_"|trimAll "_"}}
[root@master01 test]# helm template . --show-only templates/trimAll.yaml
---
# Source: test/templates/trimAll.yaml
trimAll: markhuang
[root@master01 test]# cat templates/trimSuffix.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{.Release.Name|trimSuffix "-"}}
[root@master01 test]# helm template . --show-only templates/trimSuffix.yaml
---
# Source: test/templates/trimSuffix.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: RELEASE-NAME
[root@master01 test]# cat templates/trimPrefix.yaml 
trimPrefix: {{trimPrefix "-" "-abc"}}
[root@master01 test]# helm template . --show-only templates/trimPrefix.yaml
---
# Source: test/templates/trimPrefix.yaml
trimPrefix: abc
[root@master01 test]# cat templates/nospace.yaml 
nospace: {{" this is mark "|nospace}}
[root@master01 test]# helm template . --show-only templates/nospace.yaml
---
# Source: test/templates/nospace.yaml
nospace: thisismark
[root@master01 test]# cat templates/initials.yaml 
initials: {{"my name is mark"|initials}}
[root@master01 test]# helm template . --show-only templates/initials.yaml
---
# Source: test/templates/initials.yaml
initials: mnim
[root@master01 test]# cat templates/randAlphaNum.yaml 
password: {{ randAlphaNum 10}}
[root@master01 test]# helm template . --show-only templates/randAlphaNum.yaml
---
# Source: test/templates/randAlphaNum.yaml
password: X9tDGihZOB
[root@master01 test]# cat templates/randAlpha.yaml 
randAlpha: {{randAlpha 10}}
[root@master01 test]# helm template . --show-only templates/randAlpha.yaml
---
# Source: test/templates/randAlpha.yaml
randAlpha: gxiVFaeSwg
[root@master01 test]# cat templates/randAscii.yaml 
#randAscii: "{{randAscii 10}}"
[root@master01 test]# helm template . --show-only templates/randAscii.yaml
---
# Source: test/templates/randAscii.yaml
#randAscii: "Jjd.?@GS{e"
[root@master01 test]# cat templates/randNumeric.yaml 
randNumeric: {{randNumeric 10}}
[root@master01 test]# helm template . --show-only templates/randNumeric.yaml
---
# Source: test/templates/randNumeric.yaml
randNumeric: 2491395608
[root@master01 test]# cat templates/swapcase.yaml 
swapcase: {{swapcase "My Name is mark"}}
[root@master01 test]# helm template . --show-only templates/swapcase.yaml
---
# Source: test/templates/swapcase.yaml
swapcase: mY nAME IS MARK
[root@master01 test]# cat templates/shuffle.yaml 
shuffle: {{.Values.shuffle|shuffle}}
[root@master01 test]# helm template . --show-only templates/shuffle.yaml
---
# Source: test/templates/shuffle.yaml
shuffle: kmaimamrnsye
[root@master01 test]# cat templates/snakecase.yaml 
snake: {{.Values.snake|snakecase}}
[root@master01 test]# helm template . --show-only templates/snakecase.yaml
---
# Source: test/templates/snakecase.yaml
snake: shared_buffers
[root@master01 test]# cat templates/camelcase.yaml 
camel: {{.Values.camel|camelcase}}
[root@master01 test]# helm template . --show-only templates/camelcase.yaml
---
# Source: test/templates/camelcase.yaml
camel: MyNameIsMark
[root@master01 test]# cat templates/kebabcase.yaml 
kebabcase: {{kebabcase "MyNameIsMark"}}
[root@master01 test]# helm template . --show-only templates/kebabcase.yaml
---
# Source: test/templates/kebabcase.yaml
kebabcase: my-name-is-mark
[root@master01 test]# cat templates/wrap.yaml 
wrap: |
  {{wrap 5 "markhuang"}}
[root@master01 test]# helm template . --show-only templates/wrap.yaml
---
# Source: test/templates/wrap.yaml
wrap: |
  markhuang
[root@master01 test]# cat templates/wrapWith.yaml 
wrapWith: |
  {{"markhuang"|wrapWith 3 "p"}}
[root@master01 test]# helm template . --show-only templates/wrapWith.yaml
---
# Source: test/templates/wrapWith.yaml
wrapWith: |
  marpkhupang
[root@master01 test]# cat templates/contains.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-configmap
data:
  {{- $name:= .Release.Name  -}}
  {{- if contains $name "hxpmark"}}
  name: hxpmark
  {{- end}}
[root@master01 test]# helm template hxp . --show-only templates/contains.yaml
---
# Source: test/templates/contains.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: hxp-configmap
data:
  name: hxpmark
[root@master01 test]# cat templates/hasPrefix.yaml 
{{- if hasPrefix "http" .Values.url}}
url: {{.Values.url}}
{{- else}}
url: {{printf "%s://%s" "http" .Values.url}}
{{- end}}
[root@master01 test]# helm template . --show-only templates/hasPrefix.yaml
---
# Source: test/templates/hasPrefix.yaml
url: http://www.baidu.com
[root@master01 test]# cat templates/hasSuffix.yaml 
{{- if hasSuffix "-" "mark-"}}
hasSuffix: mark-
{{- end}}
[root@master01 test]# helm template . --show-only templates/hasSuffix.yaml
---
# Source: test/templates/hasSuffix.yaml
hasSuffix: mark-
[root@master01 test]# cat  templates/quote.yaml 
quote: {{quote "mark"}}
[root@master01 test]# helm template . --show-only templates/quote.yaml
---
# Source: test/templates/quote.yaml
quote: "mark"
[root@master01 test]# cat templates/squote.yaml 
squote: {{"mark"|squote}}
[root@master01 test]# helm template . --show-only templates/squote.yaml
---
# Source: test/templates/squote.yaml
squote: 'mark'
[root@master01 test]# cat templates/cat.yaml 
cat: {{cat "my" "name" "is" "mark"}}
[root@master01 test]# helm template . --show-only templates/cat.yaml
---
# Source: test/templates/cat.yaml
cat: my name is mark
[root@master01 test]# cat templates/indent.yaml 
indent: {{"mark"|indent 2}}
[root@master01 test]# helm template . --show-only templates/indent.yaml
---
# Source: test/templates/indent.yaml
indent:   mark
[root@master01 test]# ^C
[root@master01 test]# cat templates/nindent.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{.Release.Name}}-configmap
data:
  rules:{{ toYaml .Values.rules|nindent 2}}
[root@master01 test]# helm template . --show-only templates/nindent.yaml
---
# Source: test/templates/nindent.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: RELEASE-NAME-configmap
data:
  rules:
  - rule1: aa
  - rule2: bb
[root@master01 test]# cat templates/replace.yaml 
apiVersion: v1
kind: ConfigMap
matadata:
  name: {{.Release.Name|replace "+" "_"}}
[root@master01 test]# helm template hxp+mark . --show-only templates/replace.yaml
---
# Source: test/templates/replace.yaml
apiVersion: v1
kind: ConfigMap
matadata:
  name: hxp_mark
[root@master01 test]# cat templates/plural.yaml 
plural: {{plural "sigle" "plural" 3}}
[root@master01 test]# helm template . --show-only templates/plural.yaml
---
# Source: test/templates/plural.yaml
plural: plural
[root@master01 test]# cat templates/sha1sum.yaml 
sha1sum: {{sha1sum "abc"}}
[root@master01 test]# helm template . --show-only templates/sha1sum.yaml
---
# Source: test/templates/sha1sum.yaml
sha1sum: a9993e364706816aba3e25717850c26c9cd0d89d
[root@master01 test]# cat templates/sha256sum.yaml 
sha256sum: {{sha256sum "abc"}}
[root@master01 test]# helm template . --show-only templates/sha256sum.yaml
---
# Source: test/templates/sha256sum.yaml
sha256sum: ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
[root@master01 test]# cat templates/adler32sum.yaml 
adler32sum: {{adler32sum "mark"}}
[root@master01 test]# helm template . --show-only templates/adler32sum.yaml
---
# Source: test/templates/adler32sum.yaml
adler32sum: 69861804
[root@master01 test]# cat templates/toString.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{.Release.Name}}-configmap
data:
  toString: {{.Values.minReplicas|toString}}
[root@master01 test]# helm template . --show-only templates/toString.yaml
---
# Source: test/templates/toString.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: RELEASE-NAME-configmap
data:
  toString: 1
[root@master01 test]# cat templates/atoi.yaml 
atoi: {{atoi "ssss"}}
[root@master01 test]# helm template . --show-only templates/atoi.yaml
---
# Source: test/templates/atoi.yaml
atoi: 0
[root@master01 test]# cat templates/int64.yaml 
int64: {{int64 "65"}}
[root@master01 test]# helm template . --show-only templates/int64.yaml
---
# Source: test/templates/int64.yaml
int64: 65
[root@master01 test]# cat templates/int.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{.Release.Name}}-configmap
data:
{{- if (gt (.Values.minReplicas|int) 0)}}
  minReplicas: {{.Values.minReplicas|int}}
{{- end}}
{{- if (gt (.Values.maxReplicas|int) 0)}}
  maxReplicas: {{.Values.maxReplicas}}
{{- end}}
[root@master01 test]# helm template . --show-only templates/int.yaml
---
# Source: test/templates/int.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: RELEASE-NAME-configmap
data:
  minReplicas: 1
  maxReplicas: 5
[root@master01 test]# cat templates/float64.yaml 
float64: {{float64 "3.14"}}
[root@master01 test]# helm template . --show-only templates/float64.yaml
---
# Source: test/templates/float64.yaml
float64: 3.14
[root@master01 test]# cat templates/toDecimal.yaml 
toDecimal: {{toDecimal 27}}
[root@master01 test]# helm template . --show-only templates/toDecimal.yaml
---
# Source: test/templates/toDecimal.yaml
toDecimal: 23
[root@master01 test]# cat templates/split.yaml 
{{$dic:=split "," "my,name,is,mark"}}
{{- range $key,$value:= $dic}}
{{$key}}: {{$value}}
{{- end}}
[root@master01 test]# helm template . --show-only templates/split.yaml
---
# Source: test/templates/split.yaml
_0: my
_1: name
_2: is
_3: mark
[root@master01 test]# cat templates/splitList.yaml 
{{$list:=splitList "," "my,name,is,mark"}}
{{- range $list}}
name: {{.}}
{{- end}}
[root@master01 test]# helm template . --show-only templates/splitList.yaml
---
# Source: test/templates/splitList.yaml
name: my
name: name
name: is
name: mark
[root@master01 test]# cat templates/splitn.yaml 
splitn: {{splitn "_" 2 "a_b_c_d" }}
[root@master01 test]# helm template . --show-only templates/splitn.yaml
---
# Source: test/templates/splitn.yaml
splitn: map[_0:a _1:b_c_d]
[root@master01 test]# cat templates/toStrings.yaml 
{{- $li:=list 1 2 3}}
toStrings: {{toStrings $li}}
[root@master01 test]# helm template . --show-only templates/toStrings.yaml
---
# Source: test/templates/toStrings.yaml
toStrings: [1 2 3]
[root@master01 test]# cat templates/until.yaml 
until: {{until 10}}
[root@master01 test]# helm template . --show-only templates/until.yaml
---
# Source: test/templates/until.yaml
until: [0 1 2 3 4 5 6 7 8 9]
[root@master01 test]# cat templates/untilStep.yaml 
untilStep: {{untilStep 1 10 2}}
[root@master01 test]# helm template . --show-only templates/untilStep.yaml
---
# Source: test/templates/untilStep.yaml
untilStep: [1 3 5 7 9]
[root@master01 test]# cat templates/add1.yaml 
add1: {{add1 1}}
[root@master01 test]# helm template . --show-only templates/add1.yaml
---
# Source: test/templates/add1.yaml
add1: 2
[root@master01 test]# cat templates/add.yaml 
{{$sum:=add 10 20}}
sum: {{$sum}}
[root@master01 test]# helm template . --show-only templates/add.yaml
---
# Source: test/templates/add.yaml
sum: 30
[root@master01 test]# cat templates/sub.yaml 
sub: {{sub 10 5}}
[root@master01 test]# helm template . --show-only templates/sub.yaml
---
# Source: test/templates/sub.yaml
sub: 5
[root@master01 test]# cat templates/div.yaml 
div: {{div 10 2}}
[root@master01 test]# helm template . --show-only templates/div.yaml
---
# Source: test/templates/div.yaml
div: 5
[root@master01 test]# cat templates/mod.yaml 
mod: {{mod 10 3}}
[root@master01 test]# helm template . --show-only templates/mod.yaml
---
# Source: test/templates/mod.yaml
mod: 1
[root@master01 test]# cat templates/mul.yaml 
mul: {{mul 3 3}}
[root@master01 test]# helm template . --show-only templates/mul.yaml
---
# Source: test/templates/mul.yaml
mul: 9
[root@master01 test]# cat templates/biggest.yaml 
biggest: {{biggest 1 3 10 4 }}
[root@master01 test]# helm template . --show-only templates/biggest.yaml
---
# Source: test/templates/biggest.yaml
biggest: 10
[root@master01 test]# cat templates/max.yaml 
max: {{max 1 31 99 2}}
[root@master01 test]# helm template . --show-only templates/max.yaml
---
# Source: test/templates/max.yaml
max: 99
[root@master01 test]# cat templates/min.yaml 
min: {{min 1 3 7 5}}
[root@master01 test]# helm template . --show-only templates/min.yaml
---
# Source: test/templates/min.yaml
min: 1
[root@master01 test]# cat templates/ceil.yaml 
ceil: {{ceil 3.932}}
[root@master01 test]# helm template . --show-only templates/ceil.yaml
---
# Source: test/templates/ceil.yaml
ceil: 4
[root@master01 test]# cat templates/floor.yaml 
floor: {{floor 3.91}}
[root@master01 test]# helm template . --show-only templates/floor.yaml
---
# Source: test/templates/floor.yaml
floor: 3
[root@master01 test]# cat templates/round.yaml 
round: {{round 3.6 0 }}
round2: {{round 3.2 0 }}
[root@master01 test]# helm template . --show-only templates/round.yaml
---
# Source: test/templates/round.yaml
round: 4
round2: 3
[root@master01 test]# cat templates/join.yaml 
{{- $li:=list 1 2 3}}
join: {{join "_"  $li }}
[root@master01 test]# helm template . --show-only templates/join.yaml
---
# Source: test/templates/join.yaml
join: 1_2_3
[root@master01 test]# cat templates/sortAlpha.yaml 
{{$list:=list}}
{{$list:=append $list "my"}}
{{$list:=append $list "name"}}
{{$list:=append $list "is"}}
{{$list:=append $list "mark"}}
{{$list:=sortAlpha $list}}
{{- range  $list}}
name: {{.}}
{{- end}}
[root@master01 test]# helm template . --show-only templates/sortAlpha.yaml
---
# Source: test/templates/sortAlpha.yaml
name: is
name: mark
name: my
name: name
[root@master01 test]# cat templates/default.yaml 
default: {{default 100 ""}}
[root@master01 test]# helm template . --show-only templates/default.yaml
---
# Source: test/templates/default.yaml
default: 100
[root@master01 test]# cat templates/empty.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{.Release.Name}}-configmap
data:
  {{- if not (empty .Values.favorite.fruit) }}
  fruit: {{.Values.favorite.fruit}}
  {{- end}}
[root@master01 test]# helm template . --show-only templates/empty.yaml
---
# Source: test/templates/empty.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: RELEASE-NAME-configmap
data:
[root@master01 test]# cat templates/coalesce.yaml 
coalesce: {{coalesce "" "" "1" "2"}}
[root@master01 test]# helm template . --show-only templates/coalesce.yaml
---
# Source: test/templates/coalesce.yaml
coalesce: 1
[root@master01 test]# cat templates/compact.yaml 
{{- $li:=list "1" ""  "2" "" "3"}}
compact: {{compact $li}}
[root@master01 test]# helm template . --show-only templates/compact.yaml
---
# Source: test/templates/compact.yaml
compact: [1 2 3]
[root@master01 test]# cat templates/mustCompact.yaml 
{{- $li:=list "1" ""  "2" "" "3"}}
mustCompact: {{mustCompact $li}}
[root@master01 test]# helm template . --show-only templates/mustCompact.yaml
---
# Source: test/templates/mustCompact.yaml
mustCompact: [1 2 3]
[root@master01 test]# cat templates/toJson.yaml 
json: {{.Values.json|toJson}}
[root@master01 test]# helm template . --show-only templates/toJson.yaml
---
# Source: test/templates/toJson.yaml
json: {"aa":"bb","cc":"dd"}
[root@master01 test]# cat templates/toPrettyJson.yaml 
json: {{.Values.json|toPrettyJson}}
[root@master01 test]# helm template . --show-only templates/toPrettyJson.yaml
---
# Source: test/templates/toPrettyJson.yaml
json: {
  "aa": "bb",
  "cc": "dd"
}
[root@master01 test]# cat templates/toRawJson.yaml 
json: {{.Values.json|toRawJson}}
[root@master01 test]# helm template . --show-only templates/toRawJson.yaml
---
# Source: test/templates/toRawJson.yaml
json: {"aa":"bb","cc":"dd"}
[root@master01 test]# cat templates/mustToJson.yaml 
json: {{.Values.json|mustToJson}}
[root@master01 test]# helm template . --show-only templates/mustToJson.yaml
---
# Source: test/templates/mustToJson.yaml
json: {"aa":"bb","cc":"dd"}
[root@master01 test]# cat templates/mustToPrettyJson.yaml 
json: {{.Values.json|mustToPrettyJson}}
[root@master01 test]# helm template . --show-only templates/mustToPrettyJson.yaml
---
# Source: test/templates/mustToPrettyJson.yaml
json: {
  "aa": "bb",
  "cc": "dd"
}
[root@master01 test]# cat templates/mustToRawJson.yaml 
json: {{.Values.json|mustToRawJson}}
[root@master01 test]# helm template . --show-only templates/mustToRawJson.yaml
---
# Source: test/templates/mustToRawJson.yaml
json: {"aa":"bb","cc":"dd"}
[root@master01 test]# cat templates/ternary.yaml 
value: {{ ternary "1" "0" .Values.debug | quote }}
[root@master01 test]# helm template . --show-only templates/ternary.yaml
---
# Source: test/templates/ternary.yaml
value: "1"
[root@master01 test]# cat templates/deepCopy.yaml 
{{- $li:=list 1 2 3}}
deepCopy: {{deepCopy $li}}
[root@master01 test]# helm template . --show-only templates/deepCopy.yaml
---
# Source: test/templates/deepCopy.yaml
deepCopy: [1 2 3]
[root@master01 test]# cat templates/mustDeepCopy.yaml 
{{- $li:=list 1 2 3}}
mustDeepCopy: {{mustDeepCopy $li}}

[root@master01 test]# helm template . --show-only templates/mustDeepCopy.yaml
---
# Source: test/templates/mustDeepCopy.yaml
mustDeepCopy: [1 2 3]
[root@master01 test]# cat templates/typeOf.yaml 
typeOf: {{typeOf 123}}
[root@master01 test]# helm template . --show-only templates/typeOf.yaml
---
# Source: test/templates/typeOf.yaml
typeOf: int
[root@master01 test]# cat templates/typeIs.yaml 
{{- if typeIs "int" 123}}
typeIs: int 123
{{- end}}
[root@master01 test]# helm template . --show-only templates/typeIs.yaml
---
# Source: test/templates/typeIs.yaml
typeIs: int 123
[root@master01 test]# cat templates/typeIsLike.yaml 
{{- if typeIsLike "int" 123}}
typeIsLike: int 123
{{- end}}
[root@master01 test]# helm template . --show-only templates/typeIsLike.yaml
---
# Source: test/templates/typeIsLike.yaml
typeIsLike: int 123
[root@master01 test]# cat templates/kindOf.yaml 
kindOf: {{kindOf 123}}
[root@master01 test]# helm template . --show-only templates/kindOf.yaml
---
# Source: test/templates/kindOf.yaml
kindOf: int
[root@master01 test]# cat templates/kindIs.yaml 
{{- if kindIs "int" 123}}
kindIs: int 123
{{- end}}
[root@master01 test]# helm template . --show-only templates/kindIs.yaml
---
# Source: test/templates/kindIs.yaml
kindIs: int 123
[root@master01 test]# cat templates/deepEqual.yaml 
{{- $li:=list 1 2 3}}
{{- $li2:=list 1 2 3}}
deepEqual: {{deepEqual $li $li2}}
[root@master01 test]# helm template . --show-only templates/deepEqual.yaml
---
# Source: test/templates/deepEqual.yaml
deepEqual: true
[root@master01 test]# cat templates/getHostByName.yaml 
getHostByName: {{getHostByName "www.baidu.com"}}
[root@master01 test]# helm template . --show-only templates/getHostByName.yaml
---
# Source: test/templates/getHostByName.yaml
getHostByName: 36.152.44.95
[root@master01 test]# cat templates/base.yaml 
base: {{base .Values.path}}
[root@master01 test]# helm template . --show-only templates/base.yaml
---
# Source: test/templates/base.yaml
base: aa
[root@master01 test]# cat templates/dir.yaml 
dir: {{dir "/etc/fstab"}}
[root@master01 test]# helm template . --show-only templates/dir.yaml
---
# Source: test/templates/dir.yaml
dir: /etc
[root@master01 test]# cat templates/clean.yaml 
clean: {{clean "/etc/systemd/system/"}}
[root@master01 test]# helm template . --show-only templates/clean.yaml
---
# Source: test/templates/clean.yaml
clean: /etc/systemd/system
[root@master01 test]# cat templates/ext.yaml 
ext: {{ ext "/a/b/c.yaml"}}
[root@master01 test]# helm template . --show-only templates/ext.yaml
---
# Source: test/templates/ext.yaml
ext: .yaml
[root@master01 test]# cat templates/isAbs.yaml 
{{- if isAbs "/etc/"}}
isAbs: /etc/
{{- end}}
[root@master01 test]# helm template . --show-only templates/isAbs.yaml
---
# Source: test/templates/isAbs.yaml
isAbs: /etc/
[root@master01 test]# cat templates/b64enc.yaml 
b64enc: {{b64enc "123"}}
[root@master01 test]# helm template . --show-only templates/b64enc.yaml
---
# Source: test/templates/b64enc.yaml
b64enc: MTIz
[root@master01 test]# cat templates/b64dec.yaml 
b64dec: {{"123"|b64enc|b64dec}}
[root@master01 test]# helm template . --show-only templates/b64dec.yaml
---
# Source: test/templates/b64dec.yaml
b64dec: 123
[root@master01 test]# cat templates/b32enc.yaml 
b32enc: {{b32enc "123"}}
[root@master01 test]# helm template . --show-only templates/b32enc.yaml
---
# Source: test/templates/b32enc.yaml
b32enc: GEZDG===
[root@master01 test]# cat templates/b32dec.yaml 
b32dec: {{b32enc "123"|b32dec}}
[root@master01 test]# helm template . --show-only templates/b32dec.yaml
---
# Source: test/templates/b32dec.yaml
b32dec: 123
[root@master01 test]# cat templates/tuple.yaml 
{{- $message:=tuple}}
{{- $message:=append $message "abc" }}
{{- $message:=append $message  "xyz"}}
{{- $message:=append $message  "xxx"}}
{{- $message:=without $message "xxx"}}
{{- $message:= join "$" $message}}
tuple: {{$message}}
[root@master01 test]# helm template . --show-only templates/tuple.yaml
---
# Source: test/templates/tuple.yaml
tuple: abc$xyz
[root@master01 test]# cat templates/list.yaml 
{{- $message:=list}}
{{- $message:=append $message "abc" }}
{{- $message:=append $message  "xyz"}}
{{- $message:=append $message  "xxx"}}
{{- $message:=without $message "xxx"}}
{{- $message:= join "$" $message}}
list: {{$message}}
[root@master01 test]# helm template . --show-only templates/list.yaml
---
# Source: test/templates/list.yaml
list: abc$xyz
[root@master01 test]# cat templates/dict.yaml 
name: {{ include "harbor.tplValue" ( dict "value" .Values.name "context" $) }}
[root@master01 test]# helm template . --show-only templates/dict.yaml
---
# Source: test/templates/dict.yaml
name: Tom
[root@master01 test]# cat templates/get.yaml 
{{- $di:=dict "aa" "av" "bb" "bv"}}
get: {{get $di "aa"}}
[root@master01 test]# helm template . --show-only templates/get.yaml
---
# Source: test/templates/get.yaml
get: av
[root@master01 test]# cat templates/set.yaml 
{{- $_ := set . "portal_path" "/*" -}}
{{- $_ := set . "api_path" "/api/*" -}}
{{- $_ := set . "service_path" "/service/*" -}}
{{- $_ := set . "v2_path" "/v2/*" -}}
{{- $_ := set . "chartrepo_path" "/chartrepo/*" -}}
{{- $_ := set . "controller_path" "/c/*" -}}
portal_path: {{.portal_path}}
api_path: {{.api_path}}
service_path: {{.service_path}}
v2_path: {{.v2_path}}
chartrepo_path: {{.chartrepo_path}}
controller_path: {{.controller_path}}
[root@master01 test]# ^C
[root@master01 test]# helm template . --show-only templates/set.yaml
---
# Source: test/templates/set.yaml
portal_path: /*
api_path: /api/*
service_path: /service/*
v2_path: /v2/*
chartrepo_path: /chartrepo/*
controller_path: /c/*
[root@master01 test]# cat templates/unset.yaml 
{{- $di:=dict "aa" "av" "bb" "bv" }}
dict: {{$di}}
dict: {{ unset $di "aa"}}
dict: {{$di}}
[root@master01 test]# helm template . --show-only templates/unset.yaml
---
# Source: test/templates/unset.yaml
dict: map[aa:av bb:bv]
dict: map[bb:bv]
dict: map[bb:bv]
[root@master01 test]# cat templates/hasKey.yaml 
{{- $di:=dict "aa" "av" "bb" "bv"}}
hasKey: {{hasKey $di "aa"}}
[root@master01 test]# helm template . --show-only templates/hasKey.yaml
---
# Source: test/templates/hasKey.yaml
hasKey: true
[root@master01 test]# cat templates/pluck.yaml 
{{- $d1:=dict "aa" "a1" "bb" "b1"}}
{{- $d2:=dict "aa" "a2" "bb" "b2"}}
pluck: {{pluck "aa" $d1 $d2}}
[root@master01 test]# helm template . --show-only templates/pluck.yaml
---
# Source: test/templates/pluck.yaml
pluck: [a1 a2]
[root@master01 test]# cat templates/keys.yaml 
{{- $d1:=dict "aa" "a1" "bb" "b1"}}
{{- $d2:=dict "a2" "a2" "b2" "b2"}}
keys: {{keys $d1 $d2}}
[root@master01 test]# helm template . --show-only templates/keys.yaml
---
# Source: test/templates/keys.yaml
keys: [aa bb a2 b2]
[root@master01 test]# cat templates/pick.yaml 
{{- $d1:=dict "aa" "a1" "bb" "b1" "cc" "c1"}}
pick: {{pick $d1 "aa" "cc"}}
[root@master01 test]# helm template . --show-only templates/pick.yaml
---
# Source: test/templates/pick.yaml
pick: map[aa:a1 cc:c1]
[root@master01 test]# cat templates/omit.yaml 
{{- $d1:=dict "aa" "a1" "bb" "b1"}}
omit: {{omit $d1 "aa"}}
[root@master01 test]# helm template . --show-only templates/omit.yaml
---
# Source: test/templates/omit.yaml
omit: map[bb:b1]
[root@master01 test]# cat templates/merge.yaml 
{{- $target:=dict}}
{{- $src1:=dict "a1" "a1" "b1" "b1"}}
{{- $src2:=dict "a2" "a2" "b2" "b2"}}
merge: {{merge $target $src1 $src2}}
[root@master01 test]# helm template . --show-only templates/merge.yaml
---
# Source: test/templates/merge.yaml
merge: map[a1:a1 a2:a2 b1:b1 b2:b2]
[root@master01 test]# cat templates/mergeOverwrite.yaml 
{{- $target:=dict}}
{{- $src1:=dict "a1" "a1" "b1" "b1"}}
{{- $src2:=dict "a1" "a2" "b2" "b2"}}
mergeOverwrite: {{mergeOverwrite $target $src1 $src2}}
[root@master01 test]# helm template . --show-only templates/mergeOverwrite.yaml
---
# Source: test/templates/mergeOverwrite.yaml
mergeOverwrite: map[a1:a2 b1:b1 b2:b2]
[root@master01 test]# cat templates/mustMerge.yaml 
{{- $target:=dict}}
{{- $src1:=dict "a1" "a1" "b1" "b1"}}
{{- $src2:=dict "a2" "a2" "b2" "b2"}}
mustMerge: {{mustMerge $target $src1 $src2}}
[root@master01 test]# helm template . --show-only templates/mustMerge.yaml
---
# Source: test/templates/mustMerge.yaml
mustMerge: map[a1:a1 a2:a2 b1:b1 b2:b2]
[root@master01 test]# cat templates/mustMergeOverwrite.yaml 
{{- $target:=dict}}
{{- $src1:=dict "a1" "a1" "b1" "b1"}}
{{- $src2:=dict "a1" "a2" "b2" "b2"}}
mustMergeOverwrite: {{mustMergeOverwrite $target $src1 $src2}}
[root@master01 test]# helm template . --show-only templates/mustMergeOverwrite.yaml
---
# Source: test/templates/mustMergeOverwrite.yaml
mustMergeOverwrite: map[a1:a2 b1:b1 b2:b2]
[root@master01 test]# cat templates/values.yaml 
{{- $di:=dict "aa" "av" "bb" "bv"}}
values: {{values $di}}
[root@master01 test]# helm template . --show-only templates/values.yaml
---
# Source: test/templates/values.yaml
values: [av bv]
[root@master01 test]# helm template . --show-only templates/values.yaml
---
# Source: test/templates/values.yaml
values: [av bv]
[root@master01 test]# ^C
[root@master01 test]# cat templates/listAndFunc.yaml 
{{$li:=list}}
{{$li:=append $li 1}}
{{$li:=append $li 2}}
{{$li:=prepend $li 3}}
{{$li:=prepend $li 4}}
all: {{$li}}
first: {{first $li}}
rest: {{rest $li}}
last: {{last $li}}
initial: {{initial $li}}
{{- $li:=reverse $li}}
all: {{$li}}
{{- $li:= append $li 1 }}
all: {{$li}}
{{- $li:=uniq $li }}
uniq: {{$li}}
{{- $li:= without $li 1}}
without: {{$li}}
{{- if (has 2 $li)}}
has: 2
{{- end}}
[root@master01 test]# helm template . --show-only templates/listAndFunc.yaml
---
# Source: test/templates/listAndFunc.yaml
all: [4 3 1 2]
first: 4
rest: [3 1 2]
last: 2
initial: [4 3 1]
all: [2 1 3 4]
all: [2 1 3 4 1]
uniq: [2 1 3 4]
without: [2 3 4]
has: 2
[root@master01 test]# cat templates/append.yaml 
{{$li:=list}}
{{$li:=append $li 1}}
{{$li:=append $li 2}}
all: {{$li}}
[root@master01 test]# helm template . --show-only templates/append.yaml
---
# Source: test/templates/append.yaml
all: [1 2]
[root@master01 test]# cat templates/push.yaml 
{{$li:=list}}
{{$li:=push $li 1}}
{{$li:=push $li 2}}
all: {{$li}}
[root@master01 test]# helm template . --show-only templates/push.yaml
---
# Source: test/templates/push.yaml
all: [1 2]
[root@master01 test]# cat templates/mustAppend.yaml 
{{$li:=list}}
{{$li:=mustAppend $li 1}}
{{$li:=mustAppend $li 2}}
all: {{$li}}
[root@master01 test]# helm template . --show-only templates/mustAppend.yaml
---
# Source: test/templates/mustAppend.yaml
all: [1 2]
[root@master01 test]# cat templates/mustPush.yaml 
{{$li:=list}}
{{$li:=mustPush $li 1}}
{{$li:=mustPush $li 2}}
all: {{$li}}
[root@master01 test]# helm template . --show-only templates/mustPush.yaml
---
# Source: test/templates/mustPush.yaml
all: [1 2]
[root@master01 test]# cat templates/prepend.yaml 
{{$li:=list}}
{{$li:=prepend $li 1}}
{{$li:=prepend $li 2}}
all: {{$li}}
[root@master01 test]# helm template . --show-only templates/prepend.yaml
---
# Source: test/templates/prepend.yaml
all: [2 1]
[root@master01 test]# cat templates/mustPrepend.yaml 
{{$li:=list}}
{{$li:=mustPrepend $li 1}}
{{$li:=mustPrepend $li 2}}
all: {{$li}}
[root@master01 test]# helm template . --show-only templates/mustPrepend.yaml
---
# Source: test/templates/mustPrepend.yaml
all: [2 1]
[root@master01 test]# cat templates/first.yaml 
{{$li:=list 1 2 4}}
first: {{first $li}}
[root@master01 test]# helm template . --show-only templates/first.yaml
---
# Source: test/templates/first.yaml
first: 1
[root@master01 test]# cat templates/mustFirst.yaml 
{{$li:=list 1 2 4}}
mustFirst: {{mustFirst $li}}
[root@master01 test]# helm template . --show-only templates/mustFirst.yaml
---
# Source: test/templates/mustFirst.yaml
mustFirst: 1
[root@master01 test]# cat templates/rest.yaml 
{{$li:=list 1 2 4}}
rest: {{rest $li}}
[root@master01 test]# helm template . --show-only templates/rest.yaml
---
# Source: test/templates/rest.yaml
rest: [2 4]
[root@master01 test]# cat templates/mustRest.yaml 
{{$li:=list 1 2 4}}
mustRest: {{mustRest $li}}
[root@master01 test]# helm template . --show-only templates/mustRest.yaml
---
# Source: test/templates/mustRest.yaml
mustRest: [2 4]
[root@master01 test]# cat templates/last.yaml 
{{$li:=list 1 2 4}}
last: {{last $li}}
[root@master01 test]# helm template . --show-only templates/last.yaml
---
# Source: test/templates/last.yaml
last: 4
[root@master01 test]# cat templates/mustLast.yaml 
{{$li:=list 1 2 4}}
mustLast: {{mustLast $li}}
[root@master01 test]# helm template . --show-only templates/mustLast.yaml
---
# Source: test/templates/mustLast.yaml
mustLast: 4
[root@master01 test]# cat templates/initial.yaml 
{{$li:=list 1 2 4}}
initial: {{initial $li}}
[root@master01 test]# helm template . --show-only templates/initial.yaml
---
# Source: test/templates/initial.yaml
initial: [1 2]
[root@master01 test]# cat templates/mustInitial.yaml 
{{$li:=list 1 2 4}}
mustInitial: {{mustInitial $li}}
[root@master01 test]# helm template . --show-only templates/mustInitial.yaml
---
# Source: test/templates/mustInitial.yaml
mustInitial: [1 2]
[root@master01 test]# cat templates/reverse.yaml 
{{$li:=list 1 2 3}}
{{- $li:=reverse $li}}
reverse: ${{$li}}
[root@master01 test]# helm template . --show-only templates/reverse.yaml
---
# Source: test/templates/reverse.yaml
reverse: $[3 2 1]
[root@master01 test]# cat templates/mustReverse.yaml 
{{$li:=list 1 2 3}}
{{- $li:=mustReverse $li}}
mustReverse: ${{$li}}
[root@master01 test]# helm template . --show-only templates/mustReverse.yaml
---
# Source: test/templates/mustReverse.yaml
mustReverse: $[3 2 1]
[root@master01 test]# cat templates/uniq.yaml 
{{$li:=list 1 2 4 1}}
all: {{$li}}
uniq: {{uniq $li}}
[root@master01 test]# helm template . --show-only templates/uniq.yaml
---
# Source: test/templates/uniq.yaml
all: [1 2 4 1]
uniq: [1 2 4]
root@master01 test]# cat templates/mustUniq.yaml 
{{$li:=list 1 2 4 1}}
all: {{$li}}
mustUniq: {{mustUniq $li}}
[root@master01 test]# helm template . --show-only templates/mustUniq.yaml
---
# Source: test/templates/mustUniq.yaml
all: [1 2 4 1]
mustUniq: [1 2 4]
[root@master01 test]# cat templates/without.yaml 
{{$li:=list 1 2 3}}
without: {{without $li 3}}
[root@master01 test]# helm template . --show-only templates/without.yaml
---
# Source: test/templates/without.yaml
without: [1 2]
[root@master01 test]# cat templates/mustWithout.yaml 
{{$li:=list 1 2 3}}
mustWithout: {{mustWithout $li 3}}
[root@master01 test]# helm template . --show-only templates/mustWithout.yaml
---
# Source: test/templates/mustWithout.yaml
mustWithout: [1 2]
[root@master01 test]# cat templates/list_has.yaml 
{{$li:=list 1 2 4}}
{{- if has 2 $li}}
has: 2
{{- end}}
[root@master01 test]# helm template . --show-only templates/list_has.yaml
---
# Source: test/templates/list_has.yaml
has: 2
[root@master01 test]# cat templates/mustHas.yaml 
{{$li:=list 1 2 4}}
{{- if mustHas 2 $li}}
mustHas: 2
{{- end}}
[root@master01 test]# helm template . --show-only templates/mustHas.yaml
---
# Source: test/templates/mustHas.yaml
mustHas: 2
[root@master01 test]# cat templates/slice.yaml 
{{$li:=list 1 2 4}}
slice: {{slice $li 0 1}}
[root@master01 test]# helm template . --show-only templates/slice.yaml
---
# Source: test/templates/slice.yaml
slice: [1]
[root@master01 test]# cat templates/mustSlice.yaml 
{{$li:=list 1 2 4}}
mustSlice: {{mustSlice $li 0 1}}
[root@master01 test]# helm template . --show-only templates/mustSlice.yaml
---
# Source: test/templates/mustSlice.yaml
mustSlice: [1]
[root@master01 test]# cat templates/concat.yaml 
{{$li:=list 1 2 4}}
{{$li2:=list 5 6 7}}
concat: {{concat $li $li2}}
[root@master01 test]# helm template . --show-only templates/concat.yaml
---
# Source: test/templates/concat.yaml
concat: [1 2 4 5 6 7]
[root@master01 test]# cat templates/genPrivateKey.yaml 
{{$key:=genPrivateKey "rsa"}}
len: {{len $key}}
key: {{replace "\n" "" $key }}
[root@master01 test]# helm template . --show-only templates/genPrivateKey.yaml
---
# Source: test/templates/genPrivateKey.yaml
len: 3243
key: -----BEGIN RSA PRIVATE KEY-----MIIJKAIBAAKCAgEA8PEoBhlG8etyJZp7oucUXfSZcSbGYz2Xdf3DkkiMIPWZXTqo5fObgV2IqPCj5CdjJjZOMMmxbeVGv/9dwgZn1RQTX7tWfJRv/4d1SkKUasog9IuixHYSyCqplclwAPM9Q67bwc5El3WNxn1n5FIZeT1oqcNQR9ZzQsq2ManUsrS9X9B9MiBuqqIfnytpeE5e3I6sMveRLivMLayg1JvjiOT2VvyZVrX7QsUFa9SlkpjoTmRd2XVn0rM9W9OCGSu4jZJylpP1AXO9VCG6kpvYo5wlp5d02skpAhuxNWvoPqSO9nfbQrAaSBAUDleUXlDYBRo7xUUba89N8r0yh8uNbUpYtptdapmWjjcYsgnGk5fVtZzhFFAgsi0sOsdhTaDWjRc/iTtdURlYKFYAYE4dOmeOBGFiUahwkS6zzcZFQEk/ObZYOx4LwTVW2jpt+2swGRLwzDDzqzyISzJyGIdn5iX8i5Z5vfPUaAFu2+aJxtoLx9j3V9H6VF/GPmA0IJ910JEV00LwBqju9TzN1UzndVvTcPIk9lCCLaNW4gjzXzoTo1h+prz/lX4Iz+ch4pMk/FaZ1tcvLN+f3VIoEfVyegDLb82j33qD4OLdTudmVcwDMuRzvhutSD/umC3sdif9dGoUqTlbHIJAUat84pa/ROtZIOJjdzKmYRmbpZbH5XkCAwEAAQKCAgEA8GuCx4sjerS4wwMCicvRS+uNzRWm8lH8N5WPOAHCKgVIEno9HK/XpN+jRQhSUZBn5DJeFVq8/G7DCUSU1s2zgDA3INh7dXZcx3rwM7h6BpFJDxviv+0d0rSXYcqOQ7Rzlnz99caQNR3s6XorV+4AUzVOoc8t5XD8tFI4ORhBEE0/h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gpbVco6rVwLTe69mi8JKUCYrfC1qCMA5pXNTd3qzOK+dEppJ1rXkQ4N0NQSrV4r/M=-----END RSA PRIVATE KEY-----
[root@master01 test]# cat templates/derivePassword.yaml 
derivePassword: {{derivePassword 20 "medium" "123" "abc" "www.baidu.com"}}
[root@master01 test]# helm template . --show-only templates/derivePassword.yaml
---
# Source: test/templates/derivePassword.yaml
derivePassword: Rob0#Riw
[root@master01 test]# cat templates/genCA.yaml 
{{- $ca := genCA "harbor-ca" 365 }}
ca.crt: {{ $ca.Cert | b64enc | quote }}
[root@master01 test]# helm template . --show-only templates/genCA.yaml
---
# Source: test/templates/genCA.yaml
ca.crt: "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM5RENDQWR5Z0F3SUJBZ0lRS0ptUjVXeVYzd01RRmFiOGV2enhxREFOQmdrcWhraUc5dzBCQVFzRkFEQVUKTVJJd0VBWURWUVFERXdsb1lYSmliM0l0WTJFd0hoY05NakF3TkRFd01ETTBNekl6V2hjTk1qRXdOREV3TURNMApNekl6V2pBVU1SSXdFQVlEVlFRREV3bG9ZWEppYjNJdFkyRXdnZ0VpTUEwR0NTcUdTSWIzRFFFQkFRVUFBNElCCkR3QXdnZ0VLQW9JQkFRRFhUVWlvcklrc1FidVJYeUF3blIvT1V6SkIvOGdVbUdZL2lkK25zWkwwTVN6T2wvUC8KQmp0UVlsSm1XSkEzOG95Vys3VXRUQ3I5bFpBLy9YekJKVHZSVXdmR2JNY0NjclB4b0c5eUJLcW1KS2JsSUVCdgpScTBqYnIwTWt4b1RiRkgyL09td29yZU03dm1qMDMyZXp5UzNFK2Z2SFNtTVVvY3duaTJoaGZMV05OVkxhNW5qCnZRYXVXNzJYY1hjbU5qVFFTWURZU2RMdnVFUHdmRDliMGJMWGhvVDZSWEJCVzJ2ZmlMOWhvbGdsTitlKzFqcXAKNUFFZWRGSkhDSnNNd2w4aUZWYmdSSmx6U1FWNm1IckRYcHlTUTE2cENrYTN5VFZidkRnb0tpK3p3RHFIb1BSYQpvVklqTHo5QnlETm5VdHIxTzI2M25yNWF5RmY5ZXdWL0Y5SXZBZ01CQUFHalFqQkFNQTRHQTFVZER3RUIvd1FFCkF3SUNwREFkQmdOVkhTVUVGakFVQmdnckJnRUZCUWNEQVFZSUt3WUJCUVVIQXdJd0R3WURWUjBUQVFIL0JBVXcKQXdFQi96QU5CZ2txaGtpRzl3MEJBUXNGQUFPQ0FRRUFSaVFITmxTc3hQWXBVNnZ6cTE4YXYvc2YxUDZQVCt1MwpnNXN1RGcyZDVaRnYrdW5tY0pScS9IMnhxalJhS3NoK3Z6NWxpRjFpdmFiSkdHZDdiVCtjL09WY1h2TmpibE0vClQ5dVRHN3ZwZGJ0NW5uU3Vzd0lBT1dQMEhVWWFwZGxJSzE5cVJZNVNjY0hUL1BzelpQZFdCMjdLS3hPUWo3YloKa1pMNVZNQ3ZDcjlxS284S3VCc0crZ2FsaGRyNC8xS3pER3g4SjY2UElHKzdMazBKSlQ1T3RvOWJDTFMxYnk1Vwpuc3lKdlFZbjZBNFRkK3dseVJTS1RLZDZFZ2dpdUxLWTU4d3hiRDB5enU4V3JzVklIR0Uyemp5VHV1NGJqYUlkCncxUWE0TUhJZWN6c0p3U0w3Rkg2QjhSa0Z3QmlVSDlXaWVVSzByWW5rZGhYTDVnVkk2cjVrZz09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K"
[root@master01 test]# cat templates/genSignedCert.yaml 
{{- $ca := genCA "harbor-ca" 365 }}
{{- $cert := genSignedCert "www.baidu.com" nil (list "www.baidu.com" "www.google.com") 365 $ca }}
tls.crt: {{ $cert.Cert | b64enc | quote }}
tls.key: {{ $cert.Key | b64enc | quote }}
[root@master01 test]# helm template . --show-only templates/genSignedCert.yaml
---
# Source: test/templates/genSignedCert.yaml
tls.crt: "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURJRENDQWdpZ0F3SUJBZ0lSQUxXa3NMK2J1TGxTTWgzWmxram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kys5WHpwbHY3VDhFSE94RFFLQmdBbkRPdlRKb3VFOCtCMzEzb3ZCY3RIWElsV2V1SldyLzNHTzNCdVcKU2MvMW5Tdno1MTBpUjJEQ25ucHlGN2x0UWVaQ3kycmZoTTNiVDJOY3E3ZFo0Z1dSV1B2SzVuYjBmdWVlVnBETwp4cnNXcnJQN21sZEl5ZFBYZTI4RzZ6OWh5OXVoNXlYWU1ORm40dzZmcDVpaXRwbFVWU25xWE8wRDlibDU1V3pmCnlEY0JBb0dBTS9jNDVWaXp4RHJwdDByMWx3OVlMakxPYk9DMmpIclBFUkovcnBBZmY5L3RIcnZ1bElHNEVMUVcKczNNc0t1VUFIUUZhdGJhRWN6SUhsZUdkTGJCT2JUVUNWQW1RWTdOZXhxUTA2QzdzVE9qRUNsOG1LSUVYQms4cQpoZmpVS1NDOG40UW9UbHA2dmZFbEJTSm12R2VJcnpNalp4MWtCT0Q0UmwvV0Z1aU5sbGs9Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg=="
[root@master01 test]# cat templates/encryptAES.yaml 
encryptAES: {{encryptAES "123" "dddd"}}
[root@master01 test]# helm template . --show-only templates/encryptAES.yaml
---
# Source: test/templates/encryptAES.yaml
encryptAES: BgbJivGXDX+qhEz55aEergLaRX1SLg+Buv2SD7puDr4=
[root@master01 test]# cat templates/decryptAES.yaml 
{{$data:=encryptAES "123" "dddd"}}
decryptAES: {{decryptAES "123" $data}}
[root@master01 test]# helm template . --show-only templates/decryptAES.yaml
---
# Source: test/templates/decryptAES.yaml
decryptAES: dddd
[root@master01 test]# cat templates/uuidv4.yaml 
uuidv4: {{uuidv4}}
[root@master01 test]# helm template . --show-only templates/uuidv4.yaml
---
# Source: test/templates/uuidv4.yaml
uuidv4: 184129b3-bc65-4f55-b3cc-5fa53b45fa48
[root@master01 test]# cat templates/semver.yaml 
semver: {{semver "1.2.0"}}
[root@master01 test]# helm template . --show-only templates/semver.yaml
---
# Source: test/templates/semver.yaml
semver: 1.2.0
[root@master01 test]# cat templates/semverCompare.yaml 
{{- if semverCompare ">=1.9-0" .Capabilities.KubeVersion.GitVersion -}}
apiVesion: {{ "apps/v1"}}
{{- end}}
[root@master01 test]# helm template . --show-only templates/semverCompare.yaml
---
# Source: test/templates/semverCompare.yaml
apiVesion: apps/v1
[root@master01 test]# cat templates/fail.yaml 
{{/*
{{- "this is a fail "| fail}}
*/}}
[root@master01 test]# cat templates/regexMatch.yaml 
{{- $cn:="192.168.198.145"}}
{{- if  (regexMatch `^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$` $cn) }}
url: {{$cn}}
{{- end}}
[root@master01 test]# helm template . --show-only templates/regexMatch.yaml
---
# Source: test/templates/regexMatch.yaml
url: 192.168.198.145
[root@master01 test]# cat templates/mustRegexMatch.yaml 
{{- $cn:="192.168.198.145"}}
{{- if  (mustRegexMatch `^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$` $cn) }}
url: {{$cn}}
{{- end}}
[root@master01 test]# helm template . --show-only templates/mustRegexMatch.yaml
---
# Source: test/templates/mustRegexMatch.yaml
url: 192.168.198.145
[root@master01 test]# cat templates/regixFind.yaml 
{{- if .Values.tag | toString | regexFind "-r\\d+$|sha256:"}}
aa: bb
{{- end}}
[root@master01 test]# helm template . --show-only templates/regixFind.yaml
---
# Source: test/templates/regixFind.yaml
aa: bb
[root@master01 test]# cat templates/regixFind2.yaml 
{{- if .Values.tag2 | toString | regexFind "-r\\d+$"}}
aa: bb
{{- end}}
[root@master01 test]# helm template . --show-only templates/regixFind2.yaml
---
# Source: test/templates/regixFind2.yaml
aa: bb
[root@master01 test]# cat templates/regexFindAll.yaml 
find: {{ regexFindAll "\\d+" "34343asfd112211" -1}}
[root@master01 test]# helm template . --show-only templates/regexFindAll.yaml
---
# Source: test/templates/regexFindAll.yaml
find: [34343 112211]
[root@master01 test]# cat templates/mustRegexFindAll.yaml 
mustRegexFindAll: {{ mustRegexFindAll "\\d+" "34343asfd112211" -1}}
[root@master01 test]# helm template . --show-only templates/mustRegexFindAll.yaml
---
# Source: test/templates/mustRegexFindAll.yaml
mustRegexFindAll: [34343 112211]
[root@master01 test]# cat templates/mustRegexFind.yaml 
find: {{ mustRegexFind "\\d+" "34343asfd112211" }}
[root@master01 test]# helm template . --show-only templates/mustRegexFind.yaml
---
# Source: test/templates/mustRegexFind.yaml
find: 34343
[root@master01 test]# cat templates/regexReplaceAll.yaml 
regexReplaceAll: {{ regexReplaceAll "\\d+" "34343asfd112211" "xxx"}}
[root@master01 test]# helm template . --show-only templates/regexReplaceAll.yaml
---
# Source: test/templates/regexReplaceAll.yaml
regexReplaceAll: xxxasfdxxx
[root@master01 test]# cat templates/mustRegexReplaceAll.yaml 
mustRegexReplaceAll: {{ mustRegexReplaceAll "\\d+" "34343asfd112211" "xxx"}}
[root@master01 test]# helm template . --show-only templates/mustRegexReplaceAll.yaml
---
# Source: test/templates/mustRegexReplaceAll.yaml
mustRegexReplaceAll: xxxasfdxxx
[root@master01 test]# cat templates/regexReplaceAllLiteral.yaml 
regexReplaceAllLiteral: {{ regexReplaceAllLiteral "(\\d+)" "34343asfd112211" "$1"}}
[root@master01 test]# helm template . --show-only templates/regexReplaceAllLiteral.yaml
---
# Source: test/templates/regexReplaceAllLiteral.yaml
regexReplaceAllLiteral: $1asfd$1
[root@master01 test]# cat templates/mustRegexReplaceAllLiteral.yaml 
mustRegexReplaceAllLiteral: {{mustRegexReplaceAllLiteral "(\\d+)" "34343asfd112211" "$1"}}
[root@master01 test]# helm template . --show-only templates/mustRegexReplaceAllLiteral.yaml
---
# Source: test/templates/mustRegexReplaceAllLiteral.yaml
mustRegexReplaceAllLiteral: $1asfd$1
[root@master01 test]# cat templates/regexSplit.yaml 
regexSplit: {{regexSplit "\\d+" "888ss8ff8dd" -1}}
[root@master01 test]# helm template . --show-only templates/regexSplit.yaml
---
# Source: test/templates/regexSplit.yaml
regexSplit: [ ss ff dd]
[root@master01 test]# cat templates/mustRegexSplit.yaml 
mustRegexSplit: {{mustRegexSplit "\\d+" "888ss8ff8dd" -1}}
[root@master01 test]# helm template . --show-only templates/mustRegexSplit.yaml
---
# Source: test/templates/mustRegexSplit.yaml
mustRegexSplit: [ ss ff dd]
[root@master01 test]# cat templates/urlParse.yaml 
urlParse: |
  {{urlParse "http://www.baidu.com"}}
[root@master01 test]# helm template . --show-only templates/urlParse.yaml
---
# Source: test/templates/urlParse.yaml
urlParse: |
  map[fragment: host:www.baidu.com hostname:www.baidu.com opaque: path: query: scheme:http userinfo:]
[root@master01 test]# cat templates/urlJoin.yaml 
{{- $di:=dict "scheme" "http" "host" "www.baidu.com" }}
url: {{urlJoin $di}}
[root@master01 test]# helm template . --show-only templates/urlJoin.yaml
---
# Source: test/templates/urlJoin.yaml
url: http://www.baidu.com
[root@master01 test]# cat templates/define.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-configmap
  {{- template "mychart.labels" }}
data:
  myvalue: "Hello World"
[root@master01 test]# helm template . --show-only templates/define.yaml
---
# Source: test/templates/define.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: RELEASE-NAME-configmap
  labels:
    generator: helm
    date: 2020-04-11
data:
  myvalue: "Hello World"
[root@master01 test]# cat templates/dictAndFunc.yaml 
{{- $di:=dict "aa" "av" "bb" "bv"}}
dict: {{$di}}
{{- $di:= set $di "aa" "avv"}}
{{- $di:=set $di "cc" "cv"}}
dict: {{$di}}
{{- $di:=unset $di "aa"}}
dict: {{$di}}
{{- if hasKey $di "cc"}}
dict: has cc
{{- end}}
{{- $dic2:=dict "cc" "cv" "dd" "dv"}}
pluck: {{pluck "cc" $di $dic2}}
{{- $di:=merge $di $dic2}}
di: {{$di}}
keys: {{keys $di}}
dd: {{pick $di "dd"}}
di: {{$di}}
{{- $di:=omit $di "dd"}}
di: {{$di}}
[root@master01 test]# helm template . --show-only templates/dictAndFunc.yaml
---
# Source: test/templates/dictAndFunc.yaml
dict: map[aa:av bb:bv]
dict: map[aa:avv bb:bv cc:cv]
dict: map[bb:bv cc:cv]
dict: has cc
pluck: [cv cv]
di: map[bb:bv cc:cv dd:dv]
keys: [dd bb cc]
dd: map[dd:dv]
di: map[bb:bv cc:cv dd:dv]
di: map[bb:bv cc:cv]
[root@master01 test]# cat templates/file.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-configmap
data:
  {{- $files := .Files }}
  {{- range tuple "config1.toml"  "config2.toml"  "config3.toml"  }}
  {{ . }}: |-
    {{ $files.Get . }}
  {{- end }}
[root@master01 test]# helm template . --show-only templates/file.yaml
---
# Source: test/templates/file.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: RELEASE-NAME-configmap
data:
  config1.toml: |-
    aa=bb

  config2.toml: |-
    aa=bb

  config3.toml: |-
    aa=bb
[root@master01 test]# cat templates/fromJson.yaml 
{{- $json:=(fromJson .Values.jsonTemp)}}
{{- range $key,$value:=$json}}
{{$key}}: {{$value}}
{{- end }}
[root@master01 test]# helm template . --show-only templates/fromJson.yaml
---
# Source: test/templates/fromJson.yaml
aa: bb
cc: dd
[root@master01 test]# cat templates/fromYaml.yaml 
{{- $v:= (fromYaml .Values.testYaml)}}
{{- range $key,$value:= $v.containers}}
{{$key}}: {{$value}}
{{- end}}
[root@master01 test]# helm template . --show-only templates/fromYaml.yaml
---
# Source: test/templates/fromYaml.yaml
image: b
name: a
[root@master01 test]# cat templates/global.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-configmap
data:
  salad: {{ .Values.global.salad }}
[root@master01 test]# helm template . --show-only templates/global.yaml
---
# Source: test/templates/global.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: RELEASE-NAME-configmap
data:
  salad: caesar
[root@master01 test]# cat templates/has.yaml 
{{- if .Capabilities.APIVersions.Has "batch/v1" }}
aa: bb
{{- end}}
[root@master01 test]# helm template . --show-only templates/has.yaml
---
# Source: test/templates/has.yaml
aa: bb
[root@master01 test]# cat templates/include.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-configmap
  labels:
    {{- include "mychart.app" . | nindent 4 }}
data:
  myvalue: "Hello World"
  {{- range $key, $val := .Values.favorite }}
  {{ $key }}: {{ $val | quote }}
  {{- end }}
  {{- include "mychart.app" . | nindent 2 }}
[root@master01 test]# helm template . --show-only templates/include.yaml
---
# Source: test/templates/include.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: RELEASE-NAME-configmap
  labels:
    app_name: test
    app_version: "0.1.0+2020-04-11"
data:
  myvalue: "Hello World"
  drink: "coffee"
  food: "rice"
  fruit: 
  app_name: test
  app_version: "0.1.0+2020-04-11"
[root@master01 test]# cat templates/multifile.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: conf
data:
{{ (.Files.Glob "foo/*").AsConfig | indent 2 }}
---
apiVersion: v1
kind: Secret
metadata:
  name: very-secret
type: Opaque
data:
{{ (.Files.Glob "bar/*").AsSecrets | indent 2 }}
[root@master01 test]# helm template . --show-only templates/multifile.yaml
---
# Source: test/templates/multifile.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: conf
data:
  aa: |
    aa
  bb: |
    bb
---
# Source: test/templates/multifile.yaml
apiVersion: v1
kind: Secret
metadata:
  name: very-secret
type: Opaque
data:
  aa: YWEK
  bb: YmIK
[root@master01 test]# cat templates/Template.yaml 
data: {{ include (print $.Template.BasePath "/toYaml.yaml") .|b64enc }}
[root@master01 test]# helm template . --show-only templates/Template.yaml
---
# Source: test/templates/Template.yaml
data: YXBpVmVyc2lvbjogdjEKa2luZDogUG9kCm1lYXRkYXRhOgogIG5hbWU6IFJFTEVBU0UtTkFNRS1wb2QKc3BlYzoKICBjb250YWluZXJzOgogIC0gbmFtZTogbmdpbngKICAgIGltYWdlOiBuZ2lueAogICAgcmVzb3VyY2VzOgogICAgICBsaW1pdHM6CiAgICAgICAgY3B1OiAxMDBtCiAgICAgICAgbWVtb3J5OiAxMjhNaQogICAgICByZXF1ZXN0czoKICAgICAgICBjcHU6IDEwMG0K
[root@master01 test]# cat templates/toToml.yaml 
toml: |
{{toToml .Values.toml|indent 4 }}
[root@master01 test]# helm template . --show-only templates/toToml.yaml
---
# Source: test/templates/toToml.yaml
toml: |
    [test]
      aa = "bb"
      cc = "dd"
[root@master01 test]# cat templates/toYaml.yaml 
apiVersion: v1
kind: Pod
meatdata:
  name: {{.Release.Name}}-pod
spec:
  containers:
  - name: nginx
    image: nginx
{{toYaml .Values.resources|indent 4}}
[root@master01 test]# helm template . --show-only templates/toYaml.yaml
---
# Source: test/templates/toYaml.yaml
apiVersion: v1
kind: Pod
meatdata:
  name: RELEASE-NAME-pod
spec:
  containers:
  - name: nginx
    image: nginx
    resources:
      limits:
        cpu: 100m
        memory: 128Mi
      requests:
        cpu: 100m
[root@master01 test]# cat templates/tpl.yaml 
apiVersion: v1
kind: ConfigMap
matadata:
  name: {{.Release.Name}}-configmap
data:
  tcp: {{tpl .Values.tcp .}}
  name: {{ tpl .Values.template . }}
[root@master01 test]# helm template . --show-only templates/tpl.yaml
---
# Source: test/templates/tpl.yaml
apiVersion: v1
kind: ConfigMap
matadata:
  name: RELEASE-NAME-configmap
data:
  tcp: 5
  name: Tom
[root@master01 test]# cat templates/variableAssign.yaml 
ApiVersion: v1
Kind: ConfigMap
Metadata:
  name: {{ .Release.Name }}-configmap
Data:
  myvalue: "Hello World"
  # 由于下方的with语句引入相对命令空间,无法通过.Release引入,提前定义relname变量
  {{- $relname := .Release.Name -}}
  {{- with .Values.favorite }}
  food: {{ .food }}
  release: {{ $relname }}
  # 或者可以使用$符号,引入全局命名空间
  release: {{ $.Release.Name }}
  {{- end }}
[root@master01 test]# helm template . --show-only templates/variableAssign.yaml
---
# Source: test/templates/variableAssign.yaml
ApiVersion: v1
Kind: ConfigMap
Metadata:
  name: RELEASE-NAME-configmap
Data:
  myvalue: "Hello World"
  # 由于下方的with语句引入相对命令空间,无法通过.Release引入,提前定义relname变量
  food: rice
  release: RELEASE-NAME
  # 或者可以使用$符号,引入全局命名空间
  release: RELEASE-NAME
原创文章 409 获赞 424 访问量 346万+

猜你喜欢

转载自blog.csdn.net/hxpjava1/article/details/105340435