-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(grafanaplane): expose GroupVersionKind tuples (#21)
* refactor(generator): move util functions to separate file * feat(grafanaplane): expose GroupVersionKind tuples This exposes GroupVersionKind tuples for all CRDs and XRDs covered by this library. The main goal is to configure kube-state-metrics Custom Resource State metrics. * fix(grafanaplane): update xtd dependency * fix: include plural as this is used to configure policyRules
- Loading branch information
Showing
5 changed files
with
803 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,82 @@ | ||
local namespaced = import './namespaced.libsonnet'; | ||
local crossplane = import 'github.com/jsonnet-libs/crossplane-libsonnet/crossplane/1.17/main.libsonnet'; | ||
|
||
local configuration(key, version) = | ||
local conf = crossplane.pkg.v1.configuration; | ||
conf.new(key) | ||
+ conf.spec.withPackage('ghcr.io/grafana/crossplane/' + key + ':' + version); | ||
|
||
local groups = | ||
local xrds = | ||
std.map( | ||
function(o) o.definition, | ||
(import './namespaced.libsonnet'), | ||
); | ||
|
||
local crds = | ||
std.filter( | ||
function(crd) crd.spec.group != 'grafana.crossplane.io', | ||
std.parseYaml(importstr './crds.yaml'), | ||
); | ||
|
||
local gvkXRDs = | ||
std.flatMap( | ||
function(definition) [ | ||
{ | ||
group: definition.spec.group, | ||
version: v.name, | ||
kind: definition.spec.claimNames.kind, | ||
plural: definition.spec.claimNames.plural, | ||
} | ||
for v in definition.spec.versions | ||
], | ||
xrds | ||
); | ||
|
||
local gvkCRDs = | ||
std.flatMap( | ||
function(definition) [ | ||
{ | ||
group: definition.spec.group, | ||
version: v.name, | ||
kind: definition.spec.names.kind, | ||
plural: definition.spec.names.plural, | ||
} | ||
for v in definition.spec.versions | ||
], | ||
crds | ||
); | ||
|
||
local groupSet(gvks) = | ||
std.set( | ||
std.map( | ||
function(def) | ||
std.splitLimit(def.definition.spec.group, '.', 1)[0], | ||
namespaced | ||
function(gvk) | ||
gvk.group, | ||
gvks, | ||
) | ||
); | ||
|
||
function(configurationVersion) { | ||
[group]: configuration('grafana-namespaced-' + group, configurationVersion) | ||
for group in groups | ||
local shortGroupName(group) = | ||
std.splitLimit(group, '.', 1)[0]; | ||
|
||
local groupFilter(group) = | ||
function(gvk) gvk.group == group; | ||
|
||
local gvkByGroup(name, gvks) = { | ||
[shortGroupName(group)]+: { | ||
[name]+: [ | ||
gvk | ||
for gvk in std.filter(groupFilter(group), gvks) | ||
], | ||
} | ||
for group in groupSet(gvks) | ||
}; | ||
|
||
function(version='main') { | ||
configurations: { | ||
[shortGroupName(group)]: configuration('grafana-namespaced-' + shortGroupName(group), version) | ||
for group in groupSet(gvkXRDs) | ||
}, | ||
|
||
gvks: | ||
gvkByGroup('xrd', gvkXRDs) | ||
+ gvkByGroup('crd', gvkCRDs), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
local a = import 'github.com/crdsonnet/astsonnet/main.libsonnet'; | ||
local autils = import 'github.com/crdsonnet/astsonnet/utils.libsonnet'; | ||
local d = import 'github.com/jsonnet-libs/docsonnet/doc-util/main.libsonnet'; | ||
|
||
{ | ||
local root = self, | ||
|
||
subPackageDocstring(name, help=''): | ||
a.object.new([ | ||
a.field.new( | ||
a.string.new('#'), | ||
a.literal.new( | ||
std.manifestJsonEx( | ||
d.package.newSub(name, help) | ||
, ' ', '' | ||
), | ||
), | ||
), | ||
]), | ||
|
||
mergeDocstring(group, version, name, obj, help=''): | ||
autils.deepMergeObjects([ | ||
a.object.new([ | ||
a.field.new( | ||
a.id.new(group), | ||
a.object.new([ | ||
a.field.new( | ||
a.string.new('#'), | ||
a.literal.new( | ||
std.manifestJsonEx( | ||
d.package.newSub(group, '') | ||
, ' ', '' | ||
), | ||
), | ||
), | ||
a.field.new( | ||
a.id.new(version), | ||
a.object.new([ | ||
a.field.new( | ||
a.id.new(name), | ||
root.subPackageDocstring(name, help) | ||
), | ||
]), | ||
), | ||
]), | ||
), | ||
]), | ||
obj, | ||
]), | ||
|
||
splitIntoFiles(objast, sub='', depth=1, maxDepth=5): | ||
local subdir = if sub != '' then sub + '/' else ''; | ||
std.foldl( | ||
function(acc, member) | ||
if member.type == 'field' | ||
&& member.expr.type == 'object' | ||
&& !std.startsWith(member.fieldname.string, '#') | ||
then | ||
acc | ||
+ { | ||
[subdir + 'main.libsonnet']+: | ||
a.object.withMembersMixin([ | ||
member | ||
+ a.field.withExpr( | ||
if depth != maxDepth | ||
then a.import_statement.new('./' + member.fieldname.string + '/main.libsonnet') | ||
else a.import_statement.new('./' + member.fieldname.string + '.libsonnet') | ||
), | ||
]), | ||
} | ||
+ (if depth != maxDepth && member.fieldname.string != 'global' | ||
then root.splitIntoFiles(member.expr, subdir + member.fieldname.string, depth + 1) | ||
else { | ||
[subdir + member.fieldname.string + '.libsonnet']: member.expr, | ||
}) | ||
else | ||
acc | ||
+ { | ||
[subdir + 'main.libsonnet']+: | ||
a.object.withMembersMixin([member]), | ||
} | ||
, | ||
objast.members, | ||
{ | ||
[subdir + 'main.libsonnet']: | ||
a.object.new([]), | ||
} | ||
), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
"subdir": "" | ||
} | ||
}, | ||
"version": "duologic/rfc1123" | ||
"version": "master" | ||
} | ||
], | ||
"legacyImports": true | ||
|
Oops, something went wrong.