一、trim¶
trim行数移除字符串两边的空格
trim " hello "
上述结果为: hello
下面进行举例说明
1.创建一个Chart
$ helm create helm-test
2.删掉系统自带的模板文件
[root@k8s-master01 ~]# rm -rf /root/helm-test/templates/*
3.新增模板文件,并填写Release.Name内置变量
[root@k8s-master01 ~]# cd /root/helm-test/templates
[root@k8s-master01 templates]# vim configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
myvalue: "Hello World"
trim: {{ .Values.myValue | trim }}
4.清空values.yaml文件,并添加以下内容
[root@k8s-master01 ~]# > /root/helm-test/values.yaml
[root@k8s-master01 ~]# vim /root/helm-test/values.yaml
myValue: " Hello "
5.进行验证,观察到输出结果为Hello
[root@k8s-master01 helm-test]# helm install aaa /root/helm-test/ --dry-run
NAME: aaa
LAST DEPLOYED: Sun Jul 9 14:38:19 2023
NAMESPACE: default
STATUS: pending-install
REVISION: 1
TEST SUITE: None
HOOKS:
MANIFEST:
---
# Source: helm-test/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: aaa-configmap
data:
myvalue: "Hello World"
trim: Hello
二、trimAll¶
从字符串中移除给定的字符
trimAll "$" "$5.00"
上述结果为:5.00 (作为一个字符串)。
下面进行举例说明:
1.创建一个Chart
$ helm create helm-test
2.删掉系统自带的模板文件
[root@k8s-master01 ~]# rm -rf /root/helm-test/templates/*
3.新增模板文件,并填写Release.Name内置变量
[root@k8s-master01 ~]# cd /root/helm-test/templates
[root@k8s-master01 templates]# vim configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
trim: {{ .Values.myValue | trimAll "$" }}
4.清空values.yaml文件,并添加以下内容
[root@k8s-master01 ~]# > /root/helm-test/values.yaml
[root@k8s-master01 ~]# vim /root/helm-test/values.yaml
myValue: "$5.00"
5.进行验证,观察到输出结果为5.00
[root@k8s-master01 templates]# helm install aaa /root/helm-test/ --dry-run
NAME: aaa
LAST DEPLOYED: Sun Jul 9 14:50:07 2023
NAMESPACE: default
STATUS: pending-install
REVISION: 1
TEST SUITE: None
HOOKS:
MANIFEST:
---
# Source: helm-test/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: aaa-configmap
data:
trim: 5.00
三、trimSuffix¶
从字符串中移除后缀
trimSuffix "-" "hello-"
上述结果为: hello
下面进行举例说明:
1.创建一个Chart
$ helm create helm-test
2.删掉系统自带的模板文件
[root@k8s-master01 ~]# rm -rf /root/helm-test/templates/*
3.新增模板文件,并填写Release.Name内置变量
[root@k8s-master01 ~]# vim /root/helm-test/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
trim: {{ .Values.myValue | trimSuffix "-" }}
4.清空values.yaml文件,并添加以下内容
[root@k8s-master01 ~]# > /root/helm-test/values.yaml
[root@k8s-master01 ~]# vim /root/helm-test/values.yaml
myValue: "hello-"
5.进行验证,观察到输出结果为hello
[root@k8s-master01 templates]# helm install aaa /root/helm-test/ --dry-run
NAME: aaa
LAST DEPLOYED: Sun Jul 9 15:02:04 2023
NAMESPACE: default
STATUS: pending-install
REVISION: 1
TEST SUITE: None
HOOKS:
MANIFEST:
---
# Source: helm-test/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: aaa-configmap
data:
trim: hello
四、trimPrefix¶
从字符串中移除前缀
trimPrefix "-" "-hello"
上述结果为:hello
下面进行举例说明:
1.创建一个Chart
$ helm create helm-test
2.删掉系统自带的模板文件
[root@k8s-master01 ~]# rm -rf /root/helm-test/templates/*
3.新增模板文件,并填写Release.Name内置变量
[root@k8s-master01 ~]# vim /root/helm-test/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
trim: {{ .Values.myValue | trimPrefix "-" }}
4.清空values.yaml文件,并添加以下内容
[root@k8s-master01 ~]# > /root/helm-test/values.yaml
[root@k8s-master01 ~]# vim /root/helm-test/values.yaml
myValue: "-hello"
5.进行验证,观察到输出结果为hello
[root@k8s-master01 templates]# helm install aaa /root/helm-test/ --dry-run
NAME: aaa
LAST DEPLOYED: Sun Jul 9 15:02:04 2023
NAMESPACE: default
STATUS: pending-install
REVISION: 1
TEST SUITE: None
HOOKS:
MANIFEST:
---
# Source: helm-test/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: aaa-configmap
data:
trim: hello
五、upper¶
将整个字符串转换成大写
upper "hello"
上述结果为: HELLO
下面进行举例说明:
1.创建一个Chart
$ helm create helm-test
2.删掉系统自带的模板文件
[root@k8s-master01 ~]# rm -rf /root/helm-test/templates/*
3.新增模板文件,并填写Release.Name内置变量
[root@k8s-master01 ~]# vim /root/helm-test/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
trim: {{ .Values.myValue | upper }}
4.清空values.yaml文件,并添加以下内容
[root@k8s-master01 ~]# > /root/helm-test/values.yaml
[root@k8s-master01 ~]# vim /root/helm-test/values.yaml
myValue: "hello"
5.进行验证,观察到输出结果为HELLO
[root@k8s-master01 templates]# helm install aaa /root/helm-test/ --dry-run
NAME: aaa
LAST DEPLOYED: Sun Jul 9 15:02:04 2023
NAMESPACE: default
STATUS: pending-install
REVISION: 1
TEST SUITE: None
HOOKS:
MANIFEST:
---
# Source: helm-test/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: aaa-configmap
data:
trim: HELLO
六、lower¶
将整个字符串转换成小写
lower "HELLO"
上述结果为: hello
下面进行举例说明:
1.创建一个Chart
$ helm create helm-test
2.删掉系统自带的模板文件
[root@k8s-master01 ~]# rm -rf /root/helm-test/templates/*
3.新增模板文件,并填写Release.Name内置变量
[root@k8s-master01 ~]# vim /root/helm-test/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
trim: {{ .Values.myValue | lower }}
4.清空values.yaml文件,并添加以下内容
[root@k8s-master01 ~]# > /root/helm-test/values.yaml
[root@k8s-master01 ~]# vim /root/helm-test/values.yaml
myValue: "HELLO"
5.进行验证,观察到输出结果为hello
[root@k8s-master01 templates]# helm install aaa /root/helm-test/ --dry-run
NAME: aaa
LAST DEPLOYED: Sun Jul 9 15:02:04 2023
NAMESPACE: default
STATUS: pending-install
REVISION: 1
TEST SUITE: None
HOOKS:
MANIFEST:
---
# Source: helm-test/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: aaa-configmap
data:
trim: hello
七、title¶
首字母转换成大写
title "hello"
上述结果为:Hello
下面进行举例说明:
1.创建一个Chart
$ helm create helm-test
2.删掉系统自带的模板文件
[root@k8s-master01 ~]# rm -rf /root/helm-test/templates/*
3.新增模板文件,并填写Release.Name内置变量
[root@k8s-master01 ~]# vim /root/helm-test/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
trim: {{ .Values.myValue | title }}
4.清空values.yaml文件,并添加以下内容
[root@k8s-master01 ~]# > /root/helm-test/values.yaml
[root@k8s-master01 ~]# vim /root/helm-test/values.yaml
myValue: "hello"
5.进行验证,观察到输出结果为Hello
[root@k8s-master01 templates]# helm install aaa /root/helm-test/ --dry-run
NAME: aaa
LAST DEPLOYED: Sun Jul 9 15:02:04 2023
NAMESPACE: default
STATUS: pending-install
REVISION: 1
TEST SUITE: None
HOOKS:
MANIFEST:
---
# Source: helm-test/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: aaa-configmap
data:
trim: Hello
八、untitle¶
移除首字母大写:untitle "Hello World" 会得到 hello world
下面进行举例说明:
1.创建一个Chart
$ helm create helm-test
2.删掉系统自带的模板文件
[root@k8s-master01 ~]# rm -rf /root/helm-test/templates/*
3.新增模板文件,并填写Release.Name内置变量
[root@k8s-master01 ~]# vim /root/helm-test/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
trim: {{ .Values.myValue | untitle }}
4.清空values.yaml文件,并添加以下内容
[root@k8s-master01 ~]# > /root/helm-test/values.yaml
[root@k8s-master01 ~]# vim /root/helm-test/values.yaml
myValue: "Hello"
5.进行验证,观察到输出结果为hello
[root@k8s-master01 templates]# helm install aaa /root/helm-test/ --dry-run
NAME: aaa
LAST DEPLOYED: Sun Jul 9 15:02:04 2023
NAMESPACE: default
STATUS: pending-install
REVISION: 1
TEST SUITE: None
HOOKS:
MANIFEST:
---
# Source: helm-test/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: aaa-configmap
data:
trim: hello