@@ -24,55 +24,42 @@ GOFLAGS=""
2424CRD_PATH=$( dirname " ${0} " ) /../config/300-crds
2525API_PATH=$( dirname " ${0} " ) /../pkg/apis
2626
27- TEMP_DIR_LOGS= $( mktemp -d)
28-
29- for FILENAME in ` find $CRD_PATH -type f ` ;
30- do
31- echo " Gererating CRD schema for $FILENAME "
32-
33- # NOTE: APIs for the group tekton.dev are implemented under ./pkg/apis/pipeline,
34- # while the ResolutionRequest from group resolution.tekton.dev is implemented under ./ pkg/apis/resolution
35-
36- GROUP= $( grep -E ' ^ group: ' $FILENAME )
37- GROUP= ${GROUP # " group: " }
38- if [ " $GROUP " = " tekton.dev " ] ; then
39- API_SUBDIR= ' pipeline '
40- else
41- API_SUBDIR= ${GROUP % " .tekton.dev " }
42- fi
43-
27+ mapfile -d ' ' FILES < <( find " $CRD_PATH " -type f -name ' *.yaml ' -print0 )
28+ for file in " ${FILES[@]} " ; do
29+ echo " Generating CRD schema for $file "
30+ # NOTE: Workaround for https://github.com/kubernetes-sigs/controller-tools/pull/627
31+ #
32+ # Tekton splits its CRD definitions into multiple sub-packages. E.g. under
33+ # the same ` tekton.dev/v1alpha1` we find the following packages:
34+ # pkg/apis/
35+ # ├── pipeline
36+ # │ └── v1alpha1
37+ # ├── resource
38+ # │ └── v1alpha1
39+ # └── run
40+ # └── v1alpha1
41+ # This breaks controller-gen's assumption of 1 group/version -> 1 go package.
42+ # As a workaround, we patch every crd in isolation (tmp dir) with the correct
43+ # API sub dir path.
4444 TEMP_DIR=$( mktemp -d)
45- cp -p $FILENAME $TEMP_DIR /.
46- LOG_FILE=$TEMP_DIR_LOGS /log-schema-generation-$( basename $FILENAME )
47-
48- counter=0 limit=10
49- while [ " $counter " -lt " $limit " ]; do
50- # FIXME:(burigolucas): add schema for fields with generic type once supported by controller-tools
51- # FIXME:(burigolucas): add schema for recursive fields once supported by controller-tools
52- # FIXME:(burigolucas): add reference for dependent external/internal schemas once supported in CRD specification
53- # FIXME:(burigolucas): controller-gen return status 1 with message "Error: not all generators ran successfully"
54- set +e
55- go run sigs.k8s.io/controller-tools/cmd/controller-gen@v0.17.1 \
56- schemapatch:manifests=$TEMP_DIR ,generateEmbeddedObjectMeta=false \
57- output:dir=$CRD_PATH \
58- paths=$API_PATH /$API_SUBDIR /... > $LOG_FILE 2>&1
59- rc=$?
60- set -e
61- if [ $rc -eq 0 ]; then
62- break
63- fi
64- if grep -q ' exit status 1' $LOG_FILE ; then
65- echo " [WARNING] Ignoring errors/warnings from CRD schema generation, check $LOG_FILE for details"
66- break
67- fi
68- counter=" $(( $counter + 1 )) "
69- if [ $counter -eq $limit ]; then
70- echo " [ERROR] Failed to generate CRD schema"
71- exit 1
72- fi
73- done
45+ cp -p " $file " " $TEMP_DIR "
46+ case " $( basename " $file " | tr ' [:upper:]' ' [:lower:]' ) " in
47+ * customrun* )
48+ API_SUBDIR=" run" ;;
49+ * resolutionrequest* )
50+ API_SUBDIR=" resolution" ;;
51+ * )
52+ API_SUBDIR=" pipeline" ;;
53+ esac
7454
75- rm -rf $TEMP_DIR
55+ # FIXME:(burigolucas): add schema for fields with generic type once supported by controller-tools
56+ # FIXME:(burigolucas): add schema for recursive fields once supported by controller-tools
57+ # FIXME:(burigolucas): add reference for dependent external/internal schemas once supported in CRD specification
58+ go run sigs.k8s.io/controller-tools/cmd/controller-gen@v0.18.0 \
59+ schemapatch:manifests=" $TEMP_DIR " ,generateEmbeddedObjectMeta=false \
60+ output:dir=" $CRD_PATH " \
61+ paths=" $API_PATH /$API_SUBDIR /..."
62+ rm -rf " $TEMP_DIR "
7663done
7764
7865GOFLAGS=" ${OLDGOFLAGS} "
0 commit comments