我有以下名为的 JSON 文件pool.json
:
{
"AllocateActions": {},
"Available": true,
"Description": "Pool for nodes in cluster - {{CLUSTER_NAME}}",
"Endpoint": "",
"EnterActions": {
"AddProfiles": [
"{{RC_JOIN_PROFILE}}",
"image-deploy-profile",
"rc-controlplane-profile",
"rc-etcd-profile"
],
"Workflow": "rc-image-deploy"
},
"Errors": [],
"ExitActions": {
"RemoveProfiles": [
"{{RC_JOIN_PROFILE}}",
"image-deploy-profile"
],
"Workflow": "discover-base"
},
"Meta": {
"color": "black",
"feature-flags": "sane-exit-codes",
"icon": "object ungroup outline",
"title": "User added"
},
"ReadOnly": true,
"ReleaseActions": {},
"Validated": true
}
在我的 bash 脚本中,我用来jq
将值传递给这些 JSON 占位符:
NODE_JSON=$(jq --arg RC_JOIN_PROFILE "$RC_JOIN_PROFILE" --arg CLUSTER_NAME "$CLUSTER_NAME" '.Description = "'$CLUSTER_NAME'"| .ExitActions.RemoveProfiles = [ "'$RC_JOIN_PROFILE'" ] | .EnterActions.AddProfiles = [ "'$RC_JOIN_PROFILE'" ]' pool.json)
如果我传递RC_JOIN_PROFILE="test-profile"
和CLUSTER_NAME="test-cluster"
,那么我期望最终的 JSON 如下:
{
"AllocateActions": {},
"Available": true,
"Description": "Pool for nodes in cluster - test-cluster",
"Endpoint": "",
"EnterActions": {
"AddProfiles": [
"test-profile",
"image-deploy-profile",
"rc-controlplane-profile",
"rc-etcd-profile"
],
"Workflow": "rc-image-deploy"
},
"Errors": [],
"ExitActions": {
"RemoveProfiles": [
"test-profile",
"image-deploy-profile"
],
"Workflow": "discover-base"
},
"Meta": {
"color": "black",
"feature-flags": "sane-exit-codes",
"icon": "object ungroup outline",
"title": "User added"
},
"ReadOnly": true,
"ReleaseActions": {},
"Validated": true
}
但是,我在下面得到了 JSON:
{
"AllocateActions": {},
"Available": true,
"Description": "test-cluster",
"Endpoint": "",
"EnterActions": {
"AddProfiles": [
"test-profile",
],
"Workflow": "rc-image-deploy"
},
"Errors": [],
"ExitActions": {
"RemoveProfiles": [
"test-profile",
],
"Workflow": "discover-base"
},
"Meta": {
"color": "black",
"feature-flags": "sane-exit-codes",
"icon": "object ungroup outline",
"title": "User added"
},
"ReadOnly": true,
"ReleaseActions": {},
"Validated": true
}
.ExitActions.AddPofiles
、.ExitActions.RemoveProfiles
和的现有值.Description
已被传递的值覆盖。我想要带有传递值的现有值。我尝试了很多场景,但没有任何效果。谁能帮我这个?