Given a YAML like this:
apiVersion: v1
data:
cluster-config.json: |
{
"cluster_id": "****",
"cluster_name": "prod-***-****",
"cluster_type": "cruiser",
"cluster_pay_tier": "paid",
"datacenter": "***",
"account_id": "****",
"created": "2017-06-04T07:51:06+0000"
}
etcd_host: 169.46.*.*
etcd_port: "29458"
kind: ConfigMap
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","data":{"cluster-config.json":"{\n \"cluster_id\": \"****\",\n \"cluster_name\": \"prod-****-****\",\n \"cluster_type\": \"cruiser\",\n \"cluster_pay_tier\": \"paid\",\n \"datacenter\": \"****\",\n \"account_id\": \"****\",\n \"created\": \"2017-06-04T07:51:06+0000\"\n}\n","etcd_host":"169.46.7.238","etcd_port":"29458"},"kind":"ConfigMap","metadata":{"annotations":{},"name":"cluster-info","namespace":"kube-system"}}
creationTimestamp: 2017-09-20T18:45:23Z
name: cluster-info
namespace: kube-system
resourceVersion: "20951865"
selfLink: /api/v1/namespaces/kube-system/configmaps/cluster-info
uid: dc5c0571-9e33-11e7-9da2-066e2a0e9500
I'm trying to reach data.cluster-config.json, which gives me null. How can I overcome this?
http://mikefarah.github.io/yq/read/#handling-in-the-yaml-key
yaml read ~/Desktop/1.yaml \"data.cluster-config.json\"
null
don't escape the quotes :)
oh oops just realised I pointed you to the wrong link - should be
http://mikefarah.github.io/yq/read/#keys-with-dots
yq r examples/data1.yaml 'data[cluster-config.json]'
Yeah I think those other instructions are just wrong - will update the docs ;)
Wait wait don't close just yet... So assuming I am now able to reach cluster-config.json, how do I get to each of the properties inside of it?!
hah sorry - but the values you have in there is a _stringified json_ block, not a yaml block ;)
if it was yaml, you could do
yq r examples/data1.yaml 'data[cluster-config.json].cluster_id'
for it to be yaml, it would have to be
data:
cluster-config.json:
cluster_id: "****"
etcd_host: 169.46.*.*
if it's supposed to be a stringified json, then you can access it by:
yq r examples/data1.yaml 'data[cluster-config.json]' | yq r - cluster_id
Yes unfortunately that part has to be a stringified JSON block. :/ Thanks for the help, though!
Most helpful comment
oh oops just realised I pointed you to the wrong link - should be
http://mikefarah.github.io/yq/read/#keys-with-dots