@@ -21,21 +21,24 @@ CRD_URLS=${CRD_URLS:-}
21
21
OUTPUT_DIR=${OUTPUT_DIR:- }
22
22
KUBERNETES_CRD_GROUP_PREFIX=${KUBERNETES_CRD_GROUP_PREFIX:- }
23
23
PACKAGE_NAME=${PACKAGE_NAME:- }
24
+ CLUSTER_NAME=${CLUSTER_NAME:- " crd-model-gen" }
24
25
25
26
print_usage () {
26
27
echo " Usage: generate Java model classes from CRDs" >& 2
27
28
echo " -n: the prefix of the target CRD's api group to generate." >& 2
28
29
echo " -p: the base package name of the generated java project. " >& 2
29
30
echo " -o: output directory of the generated java project. " >& 2
30
31
echo " -u: url location of the YAML manifest to install CRDs to a Kubernetes cluster. " >& 2
32
+ echo " -c: cluster name of kind. " >& 2
31
33
}
32
34
33
- while getopts ' u:n:p:o:' flag; do
35
+ while getopts ' u:n:p:o:c: ' flag; do
34
36
case " ${flag} " in
35
37
u) CRD_URLS+=(" ${OPTARG} " ) ;;
36
38
n) KUBERNETES_CRD_GROUP_PREFIX=" ${OPTARG} " ;;
37
39
p) PACKAGE_NAME=" ${OPTARG} " ;;
38
40
o) OUTPUT_DIR=" ${OPTARG} " ;;
41
+ c) CLUSTER_NAME=" ${OPTARG} " ;;
39
42
* ) print_usage
40
43
exit 1 ;;
41
44
esac
44
47
set -e
45
48
46
49
# create a KinD cluster on the host
47
- kind create cluster
50
+ kind create cluster --name ${CLUSTER_NAME}
48
51
49
52
# install CRDs to the KinD cluster and dump the swagger spec
50
53
for url in " ${CRD_URLS[@]} " ; do
@@ -62,19 +65,19 @@ kubectl get crd -o name \
62
65
do
63
66
if [[ $( kubectl get $L -o jsonpath=' {.status.conditions[?(@.type=="NonStructuralSchema")].status}' ) == " True" ]]; then
64
67
echo " $L failed publishing openapi schema because it's attached non-structral-schema condition."
65
- kind delete cluster
68
+ kind delete cluster --name ${CLUSTER_NAME}
66
69
exit 1
67
70
fi
68
71
if [[ $( kubectl get $L -o jsonpath=' {.spec.preserveUnknownFields}' ) == " true" ]]; then
69
72
echo " $L failed publishing openapi schema because it explicitly disabled unknown fields pruning."
70
- kind delete cluster
73
+ kind delete cluster --name ${CLUSTER_NAME}
71
74
exit 1
72
75
fi
73
76
echo " $L successfully installed"
74
77
done
75
78
76
79
# destroy the KinD cluster
77
- kind delete cluster
80
+ kind delete cluster --name ${CLUSTER_NAME}
78
81
79
82
# execute the generation script
80
83
bash java-crd-cmd.sh -n " ${KUBERNETES_CRD_GROUP_PREFIX} " -p " ${PACKAGE_NAME} " -l 2 -o " ${OUTPUT_DIR} /gen" < /tmp/swagger
0 commit comments