Eu tenho o seguinte arquivo JSON chamado 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
}
No meu script bash, estou usando jq
para passar os valores para estes espaços reservados 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)
Se estou passando RC_JOIN_PROFILE="test-profile"
and CLUSTER_NAME="test-cluster"
, esperava o JSON final da seguinte maneira:
{
"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
}
No entanto, estou recebendo o JSON abaixo:
{
"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
}
Os valores existentes de .ExitActions.AddPofiles
e .ExitActions.RemoveProfiles
foram .Description
substituídos pelos valores passados. Quero os valores existentes com valores passados. Tentei vários cenários e nada funcionou. Alguém pode me ajudar com isso?