Skip to content

Commit

Permalink
Switch to build-module targets for e2e, uptest, render and yamllint a…
Browse files Browse the repository at this point in the history
…nd pull out project-specifc settings (#54)

* Switch to build-module targets for e2e, uptest, render and yamllint and pull out project-specifc settings

* PR feedback

* Fix comments
  • Loading branch information
kaessert authored Oct 10, 2024
1 parent c89db02 commit 308aafc
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 68 deletions.
113 changes: 47 additions & 66 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
# 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
#
# - `e2e`
# Runs full end-to-end test, including creating cluster, setting up the configuration
# and testing if create, import and delete work as expected.
# 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`

# Project Setup
PROJECT_NAME := configuration-app
# ====================================================================================

# 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
Expand All @@ -13,8 +50,6 @@ PLATFORMS ?= linux_amd64

UP_VERSION = v0.34.0
UP_CHANNEL = stable
UPTEST_VERSION = v1.1.2
UPTEST_CLAIMS ?= examples/app-claim.yaml
CROSSPLANE_CLI_VERSION = v1.17.1

-include build/makelib/k8s_tools.mk
Expand All @@ -39,6 +74,15 @@ 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

Expand All @@ -62,69 +106,6 @@ submodules:
# machinery sets UP to point to tool cache.
build.init: $(UP)

# ====================================================================================
# End to End Testing

UPTEST_EXTRA_ARGS ?=

UPTEST_COMMAND = SKIP_DEPLOY_ARGO=$(SKIP_DEPLOY_ARGO) \
KUBECTL=$(KUBECTL) \
CHAINSAW=$(CHAINSAW) \
CROSSPLANE_CLI=$(CROSSPLANE_CLI) \
CROSSPLANE_NAMESPACE=$(CROSSPLANE_NAMESPACE) \
YQ=$(YQ) \
$(UPTEST) e2e $(UPTEST_CLAIMS) \
--data-source="${UPTEST_DATASOURCE_PATH}" \
--setup-script=$(SETUP_SCRIPT) \
--default-timeout=2400s \
--skip-update \
--skip-import \
$(UPTEST_EXTRA_ARGS)

# This target requires the following environment variables to be set:
# - To ensure the proper functioning of the end-to-end test resource pre-deletion hook, it is crucial to arrange your resources appropriately.
# You can check the basic implementation here: https://github.com/upbound/uptest/blob/main/internal/templates/01-delete.yaml.tmpl.
# - UPTEST_DATASOURCE_PATH (optional), see https://github.com/upbound/uptest#injecting-dynamic-values-and-datasource
SETUP_SCRIPT ?= test/setup.sh
uptest: $(UPTEST) $(KUBECTL) $(CHAINSAW) $(CROSSPLANE_CLI) $(YQ)
@$(INFO) running automated tests
$(UPTEST_COMMAND) || $(FAIL)
@$(OK) running automated tests

# Run uptest together with all dependencies. Use `make e2e UPTEST_EXTRA_ARGS=--skip-delete` to skip deletion of resources.
e2e: build controlplane.down controlplane.up local.xpkg.deploy.configuration.$(PROJECT_NAME) uptest #

render: $(CROSSPLANE_CLI) ${YQ}
@indir="./examples"; \
for file in $$(find $$indir -type f -name '*.yaml' ); do \
doc_count=$$(grep -c '^---' "$$file"); \
if [[ $$doc_count -gt 0 ]]; then \
continue; \
fi; \
COMPOSITION=$$(${YQ} eval '.metadata.annotations."render.crossplane.io/composition-path"' $$file); \
FUNCTION=$$(${YQ} eval '.metadata.annotations."render.crossplane.io/function-path"' $$file); \
ENVIRONMENT=$$(${YQ} eval '.metadata.annotations."render.crossplane.io/environment-path"' $$file); \
OBSERVE=$$(${YQ} eval '.metadata.annotations."render.crossplane.io/observe-path"' $$file); \
if [[ "$$ENVIRONMENT" == "null" ]]; then \
ENVIRONMENT=""; \
fi; \
if [[ "$$OBSERVE" == "null" ]]; then \
OBSERVE=""; \
fi; \
if [[ "$$COMPOSITION" == "null" || "$$FUNCTION" == "null" ]]; then \
continue; \
fi; \
ENVIRONMENT=$${ENVIRONMENT=="null" ? "" : $$ENVIRONMENT}; \
OBSERVE=$${OBSERVE=="null" ? "" : $$OBSERVE}; \
$(CROSSPLANE_CLI) render $$file $$COMPOSITION $$FUNCTION $${ENVIRONMENT:+-e $$ENVIRONMENT} $${OBSERVE:+-o $$OBSERVE} -x; \
done

yamllint: ## Static yamllint check
@$(INFO) running yamllint
@yamllint ./apis || $(FAIL)
@$(OK) running yamllint

.PHONY: uptest e2e render yamllint

help.local:
@grep -E '^[a-zA-Z_-]+.*:.*?## .*$$' Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
File renamed without changes.
2 changes: 1 addition & 1 deletion build
Submodule build updated 1 files
+90 −0 makelib/uptest.mk
2 changes: 1 addition & 1 deletion examples/app-claim.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: platform.upbound.io/v1alpha1
kind: App
metadata:
annotations:
render.crossplane.io/composition-path: apis/composition.yaml
render.crossplane.io/composition-path: apis/pat/composition.yaml
render.crossplane.io/function-path: examples/functions.yaml
name: configuration-app
namespace: default
Expand Down
4 changes: 4 additions & 0 deletions project.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PROJECT_NAME := configuration-app
UPTEST_INPUT_MANIFESTS := examples/app-claim.yaml
UPTEST_SKIP_IMPORT := true
UPTEST_SKIP_UPDATE := true

0 comments on commit 308aafc

Please sign in to comment.