Skip to content

Commit

Permalink
Split kustomize'd CRD files for building with "up xpkg batch"
Browse files Browse the repository at this point in the history
Signed-off-by: Alper Rifat Ulucinar <[email protected]>
  • Loading branch information
ulucinar committed Jan 12, 2024
1 parent a05ba62 commit 4d60778
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 8 deletions.
12 changes: 7 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ XPKG_REG_ORGS ?= xpkg.upbound.io/upbound
# inferred.
XPKG_REG_ORGS_NO_PROMOTE ?= xpkg.upbound.io/upbound
XPKG_DIR = $(OUTPUT_DIR)/package
XPKG_IGNORE = kustomize/*,crds/*
XPKG_IGNORE = kustomize/*,crds/kustomization.yaml,crds.yaml

export XPKG_REG_ORGS := $(XPKG_REG_ORGS)
export XPKG_REG_ORGS_NO_PROMOTE := $(XPKG_REG_ORGS_NO_PROMOTE)
Expand Down Expand Up @@ -315,10 +315,12 @@ go.mod.cachedir:
build.init: kustomize-crds

kustomize-crds: output.init
rm -fr $(OUTPUT_DIR)/package
cp -R package $(OUTPUT_DIR) && \
@$(INFO) Kustomizing CRDs...
@rm -fr $(OUTPUT_DIR)/package || $(FAIL)
@cp -R package $(OUTPUT_DIR) && \
cd $(OUTPUT_DIR)/package/crds && \
kustomize create --autodetect
kustomize build $(OUTPUT_DIR)/package/kustomize -o $(OUTPUT_DIR)/package/crds.yaml
kustomize create --autodetect || $(FAIL)
@XDG_CONFIG_HOME=$(PWD)/package kustomize build --enable-alpha-plugins $(OUTPUT_DIR)/package/kustomize -o $(OUTPUT_DIR)/package/crds.yaml || $(FAIL)
@$(OK) Kustomizing CRDs.

.PHONY: kustomize-crds
7 changes: 4 additions & 3 deletions cluster/images/provider-aws/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ batch-process: $(UP)
--build-only=$(BUILD_ONLY) \
--examples-root $(ROOT_DIR)/examples \
--examples-group-override monolith=* --examples-group-override config=providerconfig \
--auth-ext $(ROOT_DIR)/package/auth.yaml \
--crd-root $(ROOT_DIR)/package/crds \
--auth-ext $(XPKG_DIR)/auth.yaml \
--crd-root $(XPKG_DIR)/crds \
--ignore $(XPKG_IGNORE) \
--crd-group-override monolith=* --crd-group-override config=$(PROVIDER_NAME) \
--package-metadata-template $(ROOT_DIR)/package/crossplane.yaml.tmpl \
--package-metadata-template $(XPKG_DIR)/crossplane.yaml.tmpl \
--template-var XpkgRegOrg=$(XPKG_REG_ORGS) --template-var DepConstraint="$(DEP_CONSTRAINT)" --template-var ProviderName=$(PROVIDER_NAME) \
--concurrency $(CONCURRENCY) \
--push-retry 10 || $(FAIL)
Expand Down
3 changes: 3 additions & 0 deletions package/kustomize/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ patches:
target:
group: apiextensions.k8s.io
kind: CustomResourceDefinition

transformers:
- transformer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash

set -aeuo pipefail

# skip the config directory argument
shift
output_dir="$1"

temp_file="$(mktemp)"

function save_crd {
group="$(sed -nr 's/^[[:space:]]*group:[[:space:]]*(.+)/\1/p' "${temp_file}")"
plural="$(sed -nr 's/^[[:space:]]*plural:[[:space:]]*(.+)/\1/p' "${temp_file}")"
tee < "${temp_file}" "${output_dir}/${group//apiextensions.k8s.io?/}_${plural}.yaml"

# Reset the temporary file
: > "${temp_file}"
}

while IFS= read -r line || [[ -n "${line}" ]]; do
if [[ "$line" == "---" && -s "${temp_file}" ]]; then
save_crd
else
if [[ ! -s "${temp_file}" ]]; then
echo "---" >> "${temp_file}"
fi

echo "${line}" >> "${temp_file}"
fi
done

# Save the last document if there is one
if [[ -s "${temp_file}" ]]; then
save_crd
fi

function cleanup {
# Clean up the temporary file
rm "${temp_file}"
}

trap cleanup EXIT
5 changes: 5 additions & 0 deletions package/kustomize/transformer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: providers.upbound.io
kind: SplitTransformer
metadata:
name: splitter
argsOneLiner: ../crds

0 comments on commit 4d60778

Please sign in to comment.