Reputation: 1088
I have a json encoded string in my values.yaml file ->
values.yaml
network:
cidrs : "[\"123.123.123.123/32\",\"123.124.125.125/32\"]"
Now , I want to use this value as a list of string in my network policy egress ipblock. But I'm not able to convert it to list.
Currently, I'm following this to achieve the requirement , but it fails -
error converting YAML to JSON: yaml: line xx : did not find expected key
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
Any idea , how to convert the encoded string to list of string and use it in my network policy ?
Upvotes: 2
Views: 285
Reputation: 116
Use mustFromJson
instead of fromJson
, had the same problem recently and that fixed it, gonna have a look in the docs to see if I find out why.
edit: for some reason fromJson
cant handle top level lists, but mustFromJson
can, looks like a bug as the only difference listed in the docs is that mustFromJson
returns an error in case the JSON is invalid.
Upvotes: 2