I have the following YAML file. I need to update the YAML file with a new key-value pair using python.
I am doing the following but, it gives me error:
pod = mylib.load_yaml("net/pod.yaml")
pod['spec']['nodeSelector']['key']='val'
it gives error saying KeyError:'nodeSelector'
spec:
containers:
- image: ceridwen/networking:v1
imagePullPolicy: Always
name: networking
readinessProbe:
tcpSocket:
port: 5000
initialDelaySeconds: 5
periodSeconds: 1
restartPolicy: Always
I need to update it with a new key value
spec:
containers:
- image: ceridwen/networking:v1
imagePullPolicy: Always
name: networking
readinessProbe:
tcpSocket:
port: 5000
initialDelaySeconds: 5
periodSeconds: 1
restartPolicy: Always
nodeSelector:
key: value