【发布时间】:2020-07-21 23:09:16
【问题描述】:
我在 Linux 上使用 Helm3 (v3.2.4)。我们有许多配置文件保存在图表下的子文件夹中,我试图从中构建 ConfigMaps。它几乎可以工作,但我有 3 个问题:
- 最后的错误信息,不知道是什么原因
- 我不知道如何使每个 configMap 键仅成为一个文件名 - 我使用的 $path 变量包含该文件的文件夹。 (已解决)
- 每个项目的间距和缩进似乎不对,我不知道如何控制它。
这是我的文件结构:
└── fromfiles
├── charts
├── Chart.yaml
├── parser
├── receiver
│ ├── 100_aws_beats_receiver_input_5044.conf
│ ├── 100_aws_dmp_beats_receiver_input_5019.conf
│ └── 100_cloud_foundry_receiver_input_5020.conf
└── templates
└── configMap_glob_files.yaml
这是用于生成 ConfigMap 的 configMap_glob_files.yaml 文件:
cat configMap_glob_files.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-glob-configmap
data:
{{ $currentScope := . }}
{{ range $path, $_ := .Files.Glob "receiver/**.conf" }}
{{- with $currentScope}}
{{ base $path }}: | -
{{ .Files.Get $path | indent 4 }}
{{- end }}
{{ end }}
这是其中一个 conf 文件:
cat 100_aws_beats_receiver_input_5044.conf
input {
beats {
port => 5044
host => "0.0.0.0"
tags => ["output_beats"]
add_field => {
"[es][port]" => 5044
}
}
}
下面是我运行helm template 命令时发生的情况:
[jdepaul@pu00cenvdi323 configfun]$ helm template multi-files/fromfiles --debug
install.go:159: [debug] Original chart version: ""
install.go:176: [debug] CHART PATH: /home/jdepaul/repos/configfun/multi-files/fromfiles
---
# Source: fromfiles/templates/configMap_glob_files.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: RELEASE-NAME-glob-configmap
data:
100_aws_beats_receiver_input_5044.conf: | - **(SOLVED)**
input { **(This indentation is wrong...)**
beats {
port => 5044
host => "0.0.0.0"
tags => ["output_beats"]
add_field => {
"[es][port]" => 5044
}
}
}
... the other two items in the list removed for brevity
Error: YAML parse error on fromfiles/templates/configMap_glob_files.yaml: error converting YAML to JSON: yaml: line 8: did not find expected comment or line break
helm.go:84: [debug] error converting YAML to JSON: yaml: line 8: did not find expected comment or line break
YAML parse error on fromfiles/templates/configMap_glob_files.yaml
helm.sh/helm/v3/pkg/releaseutil.(*manifestFile).sort
/home/circleci/helm.sh/helm/pkg/releaseutil/manifest_sorter.go:146
helm.sh/helm/v3/pkg/releaseutil.SortManifests
/home/circleci/helm.sh/helm/pkg/releaseutil/manifest_sorter.go:106
helm.sh/helm/v3/pkg/action.(*Configuration).renderResources
/home/circleci/helm.sh/helm/pkg/action/action.go:159
helm.sh/helm/v3/pkg/action.(*Install).Run
/home/circleci/helm.sh/helm/pkg/action/install.go:238
main.runInstall
/home/circleci/helm.sh/helm/cmd/helm/install.go:229
main.newTemplateCmd.func1
/home/circleci/helm.sh/helm/cmd/helm/template.go:66
github.com/spf13/cobra.(*Command).execute
/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:842
github.com/spf13/cobra.(*Command).ExecuteC
/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:950
github.com/spf13/cobra.(*Command).Execute
/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:887
main.main
/home/circleci/helm.sh/helm/cmd/helm/helm.go:83
runtime.main
/usr/local/go/src/runtime/proc.go:203
runtime.goexit
/usr/local/go/src/runtime/asm_amd64.s:1357
【问题讨论】:
-
我用路径前面的“base”关键字解决了#2 问题。我的主要问题仍然是解析错误。 receiver/*.conf 文件不是有效的 JSON。有没有办法将这些数据声明为“任意”,这样 helm 就不会尝试解析它?
标签: kubernetes-helm