crds-catalog/generate.sh
Robert Kaussow 3916c8b01e
All checks were successful
continuous-integration/drone/pr Build is passing
feat: generate multi-schema files for each API resource
2023-11-20 21:26:30 +01:00

112 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
set -eo pipefail
shopt -s globstar
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
}
default_openapi_handler() {
printf "Processing %s ...\n" $API
mkdir -p "${WORKDIR}"
curl -SsfL -o "${WORKDIR}/${NAME}.crds.yaml" "${SOURCE}"
(
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")
mv "$FILE" "$TARGET_DIR/$FILENAME"
done
generate_all "$TARGET_DIR"
}
## Calico
API=projectcalico.org
WORKDIR="${TMP_CRD_DIR}/calico"
SOURCE="https://raw.githubusercontent.com/projectcalico/calico/${CALICO_VERSION}/manifests/calico.yaml"
printf "Processing %s ...\n" $API
mkdir -p "${WORKDIR}"
curl -SsfL -o "${WORKDIR}/calico.crds.yaml" "${SOURCE}"
(
cd "$WORKDIR"
openapi2jsonschema "calico.crds.yaml" >/dev/null
)
TARGET_DIR="$DIST/$API"
mkdir -p "$TARGET_DIR"
for FILE in "${WORKDIR}"/*.json; do
FILENAME=$(basename "$FILE")
mv "$FILE" "$TARGET_DIR/${FILENAME//_v1/_v3}"
done
generate_all "$TARGET_DIR"
## Flux2
API=toolkit.fluxcd.io
WORKDIR="${TMP_CRD_DIR}/flux"
SOURCE="https://github.com/fluxcd/flux2/releases/download/${FLUXCD_VERSION}/crd-schemas.tar.gz"
printf "Processing %s ...\n" $API
mkdir -p "${WORKDIR}"
curl -SsfL "${SOURCE}" | tar xz -C "${WORKDIR}"
for FILE in "${WORKDIR}"/*.json; do
FILENAME=$(basename "$FILE")
PREFIX="${FILENAME%%\-*}"
MIDDLE="${FILENAME#*-}"
SUFFIX="${MIDDLE#*-}"
MIDDLE="${MIDDLE%%\-*}"
TARGET_DIR="$DIST/$MIDDLE.$API"
TARGET_NAME="$TARGET_DIR/$PREFIX""_""$SUFFIX"
mkdir -p "$TARGET_DIR"
mv "$FILE" "$TARGET_NAME"
generate_all "$TARGET_DIR"
done
## Cloudnative-PG
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"
default_openapi_handler
## Cert-Manager
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"
default_openapi_handler
## Minio
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"
default_openapi_handler
# K8up
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"
default_openapi_handler