File tree Expand file tree Collapse file tree 1 file changed +10
-14
lines changed
Expand file tree Collapse file tree 1 file changed +10
-14
lines changed Original file line number Diff line number Diff line change 4747
4848# Extract CRDs from cluster
4949NUM_OF_CRDS=0
50- while read -r crd
50+ while read -r crd
5151do
52- resourceKind=${crd%% * }
53- kubectl get crds " $resourceKind " -o yaml > " $TMP_CRD_DIR /" $resourceKind " .yaml" 2>&1
54-
55- # Get singular name from crd
56- singularNameValue=$( grep singular: " $TMP_CRD_DIR /" $resourceKind " .yaml" -m 1)
57- singularName=${singularNameValue##* }
58-
59- # Get group
60- resourceGroup=${resourceKind#* .}
52+ filename=${crd%% * }
53+ kubectl get crds " $filename " -o yaml > " $TMP_CRD_DIR /$filename .yaml" 2>&1
54+
55+ resourceKind=$( grep " kind:" " $TMP_CRD_DIR /$filename .yaml" | awk ' NR==2{print $2}' | tr ' [:upper:]' ' [:lower:]' )
56+ resourceGroup=$( grep " group:" " $TMP_CRD_DIR /$filename .yaml" | awk ' NR==1{print $2}' )
6157
6258 # Save name and group for later directory organization
63- CRD_GROUPS[" $singularName " ]=" $resourceGroup "
64-
65- let NUM_OF_CRDS++
59+ CRD_GROUPS[" $resourceKind " ]=" $resourceGroup "
60+
61+ let ++NUM_OF_CRDS
6662done < <( kubectl get crds 2>&1 | sed -n ' /NAME/,$p' | tail -n +2)
6763
6864# If no CRDs exist in the cluster, exit
@@ -102,7 +98,7 @@ NC='\033[0m' # No Color
10298
10399if [ $conversionResult == 0 ]; then
104100 printf " ${GREEN} Successfully converted $NUM_OF_CRDS CRDs to JSON schema${NC} \n"
105-
101+
106102 printf " \nTo validate a CR using various tools, run the relevant command:\n"
107103 printf " \n- ${CYAN} datree:${NC} \n\$ datree test /path/to/file\n"
108104 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"
You can’t perform that action at this time.
0 commit comments