Refactor and add deployment support
This commit is contained in:
32
lib/utils.libsonnet
Normal file
32
lib/utils.libsonnet
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
# adopted from stdlib source to handle array merges
|
||||
# https://github.com/google/jsonnet/blob/4e67da2c015bb316158d3e52a47376b38a29a4ef/stdlib/std.jsonnet#L1473
|
||||
merge (target, patch)::
|
||||
if std.isObject(patch) then
|
||||
local target_object =
|
||||
if std.isObject(target) then target else {};
|
||||
|
||||
local target_fields =
|
||||
if std.isObject(target_object) then std.objectFields(target_object) else [];
|
||||
|
||||
local null_fields = [k for k in std.objectFields(patch) if patch[k] == null];
|
||||
local both_fields = std.setUnion(target_fields, std.objectFields(patch));
|
||||
|
||||
{
|
||||
[k]:
|
||||
if !std.objectHas(patch, k) then
|
||||
target_object[k]
|
||||
else if !std.objectHas(target_object, k) then
|
||||
$.merge(null, patch[k])
|
||||
else
|
||||
$.merge(target_object[k], patch[k])
|
||||
for k in std.setDiff(both_fields, null_fields)
|
||||
}
|
||||
else if std.isArray(patch) then
|
||||
if std.isArray(target) && target != [null] then
|
||||
target + patch
|
||||
else
|
||||
patch
|
||||
else
|
||||
patch
|
||||
}
|
||||
Reference in New Issue
Block a user