-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #202 from kukacz/custom-crd-script
Fixed crd_to_kcl.sh to work with latest kcl import structure
- Loading branch information
Showing
1 changed file
with
31 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,59 @@ | ||
#!/bin/bash | ||
|
||
if [ "$#" -ne 1 ]; then | ||
echo "Usage: $0 <github-repo-url>" | ||
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then | ||
echo "Usage: $0 <github-repo-url> <version-tag>" | ||
exit 1 | ||
fi | ||
|
||
REPO_URL="$1" | ||
VER="$2" | ||
|
||
REPO_URL_SUFFIX=$(echo $REPO_URL | sed -n 's|.*github.com/||p') | ||
OWNER=$(echo $REPO_URL_SUFFIX | cut -d '/' -f 1) | ||
REPO=$(echo $REPO_URL_SUFFIX | cut -d '/' -f 2) | ||
[ -z "$VER" ] && REPOVER="$REPO" || REPOVER="$REPO@$VER" | ||
|
||
export KCL_FAST_EVAL=1 | ||
|
||
if [ -z "$OWNER" ] || [ -z "$REPO" ]; then | ||
echo "Invalid GitHub repository URL." | ||
exit 1 | ||
fi | ||
|
||
# Init the kcl module | ||
kcl mod init $REPO | ||
if [ -z "$VER" ]; then | ||
kcl mod init $REPO | ||
else | ||
kcl mod init $REPO --version $VER | ||
fi | ||
|
||
cd $REPO | ||
|
||
# Get the Kubernetes CRD files | ||
wget "https://doc.crds.dev/raw/github.com/$OWNER/$REPO" | ||
wget "https://doc.crds.dev/raw/github.com/$OWNER/$REPOVER" | ||
mkdir -p crds | ||
mv $REPO crds/$REPO.yaml | ||
mv $REPOVER crds/$REPO.yaml | ||
|
||
# Import Kubernetes CRD to KCL files | ||
kcl import -m crd -s ./crds/** | ||
rm -rf main.k | ||
|
||
# Add the k8s dependency | ||
kcl mod add k8s | ||
rm -rf models/k8s | ||
|
||
models_dir="models" | ||
regex="^(.*)_(v[0-9]+(alpha[0-9]+|beta[0-9]+)?)(.*)$" | ||
rm -rf main.k models/{k8s,kcl.mod} | ||
|
||
if [ ! -d "$models_dir" ]; then | ||
echo "The directory '$models_dir' does not exist." | ||
exit 1 | ||
fi | ||
|
||
cd "$models_dir" | ||
|
||
for file in *; do | ||
if [ -f "$file" ]; then | ||
if [[ $file =~ $regex ]]; then | ||
version="${BASH_REMATCH[2]}" | ||
mkdir -p "../$version" | ||
mv "$file" "../$version/" | ||
else | ||
echo "File '$file' does not contain a version number." | ||
fi | ||
fi | ||
done | ||
|
||
cd - | ||
echo "Files have been grouped by version." | ||
rm -rf models | ||
# Check KCL runs | ||
for version_dir in *; do | ||
if [ -d "$version_dir" ]; then | ||
echo "Contents of '$version_dir':" | ||
kcl run ./$version_dir | ||
for version_dir in models/*/; do | ||
if [ $(basename $version_dir) == "unknown" ]; then | ||
rm -rf $version_dir | ||
continue | ||
fi | ||
echo "Contents of '$version_dir':" | ||
kcl run $version_dir | ||
mv $version_dir . | ||
done | ||
echo "Files have been grouped and listed by version." | ||
echo "Files have been listed by version." | ||
|
||
rmdir models || exit 1 | ||
|
||
kcl doc generate | ||
mv ./docs/*.md README.md |