spec:
replicas: 1
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
selector:
matchLabels:
app.kubernetes.io/name: myapp
app.kubernetes.io/instance: myapp
我想用 awk 遍历树,生成每个键的所有路径:
spec
spec:replicas
spec:strategy
spec:strategy:rollingUpdate
spec:strategy:rollingUpdate:maxSurge
spec:strategy:rollingUpdate:maxUnavailable
spec:selector
spec:selector:matchLabels
spec:selector:matchLabels:app.kubernetes.io/name
spec:selector:matchLabels:app.kubernetes.io/instance
理想情况下是深度优先搜索预排序。
我发现了这个相关问题:
但是这个解决方案离我想要的太远了,我无法用我对 awk 的可怜的知识来重新调整它的用途
YAML 处理器将为您提供可靠的结果:
gojq --yaml-input -r 'paths | join(":")' input.yaml
yq '.* | .. | path | join(":")' input.yaml
yq -r 'paths | join(":")' input.yaml