From 1cc439077ea71bf6b34412b1f816f4b767e64f77 Mon Sep 17 00:00:00 2001 From: Duologic Date: Mon, 2 Dec 2024 15:46:45 +0100 Subject: [PATCH 1/3] fix: refactor compositions into configurations --- Makefile | 12 +-- docs/README.md | 6 +- docs/compositions.md | 71 ----------------- docs/configurations.md | 22 ++++++ generator/compositions.libsonnet | 21 ----- generator/configurations.libsonnet | 19 ++++- grafanaplane/compositions.libsonnet | 106 -------------------------- grafanaplane/configurations.libsonnet | 106 ++++++++++++++++++++++++++ grafanaplane/main.libsonnet | 42 +++++----- grafanaplane/version.libsonnet | 2 +- 10 files changed, 171 insertions(+), 236 deletions(-) delete mode 100644 docs/compositions.md create mode 100644 docs/configurations.md delete mode 100644 generator/compositions.libsonnet delete mode 100644 grafanaplane/compositions.libsonnet create mode 100644 grafanaplane/configurations.libsonnet diff --git a/Makefile b/Makefile index 0e668d0..50289f3 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -LIBRARY_VERSION:=0.0.5 +LIBRARY_VERSION:=0.0.6 PROVIDER_VERSION:=0.21.0 JSONNET_BIN:=jrsonnet CROSSPLANE?=crank @@ -6,7 +6,7 @@ REGISTRY?=ghcr.io VENDOR_DEPTHS:=$(shell find generator/vendor -type f) -grafanaplane: grafanaplane/raw.libsonnet grafanaplane/compositions.libsonnet +grafanaplane: grafanaplane/raw.libsonnet grafanaplane/configurations.libsonnet generator/crds.yaml: cd generator && \ @@ -21,12 +21,12 @@ grafanaplane/raw.libsonnet: generator/main.libsonnet generator/namespaced.libson generator/main.libsonnet) && \ xargs -n1 jsonnetfmt -i <<< "$${FILES}" -grafanaplane/compositions.libsonnet: generator/compositions.libsonnet generator/namespaced.libsonnet generator/crds.yaml $(VENDOR_DEPTHS) +grafanaplane/configurations.libsonnet: generator/configurations.libsonnet generator/namespaced.libsonnet generator/crds.yaml $(VENDOR_DEPTHS) $(JSONNET_BIN) \ -J generator/vendor \ -A 'configurationVersion=$(LIBRARY_VERSION)-$(PROVIDER_VERSION)' \ - generator/compositions.libsonnet | \ - jsonnetfmt - > grafanaplane/compositions.libsonnet + generator/configurations.libsonnet | \ + jsonnetfmt - > grafanaplane/configurations.libsonnet packages: generator/packages.libsonnet generator/namespaced.libsonnet generator/crds.yaml $(VENDOR_DEPTHS) rm -rf packages && \ @@ -50,7 +50,7 @@ tag: git tag $(LIBRARY_VERSION)-$(PROVIDER_VERSION) .PHONY: build -build: grafanaplane/raw.libsonnet grafanaplane/compositions.libsonnet packages +build: grafanaplane/raw.libsonnet grafanaplane/configurations.libsonnet packages .PHONY: push push: push_packages diff --git a/docs/README.md b/docs/README.md index d3b3470..70481e9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -5,19 +5,19 @@ Jsonnet library providing a namespaced set of compositions/XRDs for the Grafana ## Install ``` -jb install github.com/Duologic/grafana-crossplane-libsonnet/grafanaplane@0.0.4-0.21.0 +jb install github.com/grafana/grafana-crossplane-libsonnet/grafanaplane@0.0.6-0.21.0 ``` ## Usage ```jsonnet -local grafanaplane = import 'github.com/Duologic/grafana-crossplane-libsonnet/grafanaplane/main.libsonnet'; +local grafanaplane = import 'github.com/grafana/grafana-crossplane-libsonnet/grafanaplane/main.libsonnet'; ``` ## Subpackages -* [compositions](compositions.md) +* [configurations](configurations.md) * [oss](oss/index.md) * [raw](raw/index.md) * [sm](sm/index.md) diff --git a/docs/compositions.md b/docs/compositions.md deleted file mode 100644 index 8e1f515..0000000 --- a/docs/compositions.md +++ /dev/null @@ -1,71 +0,0 @@ -# compositions - -This package contains the generated Compositions and CompositeResourceDefinitions (XRD). - -The compositions/XRDs can be imported like this: - -```jsonnet -local grafanaplane = import 'github.com/Duologic/grafana-crossplane-libsonnet/grafanaplane/main.libsonnet'; -local compositions = grafanaplane.compositions; - -[ - # Each composition has a `definition` and `composition` key - compositions.oss.v1alpha1.folder.composition, - compositions.oss.v1alpha1.folder.definition, - - # When using Tanka, then providing the higher level objects is also possible - compositions.cloud.v1alpha1.stack, # a composition/XRD pair - compositions.oss, # whole group of composition/XRD pairs -] -``` - -Available resources: - -- alerting.v1alpha1.contactPoint -- alerting.v1alpha1.messageTemplate -- alerting.v1alpha1.muteTiming -- alerting.v1alpha1.notificationPolicy -- alerting.v1alpha1.ruleGroup -- cloud.v1alpha1.accessPolicy -- cloud.v1alpha1.accessPolicyToken -- cloud.v1alpha1.pluginInstallation -- cloud.v1alpha1.stack -- cloud.v1alpha1.stackServiceAccount -- cloud.v1alpha1.stackServiceAccountToken -- enterprise.v1alpha1.dataSourcePermission -- enterprise.v1alpha1.report -- enterprise.v1alpha1.role -- enterprise.v1alpha1.roleAssignment -- enterprise.v1alpha1.teamExternalGroup -- ml.v1alpha1.holiday -- ml.v1alpha1.job -- ml.v1alpha1.outlierDetector -- oncall.v1alpha1.escalation -- oncall.v1alpha1.escalationChain -- oncall.v1alpha1.integration -- oncall.v1alpha1.onCallShift -- oncall.v1alpha1.outgoingWebhook -- oncall.v1alpha1.route -- oncall.v1alpha1.schedule -- oncall.v1alpha1.userNotificationRule -- oss.v1alpha1.annotation -- oss.v1alpha1.dashboard -- oss.v1alpha1.dashboardPermission -- oss.v1alpha1.dashboardPublic -- oss.v1alpha1.dataSource -- oss.v1alpha1.folder -- oss.v1alpha1.folderPermission -- oss.v1alpha1.libraryPanel -- oss.v1alpha1.organization -- oss.v1alpha1.organizationPreferences -- oss.v1alpha1.playlist -- oss.v1alpha1.serviceAccount -- oss.v1alpha1.serviceAccountPermission -- oss.v1alpha1.serviceAccountToken -- oss.v1alpha1.ssoSettings -- oss.v1alpha1.team -- oss.v1alpha1.user -- slo.v1alpha1.slo -- sm.v1alpha1.check -- sm.v1alpha1.installation -- sm.v1alpha1.probe diff --git a/docs/configurations.md b/docs/configurations.md new file mode 100644 index 0000000..7a3dd5d --- /dev/null +++ b/docs/configurations.md @@ -0,0 +1,22 @@ +# configurations + +This package contains Configurations for the generated Compositions and CompositeResourceDefinitions (XRD). A single configuration imports compositions for a resource group. + +The Configurations can be imported like this: + +```jsonnet +local grafanaplane = import 'github.com/grafana/grafana-crossplane-libsonnet/grafanaplane/main.libsonnet'; +local configurations = grafanaplane.configurations; + +[ + configuration.alerting, + configuration.cloud, + configuration.enterprise, + configuration.ml, + configuration.oncall, + configuration.oss, + configuration.slo, + configuration.sm +] +``` + diff --git a/generator/compositions.libsonnet b/generator/compositions.libsonnet deleted file mode 100644 index ec1dae6..0000000 --- a/generator/compositions.libsonnet +++ /dev/null @@ -1,21 +0,0 @@ -local namespaced = import './namespaced.libsonnet'; -local crossplane = import 'github.com/jsonnet-libs/crossplane-libsonnet/crossplane/1.14/main.libsonnet'; - -local configuration(key, version) = - local conf = crossplane.pkg.v1.configuration; - conf.new(key) - + conf.spec.withPackage('xpkg.upbound.io/grafana/' + key + ':' + version); - -local groups = - std.set( - std.map( - function(def) - def.definition.spec.group, - namespaced - ) - ); - -function(configurationVersion) { - [group]: configuration(group, configurationVersion) - for group in groups -} diff --git a/generator/configurations.libsonnet b/generator/configurations.libsonnet index 65b04f7..3b36506 100644 --- a/generator/configurations.libsonnet +++ b/generator/configurations.libsonnet @@ -1,8 +1,21 @@ +local namespaced = import './namespaced.libsonnet'; local crossplane = import 'github.com/jsonnet-libs/crossplane-libsonnet/crossplane/1.14/main.libsonnet'; -local configuration(key) = +local configuration(key, version) = local conf = crossplane.pkg.v1.configuration; conf.new(key) - + conf.spec.withPackage('xpkg.upbound.io/grafana/' + key); + + conf.spec.withPackage('ghcr.io/grafana/crossplane/' + key + ':' + version); -{} +local groups = + std.set( + std.map( + function(def) + std.splitLimit(def.definition.spec.group, '.', 1)[0], + namespaced + ) + ); + +function(configurationVersion) { + [group]: configuration(group, configurationVersion) + for group in groups +} diff --git a/grafanaplane/compositions.libsonnet b/grafanaplane/compositions.libsonnet deleted file mode 100644 index e220faa..0000000 --- a/grafanaplane/compositions.libsonnet +++ /dev/null @@ -1,106 +0,0 @@ -{ - 'alerting.grafana.crossplane.io.namespaced': { - apiVersion: 'pkg.crossplane.io/v1', - kind: 'Configuration', - metadata: { - annotations: { - 'tanka.dev/namespaced': 'false', - }, - name: 'alerting.grafana.crossplane.io.namespaced', - }, - spec: { - package: 'xpkg.upbound.io/grafana/alerting.grafana.crossplane.io.namespaced:0.0.4-0.21.0', - }, - }, - 'cloud.grafana.crossplane.io.namespaced': { - apiVersion: 'pkg.crossplane.io/v1', - kind: 'Configuration', - metadata: { - annotations: { - 'tanka.dev/namespaced': 'false', - }, - name: 'cloud.grafana.crossplane.io.namespaced', - }, - spec: { - package: 'xpkg.upbound.io/grafana/cloud.grafana.crossplane.io.namespaced:0.0.4-0.21.0', - }, - }, - 'enterprise.grafana.crossplane.io.namespaced': { - apiVersion: 'pkg.crossplane.io/v1', - kind: 'Configuration', - metadata: { - annotations: { - 'tanka.dev/namespaced': 'false', - }, - name: 'enterprise.grafana.crossplane.io.namespaced', - }, - spec: { - package: 'xpkg.upbound.io/grafana/enterprise.grafana.crossplane.io.namespaced:0.0.4-0.21.0', - }, - }, - 'ml.grafana.crossplane.io.namespaced': { - apiVersion: 'pkg.crossplane.io/v1', - kind: 'Configuration', - metadata: { - annotations: { - 'tanka.dev/namespaced': 'false', - }, - name: 'ml.grafana.crossplane.io.namespaced', - }, - spec: { - package: 'xpkg.upbound.io/grafana/ml.grafana.crossplane.io.namespaced:0.0.4-0.21.0', - }, - }, - 'oncall.grafana.crossplane.io.namespaced': { - apiVersion: 'pkg.crossplane.io/v1', - kind: 'Configuration', - metadata: { - annotations: { - 'tanka.dev/namespaced': 'false', - }, - name: 'oncall.grafana.crossplane.io.namespaced', - }, - spec: { - package: 'xpkg.upbound.io/grafana/oncall.grafana.crossplane.io.namespaced:0.0.4-0.21.0', - }, - }, - 'oss.grafana.crossplane.io.namespaced': { - apiVersion: 'pkg.crossplane.io/v1', - kind: 'Configuration', - metadata: { - annotations: { - 'tanka.dev/namespaced': 'false', - }, - name: 'oss.grafana.crossplane.io.namespaced', - }, - spec: { - package: 'xpkg.upbound.io/grafana/oss.grafana.crossplane.io.namespaced:0.0.4-0.21.0', - }, - }, - 'slo.grafana.crossplane.io.namespaced': { - apiVersion: 'pkg.crossplane.io/v1', - kind: 'Configuration', - metadata: { - annotations: { - 'tanka.dev/namespaced': 'false', - }, - name: 'slo.grafana.crossplane.io.namespaced', - }, - spec: { - package: 'xpkg.upbound.io/grafana/slo.grafana.crossplane.io.namespaced:0.0.4-0.21.0', - }, - }, - 'sm.grafana.crossplane.io.namespaced': { - apiVersion: 'pkg.crossplane.io/v1', - kind: 'Configuration', - metadata: { - annotations: { - 'tanka.dev/namespaced': 'false', - }, - name: 'sm.grafana.crossplane.io.namespaced', - }, - spec: { - package: 'xpkg.upbound.io/grafana/sm.grafana.crossplane.io.namespaced:0.0.4-0.21.0', - }, - }, -} diff --git a/grafanaplane/configurations.libsonnet b/grafanaplane/configurations.libsonnet new file mode 100644 index 0000000..822abf9 --- /dev/null +++ b/grafanaplane/configurations.libsonnet @@ -0,0 +1,106 @@ +{ + alerting: { + apiVersion: 'pkg.crossplane.io/v1', + kind: 'Configuration', + metadata: { + annotations: { + 'tanka.dev/namespaced': 'false', + }, + name: 'alerting', + }, + spec: { + package: 'ghcr.io/grafana/crossplane/alerting:0.0.6-0.21.0', + }, + }, + cloud: { + apiVersion: 'pkg.crossplane.io/v1', + kind: 'Configuration', + metadata: { + annotations: { + 'tanka.dev/namespaced': 'false', + }, + name: 'cloud', + }, + spec: { + package: 'ghcr.io/grafana/crossplane/cloud:0.0.6-0.21.0', + }, + }, + enterprise: { + apiVersion: 'pkg.crossplane.io/v1', + kind: 'Configuration', + metadata: { + annotations: { + 'tanka.dev/namespaced': 'false', + }, + name: 'enterprise', + }, + spec: { + package: 'ghcr.io/grafana/crossplane/enterprise:0.0.6-0.21.0', + }, + }, + ml: { + apiVersion: 'pkg.crossplane.io/v1', + kind: 'Configuration', + metadata: { + annotations: { + 'tanka.dev/namespaced': 'false', + }, + name: 'ml', + }, + spec: { + package: 'ghcr.io/grafana/crossplane/ml:0.0.6-0.21.0', + }, + }, + oncall: { + apiVersion: 'pkg.crossplane.io/v1', + kind: 'Configuration', + metadata: { + annotations: { + 'tanka.dev/namespaced': 'false', + }, + name: 'oncall', + }, + spec: { + package: 'ghcr.io/grafana/crossplane/oncall:0.0.6-0.21.0', + }, + }, + oss: { + apiVersion: 'pkg.crossplane.io/v1', + kind: 'Configuration', + metadata: { + annotations: { + 'tanka.dev/namespaced': 'false', + }, + name: 'oss', + }, + spec: { + package: 'ghcr.io/grafana/crossplane/oss:0.0.6-0.21.0', + }, + }, + slo: { + apiVersion: 'pkg.crossplane.io/v1', + kind: 'Configuration', + metadata: { + annotations: { + 'tanka.dev/namespaced': 'false', + }, + name: 'slo', + }, + spec: { + package: 'ghcr.io/grafana/crossplane/slo:0.0.6-0.21.0', + }, + }, + sm: { + apiVersion: 'pkg.crossplane.io/v1', + kind: 'Configuration', + metadata: { + annotations: { + 'tanka.dev/namespaced': 'false', + }, + name: 'sm', + }, + spec: { + package: 'ghcr.io/grafana/crossplane/sm:0.0.6-0.21.0', + }, + }, +} diff --git a/grafanaplane/main.libsonnet b/grafanaplane/main.libsonnet index d82f6f2..fd85f9e 100644 --- a/grafanaplane/main.libsonnet +++ b/grafanaplane/main.libsonnet @@ -1,7 +1,7 @@ local d = import 'github.com/jsonnet-libs/docsonnet/doc-util/main.libsonnet'; local xtd = import 'github.com/jsonnet-libs/xtd/main.libsonnet'; -local compositions = import './compositions.libsonnet'; +local configurations = import './configurations.libsonnet'; local raw = import './raw.libsonnet'; { @@ -10,7 +10,7 @@ local raw = import './raw.libsonnet'; '#': d.package.new( 'grafanaplane', - 'github.com/Duologic/grafana-crossplane-libsonnet/grafanaplane', + 'github.com/grafana/grafana-crossplane-libsonnet/grafanaplane', ||| Jsonnet library providing a namespaced set of compositions/XRDs for the Grafana Crossplane provider. The compositions, XRDs and the library for creating the XRD objects is generated. |||, @@ -25,41 +25,33 @@ local raw = import './raw.libsonnet'; raw + { '#': d.package.newSub('raw', "Generated libraries for all the compositions in case the manually curated functions aren't sufficient.") }, - compositions: - compositions + configurations: + configurations + { '#': d.package.newSub( - 'compositions', + 'configurations', ||| - This package contains the generated Compositions and CompositeResourceDefinitions (XRD). + This package contains Configurations for the generated Compositions and CompositeResourceDefinitions (XRD). A single configuration imports compositions for a resource group. - The compositions/XRDs can be imported like this: + The Configurations can be imported like this: ```jsonnet - local grafanaplane = import 'github.com/Duologic/grafana-crossplane-libsonnet/grafanaplane/main.libsonnet'; - local compositions = grafanaplane.compositions; + local grafanaplane = import 'github.com/grafana/grafana-crossplane-libsonnet/grafanaplane/main.libsonnet'; + local configurations = grafanaplane.configurations; [ - # Each composition has a `definition` and `composition` key - compositions.oss.v1alpha1.folder.composition, - compositions.oss.v1alpha1.folder.definition, - - # When using Tanka, then providing the higher level objects is also possible - compositions.cloud.v1alpha1.stack, # a composition/XRD pair - compositions.oss, # whole group of composition/XRD pairs + %s ] ``` - - Available resources: - ||| - + '- ' + std.join('\n- ', [ - std.join('.', [group.key, version.key, kind]) - for group in std.objectKeysValues(compositions) - for version in std.objectKeysValues(group.value) - for kind in std.objectFields(version.value) - ]) + % std.join( + ',\n', + std.map( + function(item) ' configuration.' + item, + std.objectFields(configurations) + ) + ) ), }, diff --git a/grafanaplane/version.libsonnet b/grafanaplane/version.libsonnet index b883b7e..a3fc926 100644 --- a/grafanaplane/version.libsonnet +++ b/grafanaplane/version.libsonnet @@ -1 +1 @@ -'0.0.4-0.21.0' +'0.0.6-0.21.0' From fa9731f785f73b68b04214296db2ece664a3a908 Mon Sep 17 00:00:00 2001 From: Duologic Date: Mon, 2 Dec 2024 15:58:56 +0100 Subject: [PATCH 2/3] docs --- docs/README.md | 8 +++++++- docs/configurations.md | 2 +- grafanaplane/main.libsonnet | 10 ++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/docs/README.md b/docs/README.md index 70481e9..61c4235 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,6 +1,12 @@ # grafanaplane -Jsonnet library providing a namespaced set of compositions/XRDs for the Grafana Crossplane provider. The compositions, XRDs and the library for creating the XRD objects is generated. +This repository provides a set of Crossplane Configurations packages and and accompanying Jsonnet library. + +The Configuration packages provide a set of (namespaced) composition/XRD pairs that map directly to their non-namespaced Managed resources equivalents. + +The library consists of two parts, the manually written functions to get started quicly and the full library in `raw/`. They can be used in combination with each other. + +Most of this library is generated: the Compositions/XRDs packages, Configurations and the library in `raw/`. ## Install diff --git a/docs/configurations.md b/docs/configurations.md index 7a3dd5d..983d5b2 100644 --- a/docs/configurations.md +++ b/docs/configurations.md @@ -1,6 +1,6 @@ # configurations -This package contains Configurations for the generated Compositions and CompositeResourceDefinitions (XRD). A single configuration imports compositions for a resource group. +This package contains Configurations for the generated Compositions and CompositeResourceDefinitions (XRD). A single configuration imports compositions for a resource group. For more granular selection of XRDs, consider using the manifests in 'packages/' on the root of this repository. The Configurations can be imported like this: diff --git a/grafanaplane/main.libsonnet b/grafanaplane/main.libsonnet index fd85f9e..3d8243c 100644 --- a/grafanaplane/main.libsonnet +++ b/grafanaplane/main.libsonnet @@ -12,7 +12,13 @@ local raw = import './raw.libsonnet'; 'grafanaplane', 'github.com/grafana/grafana-crossplane-libsonnet/grafanaplane', ||| - Jsonnet library providing a namespaced set of compositions/XRDs for the Grafana Crossplane provider. The compositions, XRDs and the library for creating the XRD objects is generated. + This repository provides a set of Crossplane Configurations packages and and accompanying Jsonnet library. + + The Configuration packages provide a set of (namespaced) composition/XRD pairs that map directly to their non-namespaced Managed resources equivalents. + + The library consists of two parts, the manually written functions to get started quicly and the full library in `raw/`. They can be used in combination with each other. + + Most of this library is generated: the Compositions/XRDs packages, Configurations and the library in `raw/`. |||, 'main.libsonnet', import 'version.libsonnet', @@ -32,7 +38,7 @@ local raw = import './raw.libsonnet'; d.package.newSub( 'configurations', ||| - This package contains Configurations for the generated Compositions and CompositeResourceDefinitions (XRD). A single configuration imports compositions for a resource group. + This package contains Configurations for the generated Compositions and CompositeResourceDefinitions (XRD). A single configuration imports compositions for a resource group. For more granular selection of XRDs, consider using the manifests in 'packages/' on the root of this repository. The Configurations can be imported like this: From 8167453892cea56a253d50c8fb820707f0dd9434 Mon Sep 17 00:00:00 2001 From: Duologic Date: Mon, 2 Dec 2024 16:00:22 +0100 Subject: [PATCH 3/3] ci: always run make build - set shell - setup jrsonnet - setup jsonnetfmt --- .github/workflows/build.yaml | 20 +++++++++++++++++--- Makefile | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 6454b93..2947218 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -27,17 +27,31 @@ jobs: version: ${{ github.event.inputs.version }} command: -h + - name: move crossplane cli + run: "mkdir -p $TARGET_PATH && mv ./crossplane $TARGET_PATH" + env: + TARGET_PATH: "${{ github.workspace }}/bin" + + - name: setup jsonnet-fmt + run: | + go install "github.com/google/go-jsonnet/cmd/jsonnetfmt@v0.20.0" + echo "$HOME/go/bin" >> "$GITHUB_PATH" + + - name: setup jrsonnet + uses: Duologic/tanka-exporter-workflow/.github/actions/jrsonnet-install@main + - name: Build xpkg - run: make build + run: "make -B build" + shell: bash env: - CROSSPLANE: './crossplane' + CROSSPLANE: '${{ github.workspace }}/bin/crossplane' - name: Check if file changed id: changed uses: tj-actions/verify-changed-files@v20 with: files: | - !crossplane + !bin - name: No files changed if: "${{ steps.changed.outputs.files_changed == 'true' }}" diff --git a/Makefile b/Makefile index 50289f3..6368025 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ PROVIDER_VERSION:=0.21.0 JSONNET_BIN:=jrsonnet CROSSPLANE?=crank REGISTRY?=ghcr.io +SHELL:=/bin/bash VENDOR_DEPTHS:=$(shell find generator/vendor -type f)