diff --git a/.gitmodules b/.gitmodules index c2fad47..8f84209 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "build"] path = build - url = https://github.com/upbound/build + url = https://github.com/crossplane/build diff --git a/Makefile b/Makefile index 72ede00..2fbfbd4 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,64 @@ +# Usage +# ==================================================================================== +# Generic Makefile to be used across repositories building a crossplane configuration +# package +# +# Available targets: +# +# - `yamllint` +# Runs yamllint for all files in `api`-folder recursively +# +# - `render` +# Runs crossplane render to render the output of the composition. Usefule for quick +# feedback in order to test templating. +# Important note: +# Claims need following annotations in order for render to work (adjust the paths +# if necessary): +# render.crossplane.io/composition-path: apis/pat/composition.yaml +# render.crossplane.io/function-path: examples/functions.yaml +# This will only populate the cache. Use `render.show` to use the output +# +# - `render.show` +# Outputs the rendered yaml, useful for validating the rendered output manually +# or together with 'crossplane validate', e.g.: +# `make render.show | crossplane beta validate crossplane.yaml -` +# +# - `render.test` +# Executes kcl-unit tests on rendered manifests. Tests live in `test`-folder and +# can be written as normal kcl-tests +# +# - `e2e` +# Runs full end-to-end test, including creating cluster, setting up the configuration +# and testing if create, import and delete work as expected. +# In case the configuration creates resources on a cloud provider, it requires the following +# environment variables to be set: +# UPTEST_CLOUD_CREDENTIALS, cloud credentials for the provider being tested, e.g. +# - for aws: `export UPTEST_CLOUD_CREDENTIALS=$(cat ~/.aws/credentials)` +# - for gcp: `export UPTEST_CLOUD_CREDENTIALS=$(cat gcp-sa.json)` +# - for azure: `export UPTEST_CLOUD_CREDENTIALS=$(cat azure.json)` +# +# Available options: +# UPTEST_SKIP_DELETE (default `false`) skips the deletion of any resources created during the test +# UPTEST_SKIP_UPDATE (default `false`) skips testing the update of the claims +# UPTEST_SKIP_IMPORT (default `true`) skips testing the import of resources +# Example: +# `make e2e UPTEST_SKIP_DELETE=true` +# +# Language specific options: +# +# - `KCL` +# KCL_COMPOSITION_PATH can be set to the kcl-file creating composition.yaml. Default: `apis/kcl/generate.k` + # Project Setup -PROJECT_NAME := platform-ref-azure +# ==================================================================================== + +# Include project.mk for project specific settings +include project.mk + +ifndef PROJECT_NAME + $(error PROJECT_NAME is not set. Please create `project.mk` and set it there.) +endif + PROJECT_REPO := github.com/upbound/$(PROJECT_NAME) # NOTE(hasheddan): the platform is insignificant here as Configuration package @@ -11,15 +70,15 @@ PLATFORMS ?= linux_amd64 # ==================================================================================== # Setup Kubernetes tools -UP_VERSION = v0.31.0 +UP_VERSION = v0.34.0 UP_CHANNEL = stable -UPTEST_VERSION = v0.11.1 +CROSSPLANE_CLI_VERSION = v1.17.1 -include build/makelib/k8s_tools.mk # ==================================================================================== # Setup XPKG XPKG_DIR = $(shell pwd) -XPKG_IGNORE = .github/workflows/*.yaml,.github/workflows/*.yml,examples/*.yaml,.work/uptest-datasource.yaml +XPKG_IGNORE = .github/workflows/*.yaml,.github/workflows/*.yml,examples/*.yaml,.work/uptest-datasource.yaml,.cache/render/* XPKG_REG_ORGS ?= xpkg.upbound.io/upbound # NOTE(hasheddan): skip promoting on xpkg.upbound.io as channel tags are # inferred. @@ -27,11 +86,25 @@ XPKG_REG_ORGS_NO_PROMOTE ?= xpkg.upbound.io/upbound XPKGS = $(PROJECT_NAME) -include build/makelib/xpkg.mk +CROSSPLANE_VERSION = v1.17.1-up.1 +CROSSPLANE_CHART_REPO = https://charts.upbound.io/stable +CROSSPLANE_CHART_NAME = universal-crossplane CROSSPLANE_NAMESPACE = upbound-system CROSSPLANE_ARGS = "--enable-usages" +KIND_CLUSTER_NAME ?= uptest-$(PROJECT_NAME) + -include build/makelib/local.xpkg.mk -include build/makelib/controlplane.mk +# ==================================================================================== +# Testing + +UPTEST_VERSION = v1.1.2 +UPTEST_LOCAL_DEPLOY_TARGET = local.xpkg.deploy.configuration.$(PROJECT_NAME) +UPTEST_DEFAULT_TIMEOUT = 2400s + +-include build/makelib/uptest.mk + # ==================================================================================== # Targets @@ -46,8 +119,7 @@ fallthrough: submodules @echo Initial setup complete. Running make again . . . @make -# Update the submodules, such as the common build scripts. -submodules: +submodules: ## Update the submodules, such as the common build scripts. @git submodule sync @git submodule update --init --recursive @@ -55,23 +127,56 @@ submodules: # machinery sets UP to point to tool cache. build.init: $(UP) -# ==================================================================================== -# End to End Testing +# In case of building a composition with kcl, we must first render the composition-file +KCL_COMPOSITION_PATH ?= apis/kcl/generate.k +LANG_KCL := $(shell find ./apis -type f -name '*.k') +ifdef LANG_KCL +kcl: $(KCL) ## Generate KCL-based Composition + @$(INFO) Generating kcl composition + @$(KCL) $(KCL_COMPOSITION_PATH) 1>/dev/null + @$(OK) Generated kcl composition + +render: kcl +build.init: kcl +.PHONY: kcl +endif -# This target requires the following environment variables to be set: -# - UPTEST_CLOUD_CREDENTIALS, cloud credentials for the provider being tested, e.g. export UPTEST_CLOUD_CREDENTIALS=$(cat azure.json) -uptest: $(UPTEST) $(KUBECTL) $(KUTTL) - @$(INFO) running automated tests - @KUBECTL=$(KUBECTL) KUTTL=$(KUTTL) CROSSPLANE_NAMESPACE=$(CROSSPLANE_NAMESPACE) $(UPTEST) e2e examples/cluster-claim.yaml,examples/postgres-claim.yaml,examples/mariadb-claim.yaml,examples/app-claim.yaml --setup-script=test/setup.sh --default-timeout=2400 || $(FAIL) - @$(OK) running automated tests +render.test: $(CROSSPLANE_CLI) $(KCL) render + @echo find .cache/render -depth 1 -type f -name '*.yaml' + @for RENDERED_COMPOSITION in $$(find .cache/render -maxdepth 1 -type f -name '*.yaml'); do \ + $(INFO) "Testing $${RENDERED_COMPOSITION}"; \ + export RENDERED_COMPOSITION; \ + $(KCL) test test/ && \ + $(OK) "Success testing \"$${RENDERED_COMPOSITION}\"!" || \ + ($(ERR) "Failure testing \"$${RENDERED_COMPOSITION}\"!" && exit 1); \ + done; \ -# This target requires the following environment variables to be set: -# - UPTEST_CLOUD_CREDENTIALS, cloud credentials for the provider being tested, e.g. export UPTEST_CLOUD_CREDENTIALS=$(cat azure.json) -e2e: build controlplane.up local.xpkg.deploy.configuration.$(PROJECT_NAME) uptest +.PHONY: check-examples +check-examples: ## Check examples for sanity + @$(INFO) Checking if package versions in dependencies match examples + @FN_EXAMPLES=$$( \ + find examples -type f -name "*.yaml" | \ + xargs $(YQ) -r -o=json 'select(.kind == "Function" and (.apiVersion | test("^pkg.crossplane.io/"))) | .spec.package' | \ + sort -u); \ + FN_DEPS=$$( \ + $(YQ) '.spec.dependsOn[] | select(.function != null) | (.function + ":" + .version)' crossplane.yaml | \ + sort -u \ + ); \ + if [ "$$FN_EXAMPLES" != "$$FN_DEPS" ]; then \ + echo "Function package versions in examples and in crossplane.yaml don't match!"; \ + echo "" ; \ + echo "Versions in dependencies:"; \ + echo "---" ; \ + echo "$$FN_DEPS"; \ + echo "" ; \ + echo "Versions in examples:"; \ + echo "---" ; \ + echo "$$FN_EXAMPLES"; \ + exit 1; \ + fi; + @$(OK) Package versions are sane -yamllint: - @$(INFO) running yamllint - @yamllint ./apis || $(FAIL) - @$(OK) running yamllint +help.local: + @grep -E '^[a-zA-Z_-]+.*:.*?## .*$$' Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' -.PHONY: uptest e2e yamllint +.PHONY: uptest e2e render yamllint help.local diff --git a/build b/build index 2672eeb..cc14f9c 160000 --- a/build +++ b/build @@ -1 +1 @@ -Subproject commit 2672eeb767636ec837aa7c63cd7e26e6089fa810 +Subproject commit cc14f9cdac034e0eaaeb43479f57ee85d5490473 diff --git a/crossplane.yaml b/crossplane.yaml index 4f31ed0..5254a54 100644 --- a/crossplane.yaml +++ b/crossplane.yaml @@ -54,3 +54,6 @@ spec: - configuration: xpkg.upbound.io/upbound/configuration-gitops-flux # renovate: datasource=github-releases depName=upbound/configuration-gitops-flux version: "v0.7.0" + - function: xpkg.upbound.io/crossplane-contrib/function-patch-and-transform + # renovate: datasource=github-releases depName=crossplane-contrib/function-patch-and-transform + version: "v0.7.0" diff --git a/examples/cluster-claim.yaml b/examples/cluster-claim.yaml index fc1679e..8540afa 100644 --- a/examples/cluster-claim.yaml +++ b/examples/cluster-claim.yaml @@ -1,6 +1,9 @@ apiVersion: azure.platformref.upbound.io/v1alpha1 kind: Cluster metadata: + annotations: + render.crossplane.io/composition-path: apis/cluster/composition.yaml + render.crossplane.io/function-path: examples/functions.yaml name: platform-ref-azure-cluster namespace: default spec: diff --git a/examples/functions.yaml b/examples/functions.yaml new file mode 100644 index 0000000..e054781 --- /dev/null +++ b/examples/functions.yaml @@ -0,0 +1,6 @@ +apiVersion: pkg.crossplane.io/v1beta1 +kind: Function +metadata: + name: crossplane-contrib-function-patch-and-transform +spec: + package: xpkg.upbound.io/crossplane-contrib/function-patch-and-transform:v0.7.0 diff --git a/project.mk b/project.mk new file mode 100644 index 0000000..619679e --- /dev/null +++ b/project.mk @@ -0,0 +1,3 @@ +PROJECT_NAME := platform-ref-azure +UPTEST_INPUT_MANIFESTS := examples/cluster-claim.yaml,examples/postgres-claim.yaml,examples/mariadb-claim.yaml,examples/app-claim.yaml +UPTEST_SKIP_UPDATE := true