Skip to content

Commit

Permalink
feat: move compositions to configuration packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Duologic committed Nov 29, 2024
1 parent b68c524 commit 3e5e2cf
Show file tree
Hide file tree
Showing 110 changed files with 14,767 additions and 46,308 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Build

on:
pull_request: {}
push:
branches:
- main
workflow_dispatch:
inputs:
channel:
description: release channel
required: true
default: stable
version:
description: release version
required: true
default: current

#env:
# DOCKER_USR: ${{ secrets.DOCKER_USR }}

jobs:
test:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4

- name: setup Crossplane cli
uses: crossplane-contrib/xpkg-action@master
with:
channel: ${{ github.event.inputs.channel }}
version: ${{ github.event.inputs.version }}
command: -h

- name: Build xpkg
run: make output
env:
CROSSPLANE: './crossplane'

# - name: Login to Docker
# uses: docker/login-action@v3
# if: env.DOCKER_USR != ''
# with:
# registry: registry.upbound.io
# username: ${{ secrets.DOCKER_USR }}
# password: ${{ secrets.DOCKER_PSW }}

# - name: Push xpkg
# uses: crossplane-contrib/xpkg-action@master
# with:
# command: push configuration -f test/xpkg-action-test/xpkg-action-test.xpkg registry.upbound.io/crossplane-test/xpkg-action-test:v0.0.1
20 changes: 18 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
LIBRARY_VERSION:=0.0.4
PROVIDER_VERSION:=0.21.0
JSONNET_BIN:=jrsonnet
CROSSPLANE?=crank

VENDOR_DEPTHS:=$(shell find generator/vendor -type f)

Expand All @@ -11,11 +12,26 @@ generator/crds.yaml:
curl -sLO https://github.com/grafana/crossplane-provider-grafana/releases/download/v$(PROVIDER_VERSION)/crds.yaml

grafanaplane/raw.libsonnet: generator/main.libsonnet generator/namespaced.libsonnet generator/crds.yaml $(VENDOR_DEPTHS)
FILES=$$($(JSONNET_BIN) -S -c -m grafanaplane -J generator/vendor -A 'version=$(LIBRARY_VERSION)-$(PROVIDER_VERSION)' generator/main.libsonnet) && \
FILES=$$($(JSONNET_BIN) \
-S -c -m grafanaplane \
-J generator/vendor \
-A 'version=$(LIBRARY_VERSION)-$(PROVIDER_VERSION)' \
generator/main.libsonnet) && \
xargs -n1 jsonnetfmt -i <<< "$${FILES}"

grafanaplane/compositions.libsonnet: generator/compositions.libsonnet generator/namespaced.libsonnet generator/crds.yaml $(VENDOR_DEPTHS)
$(JSONNET_BIN) -J generator/vendor generator/compositions.libsonnet | jsonnetfmt - > grafanaplane/compositions.libsonnet
$(JSONNET_BIN) \
-J generator/vendor generator/compositions.libsonnet \
-A 'configurationVersion=$(LIBRARY_VERSION)-$(PROVIDER_VERSION)'| \
jsonnetfmt - > grafanaplane/compositions.libsonnet

packages: generator/packages.libsonnet generator/namespaced.libsonnet generator/crds.yaml $(VENDOR_DEPTHS)
$(JSONNET_BIN) -S -m packages -c -J generator/vendor generator/packages.libsonnet

packages=$(wildcard packages/*)
output: packages $(packages)
rm -rf output && mkdir -p output/packages
$(foreach pkg,$(packages),$(CROSSPLANE) xpkg build --package-root=$(pkg) --package-file=output/$(pkg)-$(LIBRARY_VERSION)-$(PROVIDER_VERSION).xpkg;)

docs: $(shell find grafanaplane/ -type f)
@rm -rf docs/
Expand Down
35 changes: 17 additions & 18 deletions generator/compositions.libsonnet
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
local namespaced = import './namespaced.libsonnet';
local crossplane = import 'github.com/jsonnet-libs/crossplane-libsonnet/crossplane/1.14/main.libsonnet';

local helpers = import 'github.com/crdsonnet/crdsonnet/crdsonnet/helpers.libsonnet';
local crdsonnet = import 'github.com/crdsonnet/crdsonnet/crdsonnet/main.libsonnet';
local configuration(key, version) =
local conf = crossplane.pkg.v1.configuration;
conf.new(key)
+ conf.spec.withPackage('xpkg.upbound.io/grafana/' + key + ':' + version);

std.foldl(
function(acc, def)
local group = helpers.getGroupKey(def.definition.spec.group, 'grafana.crossplane.io');
local version = 'v1alpha1';
local kind = helpers.camelCaseKind(crdsonnet.xrd.getKind(def.definition));
local groups =
std.set(
std.map(
function(def)
def.definition.spec.group,
namespaced
)
);

acc + {
[group]+: {
[version]+: {
[kind]+:
def,
},
},
},
namespaced,
{}
)
function(configurationVersion) {
[group]: configuration(group, configurationVersion)
for group in groups
}
8 changes: 8 additions & 0 deletions generator/configurations.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
local crossplane = import 'github.com/jsonnet-libs/crossplane-libsonnet/crossplane/1.14/main.libsonnet';

local configuration(key) =
local conf = crossplane.pkg.v1.configuration;
conf.new(key)
+ conf.spec.withPackage('xpkg.upbound.io/grafana/' + key);

{}
34 changes: 34 additions & 0 deletions generator/packages.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
local crossplane = import 'github.com/jsonnet-libs/crossplane-libsonnet/crossplane/1.14/main.libsonnet';
local namespaced = import 'namespaced.libsonnet';

local package(key) =
local metaConf = crossplane.meta.v1.configuration;
metaConf.new(key)
+ metaConf.metadata.withAnnotations({
'meta.crossplane.io/maintainer': 'Grafana',
'meta.crossplane.io/source': 'github.com/grafana/grafana-crossplane-libsonnet',
'meta.crossplane.io/license': 'Apache-2.0',
'meta.crossplane.io/description': 'This configuration provides Compositions that map 1:1 to the managed resources with the only goal is to provide a namespaced resource of the same managed resource.',
})
+ metaConf.spec.crossplane.withVersion('>=v1.17')
+ metaConf.spec.withDependsOn(
metaConf.spec.dependsOn.withProvider('xpkg.upbound.io/grafana/provider-grafana')
+ metaConf.spec.dependsOn.withVersion('>=v0.21.0')
);

local manifest(value) = std.manifestYamlDoc(value, true, false);

std.foldl(
function(acc, item)
local group = item.definition.spec.group;
local kind = item.definition.spec.claimNames.kind;
acc
+ {
[group + '/package.yaml']: manifest(package(group)),
[group + '/Composition-' + kind + '.yaml']: manifest(item.composition),
[group + '/CompositeResourceDefinition-' + kind + '.yaml']: manifest(item.composition),
},
namespaced,
{}
)

Loading

0 comments on commit 3e5e2cf

Please sign in to comment.