例如有以下文件结构,需要使用helm将png格式、json、bson格式数据放入k8s的configmap中
└─charts
├─xxxxx-server
│ ├─pngcm
│ │ picture1.png
│ │ picture2.png
│ │ picture3.png
│ ├─mongodbinitdatacm
│ │ mongodbcollcollection1.bson
│ │ mongodbcollcollection1.metadata.json
│ │ mongodbcollcollection2.bson
│ │ mongodbcollcollection2.metadata.json
│ └─templates
│ 01.initpngcm.yaml
│ 02.initmongocm.yaml
│ └─tests
以下为 01.initpngcm.yaml 的文件内容
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "xxxxx-server.name" . }}-pngcm
data:
{{ range $path, $_ := .Files.Glob "png/**.png" }}
{{ base $path }}: |-
{{ $.Files.GetBytes $path }}
{{ end }}
以下为 02.initmongocm.yaml 文件内容
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "xxxxx-server.name" . }}-datainitialization
data:
{{ range $path, $_ := .Files.Glob "initdata/**.json" }}
{{ base $path }}: |-
{{ $.Files.Get $path | indent 4 }}
{{ end }}
binaryData:
{{ range $path, $_ := .Files.Glob "initdata/**.bson" }}
{{ base $path }}: |-
{{ $.Files.Get $path | b64enc }}
{{ end }}