I'll write "pseudo-python-jsonnet" code to show what I want to achieve. I really have no clue how to do something like that in jsonnet.
local createCopy(gname, rname, kp) =
for topLvlKey in std.objectFieldsAll(kp):
for subKey in std.objectFieldsAll(kp[topLvlKey]):
if kp[topLvlKey][subKey].get("kind", "") == "PrometheusRule":
for group in kp[topLvlKey][subKey]["spec"]["groups"]:
if group["name"] == gname:
for rule in group["rules"]:
if rule.get("alert", "") == rname:
return rule
return null
return null
So basically I want to search a deep object structure for a specific sub-object and return it or return null/None if it is not found.
https://jsonnet.org/learning/tutorial.html is somehow good, but only shows the "easy" parts, if you want to do more complex things with jsonnet, it seems you're left on your own. I'm new to jsonnet and it really gives me headaches, so I hope someone can help me.