From 2ae75618619866c988cf4b76cdad930ce60e4e78 Mon Sep 17 00:00:00 2001 From: Spencer Small Date: Fri, 15 Mar 2024 11:59:32 -0700 Subject: [PATCH 1/2] Use yq instead of grep to extract kind and group from CRDs This fixes https://github.com/datreeio/CRDs-catalog/issues/287 --- Utilities/crd-extractor.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Utilities/crd-extractor.sh b/Utilities/crd-extractor.sh index 52f9481a..49ae8cb7 100755 --- a/Utilities/crd-extractor.sh +++ b/Utilities/crd-extractor.sh @@ -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 @@ -50,10 +56,10 @@ NUM_OF_CRDS=0 while read -r crd do filename=${crd%% *} - kubectl get crds "$filename" -o yaml > "$TMP_CRD_DIR/$filename.yaml" 2>&1 + kubectl get crds "$filename" -o yaml > "$TMP_CRD_DIR/$filename.yaml" 2>&1q - 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" From aa9f7cbbd1ffda5be8b209e94205a6b17731ebef Mon Sep 17 00:00:00 2001 From: Spencer Small <641091+ssmall@users.noreply.github.com> Date: Mon, 8 Jul 2024 10:07:04 -0700 Subject: [PATCH 2/2] fix typo Co-authored-by: Sean Poulter <98067886+seanpoulter-foci@users.noreply.github.com> --- Utilities/crd-extractor.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Utilities/crd-extractor.sh b/Utilities/crd-extractor.sh index 49ae8cb7..3f36e13d 100755 --- a/Utilities/crd-extractor.sh +++ b/Utilities/crd-extractor.sh @@ -56,7 +56,7 @@ NUM_OF_CRDS=0 while read -r crd do filename=${crd%% *} - kubectl get crds "$filename" -o yaml > "$TMP_CRD_DIR/$filename.yaml" 2>&1q + kubectl get crds "$filename" -o yaml > "$TMP_CRD_DIR/$filename.yaml" 2>&1 resourceKind=$(yq -r '.spec.names.singular' "$TMP_CRD_DIR/$filename.yaml") resourceGroup=$(yq -r '.spec.group' "$TMP_CRD_DIR/$filename.yaml")