如何调试 Helm 图表错误,例如“将 YAML 转换为 JSON 时出错:yaml:此上下文中不允许映射值”?

Yan*_*ann 16 yaml kubernetes-helm microk8s

我正在使用 Helm 3 和 microk8s。当我尝试试运行时:

microk8s.helm install <...> --dry-run --debug
Run Code Online (Sandbox Code Playgroud)

我看到类似的错误

Error: YAML parse error on ./templates/deployment.yaml: error converting YAML to JSON: yaml: mapping values are not allowed in this context
helm.go:76: [debug] error converting YAML to JSON: yaml: mapping values are not allowed in this context
YAML parse error on ./templates/deployment.yaml
helm.sh/helm/v3/pkg/releaseutil.(*manifestFile).sort
    /home/circleci/helm.sh/helm/pkg/releaseutil/manifest_sorter.go:129
helm.sh/helm/v3/pkg/releaseutil.SortManifests
    /home/circleci/helm.sh/helm/pkg/releaseutil/manifest_sorter.go:98
helm.sh/helm/v3/pkg/action.(*Configuration).renderResources
    /home/circleci/helm.sh/helm/pkg/action/install.go:455
helm.sh/helm/v3/pkg/action.(*Install).Run
    /home/circleci/helm.sh/helm/pkg/action/install.go:214
main.runInstall
...
Run Code Online (Sandbox Code Playgroud)

我发现了几个有类似错误的问题,但答案通常只是要求读取图表代码。我有一个很大的图表,需要自己调试这个错误。猜测它抱怨哪一行似乎没有意义。

有没有办法知道配置中究竟有什么问题?

Eri*_*oen 7

尝试:helm template ... --debug > foo.yaml

这会将渲染的图表输出到 foo.yaml (并将 helm 错误堆栈跟踪输出到 stderr)。然后从 helm 错误中找到有问题的模板文件名,并在渲染的图表中查找类似# Source: the-template-name.yaml. YAML 到 JSON 的转换是针对每个 YAML 对象单独完成的,因此您可能有相同# Source: the-template-name.yaml.

查看每个注释下面的n# Source: ...行是否有错误,其中n是 Helm render 报告的错误的行号。