Skip to content

Commit a80f0a4

Browse files
author
hadar-co
authored
Merge pull request #8 from datreeio/extractor-fixes
script fixes
2 parents db6ef1d + 64376fd commit a80f0a4

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

crd-extractor/crd-extractor

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ do
2626
let NUM_OF_CRDS++
2727
done < <(kubectl get crds 2>&1 | tail -n +2)
2828

29+
# If no CRDs exist in the cluster, exit
30+
if [ $NUM_OF_CRDS == 0 ]; then
31+
printf "No CRDs found in your cluster, exiting...\n"
32+
exit 0
33+
fi
34+
2935
# Download converter script
3036
curl https://raw.githubusercontent.com/yannh/kubeconform/master/scripts/openapi2jsonschema.py --output $TMP_CRD_DIR/openapi2jsonschema.py 2>/dev/null
3137

@@ -37,12 +43,16 @@ cd $SCHEMAS_DIR
3743
# Convert crds to jsonSchema
3844
python3 $TMP_CRD_DIR/openapi2jsonschema.py $TMP_CRD_DIR/*.yaml
3945

46+
CYAN='\033[0;36m'
47+
GREEN='\033[0;32m'
48+
NC='\033[0m' # No Color
49+
4050
if [ $? == 0 ]; then
41-
printf "Successfully converted $NUM_OF_CRDS CRDs to JSON schema\n"
51+
printf "${GREEN}Successfully converted $NUM_OF_CRDS CRDs to JSON schema${NC}\n"
4252

4353
printf "\nTo validate a CR using various tools, run the relevant command:\n"
44-
printf "\n- kubeconform:\n\$kubeconform -summary -output json -schema-location default -schema-location '$HOME/.datree/crdSchemas/{{ .ResourceKind }}_{{ .ResourceAPIVersion }}.json' /path/to/file\n"
45-
printf "\n- datree:\n\$datree test --schema-location $HOME/.datree/crdSchemas/{{ .ResourceKind }}_{{ .ResourceAPIVersion }}.json /path/to/file\n\n"
54+
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"
55+
printf "\n- ${CYAN}datree:${NC}\n\$ datree test --schema-location $HOME/.datree/crdSchemas/{{ .ResourceKind }}_{{ .ResourceAPIVersion }}.json /path/to/file\n\n"
4656
fi
4757

4858
rm -rf $TMP_CRD_DIR

0 commit comments

Comments
 (0)