From ea284ca60dda453329ab621c02d62b7e723d94c7 Mon Sep 17 00:00:00 2001 From: hadar-co Date: Wed, 17 Aug 2022 17:32:27 +0300 Subject: [PATCH] fix: ignore warnings in get crd output (#38) --- Utilities/crd-extractor.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Utilities/crd-extractor.sh b/Utilities/crd-extractor.sh index 9505d347..24073744 100755 --- a/Utilities/crd-extractor.sh +++ b/Utilities/crd-extractor.sh @@ -40,11 +40,11 @@ do ResourceKind=${crd%%.*} kubectl get crds ${crd} -o yaml > "$TMP_CRD_DIR/${ResourceKind}.yaml" 2>&1 let NUM_OF_CRDS++ -done < <(kubectl get crds 2>&1 | tail -n +2) +done < <(kubectl get crds 2>&1 | sed -n '/NAME/,$p' | tail -n +2) # If no CRDs exist in the cluster, exit if [ $NUM_OF_CRDS == 0 ]; then - printf "No CRDs found in your cluster, exiting...\n" + printf "No CRDs found in the cluster, exiting...\n" exit 0 fi @@ -58,6 +58,7 @@ cd $SCHEMAS_DIR # Convert crds to jsonSchema python3 $TMP_CRD_DIR/openapi2jsonschema.py $TMP_CRD_DIR/*.yaml +conversionResult=$? # Copy and rename files to support kubeval rm -rf $SCHEMAS_DIR/master-standalone @@ -69,11 +70,11 @@ CYAN='\033[0;36m' GREEN='\033[0;32m' NC='\033[0m' # No Color -if [ $? == 0 ]; then +if [ $conversionResult == 0 ]; then printf "${GREEN}Successfully converted $NUM_OF_CRDS CRDs to JSON schema${NC}\n" printf "\nTo validate a CR using various tools, run the relevant command:\n" - printf "\n- ${CYAN}datree:${NC}\n\$ datree test --schema-location '$HOME/.datree/crdSchemas/{{ .ResourceKind }}_{{ .ResourceAPIVersion }}.json' /path/to/file\n\n" + printf "\n- ${CYAN}datree:${NC}\n\$ datree test --schema-location '$HOME/.datree/crdSchemas/{{ .ResourceKind }}_{{ .ResourceAPIVersion }}.json' /path/to/file\n" printf "\n- ${CYAN}kubeconform:${NC}\n\$ kubeconform -summary -output json -schema-location default -schema-location '$HOME/.datree/crdSchemas/{{ .ResourceKind }}_{{ .ResourceAPIVersion }}.json' /path/to/file\n" printf "\n- ${CYAN}kubeval:${NC}\n\$ kubeval --additional-schema-locations file:\"$HOME/.datree/crdSchemas\" /path/to/file\n\n" fi