Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move compositions to configuration packages #4

Merged
merged 6 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
46 changes: 46 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build

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

jobs:
build:
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 build
env:
CROSSPLANE: './crossplane'

- name: Check if file changed
id: changed
uses: tj-actions/verify-changed-files@v20
with:
files: |
!crossplane

- name: No files changed
if: "${{ steps.changed.outputs.files_changed == 'true' }}"
run: "echo 'Please run `make build`' && exit 1"
env:
CHANGED_FILES: "${{ steps.changed.outputs.changed_files }}"
47 changes: 47 additions & 0 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build

on:
push:
tags:
- '*'
workflow_dispatch:
inputs:
channel:
description: release channel
required: true
default: stable
version:
description: release version
required: true
default: current

env:
UPBOUND_MARKETPLACE_PUSH_ROBOT_USR: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR }}

jobs:
build:
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: Login to Upbound
uses: docker/login-action@v3
if: env.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR != ''
with:
registry: xpkg.upbound.io
username: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR }}
password: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_PSW }}

- name: Push xpkg
run: make push
if: ${{ github.ref == 'refs/heads/main' }} && env.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR != ''
env:
CROSSPLANE: './crossplane'
30 changes: 28 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,30 @@ 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) && \
rm -rf grafanaplane/raw && \
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 \
-A 'configurationVersion=$(LIBRARY_VERSION)-$(PROVIDER_VERSION)' \
generator/compositions.libsonnet | \
jsonnetfmt - > grafanaplane/compositions.libsonnet

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

packages=$(wildcard packages/*)
push_packages: packages $(packages)
rm -rf output && mkdir -p output/
$(foreach pkg,$(packages),$(CROSSPLANE) xpkg build --package-root=$(pkg) --package-file=output/$(patsubst packages/%,%,$(pkg)).xpkg;)
$(foreach pkg,$(packages),$(CROSSPLANE) xpkg push configuration -f output/$(patsubst packages/%,%,$(pkg)).xpkg registry.upbound.io/grafana/$(patsubst packages/%,%,$(pkg)).xpkg:v$(LIBRARY_VERSION)-$(PROVIDER_VERSION);)

docs: $(shell find grafanaplane/ -type f)
@rm -rf docs/
Expand All @@ -27,3 +47,9 @@ docs: $(shell find grafanaplane/ -type f)
.PHONY: tag
tag:
git tag $(LIBRARY_VERSION)-$(PROVIDER_VERSION)

.PHONY: build
build: grafanaplane/raw.libsonnet grafanaplane/compositions.libsonnet packages

.PHONY: push
push: push_packages
1 change: 0 additions & 1 deletion generator/.gitignore

This file was deleted.

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);

{}
8 changes: 4 additions & 4 deletions generator/jsonnetfile.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"subdir": ""
}
},
"version": "4f3ca583ccfa4f6833abe75428677a005bc6b486",
"version": "349569e180192547cb37cb94b3caea05384a81ff",
"sum": "0N0SeOSZeD1DaVp7Avj9WpTRVt3tdPrAjxZ0qWr/xrU="
},
{
Expand All @@ -28,8 +28,8 @@
"subdir": ""
}
},
"version": "f810e234468906b2d05b091ae1b5f8c6047090a4",
"sum": "Q1BAaS0EIkBXdOOGXfQrnJlo1wvlVd2JTRIRUhfxTj0="
"version": "0c82db246c00af8a25ead5240d82db195febee60",
"sum": "zgyJG+0zLt/9OreKeHzJD4NaEltwwMYJ5O5obKBk35I="
},
{
"source": {
Expand Down Expand Up @@ -58,7 +58,7 @@
"subdir": "crossplane/1.14"
}
},
"version": "b8c879544f4292f788770373c900f9fde696a23b",
"version": "4a23ed218573867f36482f8e61f5fc1e53e2b3ba",
"sum": "40w1wppQmnIUUMoWAY5sd3rWl6HwKhIuSb/8XNBjJCY=",
"name": "crossplane"
},
Expand Down
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 configurationName = 'grafana-namespaced-' + std.splitLimit(group, '.', 1)[0];
local kind = item.definition.spec.claimNames.kind;
acc
+ {
[configurationName + '/package.yaml']: manifest(package(configurationName)),
[configurationName + '/Composition-' + kind + '.yaml']: manifest(item.composition),
[configurationName + '/CompositeResourceDefinition-' + kind + '.yaml']: manifest(item.composition),
},
namespaced,
{}
)

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading