Skip to content

generate volumemout jsonpatch array depending on if container already have volumemount #87

Discussion options

You must be logged in to vote

The function should not be defined inside of the rule, but can definitely be called from there. Something like this should work:

package play

vm_value := {"name": "volmount1"}

patches[patch] {
	some i
	container_i := input.containers[i]
	patch := {
		"op": "add",
		"path": concat("/", get_path(i, object.get(container_i, "volmount", false))),
		"value": [vm_value],
	}
}

get_path(i, exists) = ["/containers", format_int(i, 10), "volmount", "-"] {
	exists
}

get_path(i, exists) = ["/containers", format_int(i, 10), "volmount"] {
	not exists
}

Though if you are trying to build the path dynamically for mutation, that's actually trickier than it seems. Have a look at this repo from @tsandall

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@zhoupoko2000
Comment options

Answer selected by zhoupoko2000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants