refactor: add helper functions to reduce code duplication (#76)
Reviewed-on: #76 Co-authored-by: Robert Kaussow <mail@thegeeklab.de> Co-committed-by: Robert Kaussow <mail@thegeeklab.de>
This commit is contained in:
parent
592642167d
commit
543151ff52
129
generate.sh
129
generate.sh
@ -2,6 +2,22 @@
|
|||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
shopt -s globstar
|
shopt -s globstar
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
generate_all() {
|
generate_all() {
|
||||||
export SOURCE=$1
|
export SOURCE=$1
|
||||||
|
|
||||||
@ -14,8 +30,18 @@ generate_all() {
|
|||||||
|
|
||||||
default_openapi_handler() {
|
default_openapi_handler() {
|
||||||
printf "Processing %s ...\n" $API
|
printf "Processing %s ...\n" $API
|
||||||
mkdir -p "${WORKDIR}"
|
prepare
|
||||||
curl -SsfL -o "${WORKDIR}/${NAME}.crds.yaml" "${SOURCE}"
|
(
|
||||||
|
cd "$WORKDIR"
|
||||||
|
openapi2jsonschema "${NAME}.crds.yaml" >/dev/null
|
||||||
|
)
|
||||||
|
output
|
||||||
|
generate_all "$TARGET_DIR"
|
||||||
|
}
|
||||||
|
|
||||||
|
calico_handler() {
|
||||||
|
printf "Processing %s ...\n" $API
|
||||||
|
prepare
|
||||||
(
|
(
|
||||||
cd "$WORKDIR"
|
cd "$WORKDIR"
|
||||||
openapi2jsonschema "${NAME}.crds.yaml" >/dev/null
|
openapi2jsonschema "${NAME}.crds.yaml" >/dev/null
|
||||||
@ -27,86 +53,65 @@ default_openapi_handler() {
|
|||||||
for FILE in "${WORKDIR}"/*.json; do
|
for FILE in "${WORKDIR}"/*.json; do
|
||||||
FILENAME=$(basename "$FILE")
|
FILENAME=$(basename "$FILE")
|
||||||
|
|
||||||
mv "$FILE" "$TARGET_DIR/$FILENAME"
|
mv "$FILE" "$TARGET_DIR/${FILENAME//_v1/_v3}"
|
||||||
done
|
done
|
||||||
|
|
||||||
generate_all "$TARGET_DIR"
|
generate_all "$TARGET_DIR"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flux_handler() {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
metallb_handler() {
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
|
||||||
## Calico
|
## Calico
|
||||||
API=projectcalico.org
|
API=projectcalico.org
|
||||||
|
NAME=calico
|
||||||
WORKDIR="${TMP_CRD_DIR}/calico"
|
WORKDIR="${TMP_CRD_DIR}/calico"
|
||||||
SOURCE="https://raw.githubusercontent.com/projectcalico/calico/${CALICO_VERSION}/manifests/calico.yaml"
|
SOURCE="https://raw.githubusercontent.com/projectcalico/calico/${CALICO_VERSION}/manifests/calico.yaml"
|
||||||
|
calico_handler
|
||||||
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
|
## Flux2
|
||||||
API=toolkit.fluxcd.io
|
API=toolkit.fluxcd.io
|
||||||
WORKDIR="${TMP_CRD_DIR}/flux"
|
WORKDIR="${TMP_CRD_DIR}/flux"
|
||||||
SOURCE="https://github.com/fluxcd/flux2/releases/download/${FLUXCD_VERSION}/crd-schemas.tar.gz"
|
SOURCE="https://github.com/fluxcd/flux2/releases/download/${FLUXCD_VERSION}/crd-schemas.tar.gz"
|
||||||
|
flux_handler
|
||||||
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
|
|
||||||
|
|
||||||
## Metallb
|
## Metallb
|
||||||
API=metallb.io
|
API=metallb.io
|
||||||
NAME=metallb
|
NAME=metallb
|
||||||
WORKDIR="${TMP_CRD_DIR}/$NAME"
|
WORKDIR="${TMP_CRD_DIR}/$NAME"
|
||||||
SOURCE="https://raw.githubusercontent.com/metallb/metallb/${METALLB_VERSION}/charts/metallb/charts/crds/templates/crds.yaml"
|
SOURCE="https://raw.githubusercontent.com/metallb/metallb/${METALLB_VERSION}/charts/metallb/charts/crds/templates/crds.yaml"
|
||||||
|
metallb_handler
|
||||||
printf "Processing %s ...\n" $API
|
|
||||||
mkdir -p "${WORKDIR}"
|
|
||||||
curl -SsfL -o "${WORKDIR}/${NAME}.crds.yaml" "${SOURCE}"
|
|
||||||
(
|
|
||||||
cd "$WORKDIR"
|
|
||||||
yq --inplace 'del(.spec.conversion)' "${NAME}.crds.yaml"
|
|
||||||
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"
|
|
||||||
|
|
||||||
## Cloudnative-PG
|
## Cloudnative-PG
|
||||||
API=postgresql.cnpg.io
|
API=postgresql.cnpg.io
|
||||||
|
Loading…
Reference in New Issue
Block a user