[英]yq update yaml array using other yaml file's array
I dont have any detail knowledge on yq.我对yq没有任何详细的知识。 template1.yaml
模板1.yaml
spec:
template:
temp:
vars:
- name: first
env: []
template2.yaml模板2.yaml
env:
-name: "first"
value: 1
-name: "two"
value: 2
I want to add env array of template2.yaml to template1.yaml's env array using yq.我想使用 yq 将 template2.yaml 的 env 数组添加到 template1.yaml 的 env 数组中。 How can we do this??
我们应该怎么做??
Which tool called yq are you using?您使用的是哪个工具 yq ?
Using mikefarah/yq (tested with v4.20.2):使用mikefarah/yq (使用 v4.20.2 测试):
yq '
.spec.template.temp.vars[].env += load("template2.yaml").env
' template1.yaml
Using kislyuk/yq (tested with v3.0.2):使用kislyuk/yq (使用 v3.0.2 测试):
yq -y '
.spec.template.temp.vars[].env += input.env
' template1.yaml template2.yaml
Output: Output:
spec:
template:
temp:
vars:
- name: first
env:
- name: "first"
value: 1
- name: "two"
value: 2
Note: This assumes, your template2.yaml
looks more like this:注意:这假设您的
template2.yaml
看起来更像这样:
env:
- name: "first"
value: 1
- name: "two"
value: 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.