helm : Error converting YAML to JSON: yaml: line xx: Expected key not found

PHPz
Release: 2024-02-10 12:30:10
forward
718 people have browsed it

helm :将 YAML 转换为 JSON 时出错:yaml:第 xx 行:未找到预期的密钥

php editor Zimo helm is a popular Kubernetes package manager used to simplify the deployment and management of applications. However, sometimes you may encounter errors while converting YAML files to JSON format. One of the common errors is "helm: error converting YAML to JSON: yaml: line xx: could not find expected key". This error usually means that an expected key is missing at line xx of the YAML file. In this article, we will delve into the causes of this error and provide solutions to fix it.

Question content

There is a json encoded string in my values.yaml file->

values.yaml

network:
  cidrs : "[\"123.123.123.123/32\",\"123.124.125.125/32\"]"
Copy after login

Now I want to use this value as a list of strings in my network policy exit ipblock. But I can't convert it to a list.

Currently, I am following this method to achieve the requirement, but it failed -

error converting yaml to json: yaml: line xx : did not find expected key
Copy after login

netpol.yaml

spec:
  podSelector:
    matchLabels:
      name: log-forwarder
  policyTypes:
  - Egress
  egress:
  {{- $json := .Values.network.cidrs | fromJson -}}
  {{- range $json }}
  - to:
    - ipBlock:
        cidr: {{- . }}
  {{- end }}
    ports:
    - protocol: TCP
      port: 443
Copy after login

Any idea how to convert an encoded string to a list of strings and use it in my network strategy?

Workaround

Use mustFromJson instead of fromJson, recently encountered the same problem and fixed it, check the documentation to find out why .

EDIT: For some reason fromJson can't handle the top level list, but mustFromJson can, looks like a bug since the only difference listed in the documentation is mustFromJson Return an error if the JSON is invalid.

source

The above is the detailed content of helm : Error converting YAML to JSON: yaml: line xx: Expected key not found. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!