Skip to content

Commit

Permalink
fix: ignore warnings in get crd output (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
hadar-co authored Aug 17, 2022
1 parent d9edc6c commit ea284ca
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Utilities/crd-extractor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ea284ca

Please sign in to comment.