2023-03-08 11:54:34 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -eo pipefail
|
|
|
|
shopt -s globstar
|
|
|
|
|
2024-03-26 12:18:00 +00:00
|
|
|
prepare() {
|
|
|
|
mkdir -p "${WORKDIR}"
|
|
|
|
curl -SsfL -o "${WORKDIR}/${NAME}.crds.yaml" "${SOURCE}"
|
|
|
|
}
|
|
|
|
|
|
|
|
output() {
|
|
|
|
TARGET_DIR="$DIST/$API"
|
|
|
|
mkdir -p "$TARGET_DIR"
|
|
|
|
|
|
|
|
for FILE in "${WORKDIR}"/*.json; do
|
|
|
|
FILENAME=$(basename "$FILE")
|
|
|
|
|
|
|
|
mv "$FILE" "$TARGET_DIR/$FILENAME"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2023-11-20 20:40:07 +00:00
|
|
|
generate_all() {
|
|
|
|
export SOURCE=$1
|
|
|
|
|
|
|
|
export TYPE=anyOf
|
|
|
|
gomplate -d source=env:SOURCE -d type=env:TYPE -o "$SOURCE/all-$TYPE.json" -f templates/all.json.tmpl
|
|
|
|
|
|
|
|
export TYPE=oneOf
|
|
|
|
gomplate -d source=env:SOURCE -d type=env:TYPE -o "$SOURCE/all-$TYPE.json" -f templates/all.json.tmpl
|
|
|
|
}
|
|
|
|
|
2024-04-02 12:57:12 +00:00
|
|
|
exec_openapi() {
|
|
|
|
printf "Processing %s ...\n" "$1"
|
2024-03-26 12:18:00 +00:00
|
|
|
prepare
|
|
|
|
(
|
|
|
|
cd "$WORKDIR"
|
|
|
|
openapi2jsonschema "${NAME}.crds.yaml" >/dev/null
|
|
|
|
)
|
|
|
|
output
|
|
|
|
generate_all "$TARGET_DIR"
|
|
|
|
}
|
|
|
|
|
|
|
|
calico_handler() {
|
2024-04-02 12:57:12 +00:00
|
|
|
API=projectcalico.org
|
|
|
|
NAME=calico
|
|
|
|
WORKDIR="${TMP_CRD_DIR}/calico"
|
|
|
|
SOURCE="https://raw.githubusercontent.com/projectcalico/calico/${CALICO_VERSION}/manifests/calico.yaml"
|
|
|
|
|
2024-03-26 12:18:00 +00:00
|
|
|
printf "Processing %s ...\n" $API
|
|
|
|
prepare
|
2023-03-08 11:54:34 +00:00
|
|
|
(
|
|
|
|
cd "$WORKDIR"
|
|
|
|
openapi2jsonschema "${NAME}.crds.yaml" >/dev/null
|
|
|
|
)
|
|
|
|
|
|
|
|
TARGET_DIR="$DIST/$API"
|
|
|
|
mkdir -p "$TARGET_DIR"
|
|
|
|
|
|
|
|
for FILE in "${WORKDIR}"/*.json; do
|
|
|
|
FILENAME=$(basename "$FILE")
|
|
|
|
|
2024-03-26 12:18:00 +00:00
|
|
|
mv "$FILE" "$TARGET_DIR/${FILENAME//_v1/_v3}"
|
2023-03-08 11:54:34 +00:00
|
|
|
done
|
2023-11-20 20:40:07 +00:00
|
|
|
|
|
|
|
generate_all "$TARGET_DIR"
|
2023-03-08 11:54:34 +00:00
|
|
|
}
|
|
|
|
|
2024-03-26 12:18:00 +00:00
|
|
|
flux_handler() {
|
2024-04-02 12:57:12 +00:00
|
|
|
API=toolkit.fluxcd.io
|
|
|
|
WORKDIR="${TMP_CRD_DIR}/flux"
|
|
|
|
SOURCE="https://github.com/fluxcd/flux2/releases/download/${FLUXCD_VERSION}/crd-schemas.tar.gz"
|
|
|
|
|
2024-03-26 12:18:00 +00:00
|
|
|
printf "Processing %s ...\n" $API
|
|
|
|
mkdir -p "${WORKDIR}"
|
|
|
|
curl -SsfL "${SOURCE}" | tar xz -C "${WORKDIR}"
|
2023-03-08 11:54:34 +00:00
|
|
|
|
2024-03-26 12:18:00 +00:00
|
|
|
for FILE in "${WORKDIR}"/*.json; do
|
|
|
|
FILENAME=$(basename "$FILE")
|
|
|
|
PREFIX="${FILENAME%%\-*}"
|
|
|
|
MIDDLE="${FILENAME#*-}"
|
|
|
|
SUFFIX="${MIDDLE#*-}"
|
|
|
|
MIDDLE="${MIDDLE%%\-*}"
|
2023-03-08 11:54:34 +00:00
|
|
|
|
2024-03-26 12:18:00 +00:00
|
|
|
TARGET_DIR="$DIST/$MIDDLE.$API"
|
|
|
|
TARGET_NAME="$TARGET_DIR/$PREFIX""_""$SUFFIX"
|
2023-03-08 11:54:34 +00:00
|
|
|
|
2024-03-26 12:18:00 +00:00
|
|
|
mkdir -p "$TARGET_DIR"
|
|
|
|
mv "$FILE" "$TARGET_NAME"
|
2023-03-08 11:54:34 +00:00
|
|
|
|
2024-03-26 12:18:00 +00:00
|
|
|
generate_all "$TARGET_DIR"
|
|
|
|
done
|
|
|
|
}
|
2023-03-08 11:54:34 +00:00
|
|
|
|
2024-03-26 12:18:00 +00:00
|
|
|
metallb_handler() {
|
2024-04-02 12:57:12 +00:00
|
|
|
API=metallb.io
|
|
|
|
NAME=metallb
|
|
|
|
WORKDIR="${TMP_CRD_DIR}/$NAME"
|
|
|
|
SOURCE="https://raw.githubusercontent.com/metallb/metallb/${METALLB_VERSION}/charts/metallb/charts/crds/templates/crds.yaml"
|
|
|
|
|
2024-03-26 12:18:00 +00:00
|
|
|
printf "Processing %s ...\n" $API
|
|
|
|
prepare
|
|
|
|
(
|
|
|
|
cd "$WORKDIR"
|
|
|
|
yq --inplace 'del(.spec.conversion)' "${NAME}.crds.yaml"
|
|
|
|
openapi2jsonschema "${NAME}.crds.yaml" >/dev/null
|
|
|
|
)
|
|
|
|
output
|
|
|
|
generate_all "$TARGET_DIR"
|
|
|
|
}
|
|
|
|
|
2024-04-02 13:00:03 +00:00
|
|
|
objectbucket_handler() {
|
|
|
|
API=objectbucket.io
|
|
|
|
NAME=objectbucket
|
|
|
|
WORKDIR="${TMP_CRD_DIR}/$NAME"
|
|
|
|
SOURCE="https://github.com/kube-object-storage/lib-bucket-provisioner/archive/refs/tags/kubernetes-v1.14.1.tar.gz"
|
|
|
|
|
|
|
|
printf "Processing %s ...\n" $API
|
|
|
|
mkdir -p "${WORKDIR}"
|
|
|
|
curl -SsfL "${SOURCE}" | tar xz -C "${WORKDIR}" --strip-components=1
|
|
|
|
(
|
|
|
|
cd "$WORKDIR"
|
|
|
|
for FILE in "${WORKDIR}"/deploy/crds/*crd.yaml; do
|
|
|
|
openapi2jsonschema "${FILE}" >/dev/null
|
|
|
|
done
|
|
|
|
)
|
|
|
|
|
|
|
|
output
|
|
|
|
generate_all "$TARGET_DIR"
|
|
|
|
}
|
|
|
|
|
2024-04-02 12:57:12 +00:00
|
|
|
cnpg_handler() {
|
|
|
|
API=postgresql.cnpg.io
|
|
|
|
NAME=cnpg
|
|
|
|
WORKDIR="${TMP_CRD_DIR}/$NAME"
|
|
|
|
SOURCE="https://github.com/cloudnative-pg/cloudnative-pg/releases/download/${CNPG_VERSION}/cnpg-${CNPG_VERSION##v}.yaml"
|
|
|
|
|
|
|
|
exec_openapi $API
|
|
|
|
}
|
|
|
|
|
|
|
|
certmanager_handler() {
|
|
|
|
API=cert-manager.io
|
|
|
|
NAME=cert-manager
|
|
|
|
WORKDIR="${TMP_CRD_DIR}/$NAME"
|
|
|
|
SOURCE="https://github.com/cert-manager/cert-manager/releases/download/${CERTMANAGER_VERSION}/cert-manager.crds.yaml"
|
|
|
|
|
|
|
|
exec_openapi $API
|
|
|
|
}
|
|
|
|
|
|
|
|
minio_handler() {
|
|
|
|
API=minio.min.io
|
|
|
|
NAME=minio
|
|
|
|
WORKDIR="${TMP_CRD_DIR}/$NAME"
|
|
|
|
SOURCE="https://raw.githubusercontent.com/minio/operator/${MINIO_VERSION}/resources/base/crds/minio.min.io_tenants.yaml"
|
|
|
|
|
|
|
|
exec_openapi $API
|
|
|
|
}
|
|
|
|
|
|
|
|
k8up_handler() {
|
|
|
|
API=k8up.io
|
|
|
|
NAME=k8up
|
|
|
|
WORKDIR="${TMP_CRD_DIR}/$NAME"
|
|
|
|
SOURCE="https://github.com/k8up-io/k8up/releases/download/k8up-${K8UP_VERSION}/k8up-crd.yaml"
|
|
|
|
|
|
|
|
exec_openapi $API
|
|
|
|
}
|
|
|
|
|
|
|
|
handlers=(
|
|
|
|
calico_handler
|
|
|
|
flux_handler
|
|
|
|
metallb_handler
|
2024-04-02 13:00:03 +00:00
|
|
|
objectbucket_handler
|
2024-04-02 12:57:12 +00:00
|
|
|
cnpg_handler
|
|
|
|
certmanager_handler
|
|
|
|
minio_handler
|
|
|
|
k8up_handler
|
|
|
|
)
|
|
|
|
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
for handler in "${handlers[@]}"; do
|
|
|
|
"$handler"
|
|
|
|
done
|
|
|
|
else
|
|
|
|
"$1"_handler
|
|
|
|
fi
|