Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use yq instead of grep to extract kind and group from CRDs #288

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Utilities/crd-extractor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ if ! command -v kubectl &> /dev/null; then
printf "please visit https://kubernetes.io/docs/tasks/tools/#kubectl to install it"
exit 1
fi
# Check if yq is installed
if ! command -v yq &> /dev/null; then
printf "yq is required for this utility, and is not installed on your machine"
printf "please visit https://github.com/mikefarah/yq#install to install it"
exit 1
fi

# Check if the pyyaml module is installed
if ! echo 'import yaml' | python3 &> /dev/null; then
Expand Down Expand Up @@ -52,8 +58,8 @@ do
filename=${crd%% *}
kubectl get crds "$filename" -o yaml > "$TMP_CRD_DIR/$filename.yaml" 2>&1

resourceKind=$(grep "kind:" "$TMP_CRD_DIR/$filename.yaml" | awk 'NR==2{print $2}' | tr '[:upper:]' '[:lower:]')
resourceGroup=$(grep "group:" "$TMP_CRD_DIR/$filename.yaml" | awk 'NR==1{print $2}')
resourceKind=$(yq -r '.spec.names.singular' "$TMP_CRD_DIR/$filename.yaml")
resourceGroup=$(yq -r '.spec.group' "$TMP_CRD_DIR/$filename.yaml")

# Save name and group for later directory organization
CRD_GROUPS["$resourceKind"]="$resourceGroup"
Expand Down