Skip to content
This repository has been archived by the owner on Feb 9, 2022. It is now read-only.

Commit

Permalink
add showtree.jsonnet
Browse files Browse the repository at this point in the history
  • Loading branch information
jjo committed Mar 5, 2019
1 parent 7069ca2 commit 6b6aac6
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions manifests/contrib/showtree.jsonnet
@@ -0,0 +1,54 @@
// Simple tool to show BKPR jsonnet objects -> Kubernetes objects tree
// useful to find out where to override wanted fields
// Run as:
// jsonnet showtree.jsonnet
// jsonnet showtree.jsonnet | sed -e '1d;$d' -e 's/[",:]//g' | column -t
local helpers = (import 'helpers.jsonnet');

// Need to "fuse" kubecfg.manifestYaml() calls as it's kubecfg internal,
// unsupported by jsonnet
local voidKubecfgInternals(obj) = (
obj
+ helpers.setAtPath('grafana.datasources.data', { 'bkpr.yml': '' })
+ helpers.setAtPath('prometheus.rules', {})
+ helpers.setAtPath('prometheus.prometheus.config.data', { 'prometheus.yml': '' })
+ helpers.setAtPath('prometheus.alertmanager.config.data', { 'config.yml': '' })
);

// Just picking up one of the supported platforms, to get a full
// kubeprod treeish object
local kubeprod = voidKubecfgInternals(import '../tests/gke.jsonnet');

local formatKube(k, obj) = (
if std.objectHas(obj.metadata, 'namespace') then
{ [k]: '%s %s -n %s' % [obj.kind, obj.metadata.name, obj.metadata.namespace] }
else
{ [k]: '%s %s' % [obj.kind, obj.metadata.name] }
);

// Build main tree: jsonnet key -> formatted Kubernetes object
local show_tree(obj) = (
local tree(key, x) = (
if std.objectHas(x, 'metadata') then
formatKube(key, x)
else
[tree(key + '.' + k, x[k]) for k in std.objectFields(x)]
);
tree('', obj)
);

// Flatten into a single object
local flatten(obj) = (
std.foldl(
function(x, y) (
if std.type(y) == 'object' then
x + y
else
x + flatten(y)
),
obj,
{}
)
);

flatten(show_tree(kubeprod))

0 comments on commit 6b6aac6

Please sign in to comment.