1
0
mirror of https://github.com/openshift/installer.git synced 2026-02-05 15:47:14 +01:00

CORS-3295: hack: add script to verify capi CRDs (#8106)

* CORS-3295: hack: add script to verify capi CRDs

This script will be used to create a test in CI to check that the capi
CRDs in data/data/cluster-api match what's expected from the provider
version used in cluster-api/providers.

As a side effect, this script can be used to generate the CRD, allowing
a dev to then commit the result.

* hack: add capi CRD generation to verify-capi-manifests script

* hack/verify-capi-manifests: use Golang 1.22 image

* hack: add azureaso to the manifest generation

Although we are not technically generating the manifest, only
downloading it from the upstream repo.

* data/data/cluster-api: reconcile CRDs differences

This is the diff generated by running `hack/verify-capi-manifests.sh`
This commit is contained in:
Rafael F.
2025-01-15 12:14:41 +01:00
committed by GitHub
parent 2fed4eddd7
commit cbcd65fa6b
6 changed files with 22145 additions and 4513 deletions

85
hack/verify-capi-manifests.sh Executable file
View File

@@ -0,0 +1,85 @@
#!/bin/bash
MANIFESTS_DIR="/go/src/github.com/openshift/installer/data/data/cluster-api"
generate_capi_manifest() {
provider="$(basename "$1")"
echo "Generating ${provider} manifest"
pushd "$1"
# Parse provider module URL and revision
# Workaround the import path for azure-service-operator being different from the module path
provider_go_module="$(grep _ tools.go | awk '{ print $2 }' | sed 's|"||g' | sed 's|/cmd/controller$||g')"
mod_info="$(go mod download -json "${provider_go_module}")"
popd
version="$(echo "${mod_info}" | jq '.Version' | sed 's|"||g')"
info_path="$(echo "${mod_info}" | jq '.Info' | sed 's|"||g')"
repo_origin="$(jq '.Origin.URL' "${info_path}" | sed 's|"||g')"
revision="$(jq '.Origin.Hash' "${info_path}" | sed 's|"||g')"
if [ "${provider}" = "azureaso" ]; then
# Just copy the CRD from upstream
curl -fSsL "https://github.com/Azure/azure-service-operator/releases/download/${version}/azureserviceoperator_${version}.yaml" -o "${MANIFESTS_DIR}/${provider}-infrastructure-components.yaml"
echo "---" >>"${MANIFESTS_DIR}/${provider}-infrastructure-components.yaml"
curl -fSsL "https://github.com/Azure/azure-service-operator/releases/download/${version}/azureserviceoperator_customresourcedefinitions_${version}.yaml" >>"${MANIFESTS_DIR}/${provider}-infrastructure-components.yaml"
else
# Generate provider manifest from specified revision
clone_path="$(mktemp -d)"
git clone "${repo_origin}" "${clone_path}"
pushd "${clone_path}"
git checkout "${revision}"
case "${provider}" in
vsphere)
make release-manifests-all
;;
*)
make release-manifests
;;
esac
case "${provider}" in
cluster-api)
cp out/cluster-api-components.yaml "${MANIFESTS_DIR}/core-components.yaml"
;;
*)
cp out/infrastructure-components.yaml "${MANIFESTS_DIR}/${provider}-infrastructure-components.yaml"
;;
esac
popd
rm -rf "${clone_path}"
fi
}
if [ "$IS_CONTAINER" != "" ]; then
set -eux
# Install `jq` if not present
if ! command -v jq; then
curl -L https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux-amd64 -o /usr/bin/jq
chmod u+x /usr/bin/jq
fi
# Silence git hints and advices
git config --global init.defaultBranch master
git config --global advice.detachedHead false
if [ $# -gt 0 ]; then
for target in "${@}"; do
generate_capi_manifest "${target}"
done
else
find cluster-api/providers -maxdepth 1 -mindepth 1 -type d -print0 | while read -r -d '' dir; do
generate_capi_manifest "${dir}"
done
generate_capi_manifest "cluster-api/cluster-api"
fi
git diff --exit-code
else
podman run --rm \
--env IS_CONTAINER=TRUE \
--volume "${PWD}:/go/src/github.com/openshift/installer:z" \
--workdir /go/src/github.com/openshift/installer \
docker.io/golang:1.22 \
./hack/verify-capi-manifests.sh "${@}"
fi