@@ -24,55 +24,44 @@ 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+ # collect all existing crds into the FILES array using the recommended
28+ # mapfile: https://www.shellcheck.net/wiki/SC2207
29+ mapfile -d ' ' FILES < <( find " $CRD_PATH " -type f -name ' *.yaml' -print0)
30+ for file in " ${FILES[@]} " ; do
31+ echo " Generating CRD schema for $file "
32+ # NOTE: Workaround for https://github.com/kubernetes-sigs/controller-tools/pull/627
33+ #
34+ # Tekton splits its CRD definitions into multiple sub-packages. E.g. under
35+ # the same `tekton.dev/v1alpha1` we find the following packages:
36+ # pkg/apis/
37+ # ├── pipeline
38+ # │ └── v1alpha1
39+ # ├── resource
40+ # │ └── v1alpha1
41+ # └── run
42+ # └── v1alpha1
43+ # This breaks controller-gen's assumption of 1 group/version -> 1 go package.
44+ # As a workaround, we patch every crd in isolation (tmp dir) with the correct
45+ # API sub dir path.
4446 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/
[email protected] \
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
47+ cp -p " $file " " $TEMP_DIR "
48+ case " $( basename " $file " | tr ' [:upper:]' ' [:lower:]' ) " in
49+ * customrun* )
50+ API_SUBDIR=" run" ;;
51+ * resolutionrequest* )
52+ API_SUBDIR=" resolution" ;;
53+ * )
54+ API_SUBDIR=" pipeline" ;;
55+ esac
7456
75- rm -rf $TEMP_DIR
57+ # FIXME:(burigolucas): add schema for fields with generic type once supported by controller-tools
58+ # FIXME:(burigolucas): add schema for recursive fields once supported by controller-tools
59+ # FIXME:(burigolucas): add reference for dependent external/internal schemas once supported in CRD specification
60+ go run sigs.k8s.io/controller-tools/cmd/
[email protected] \
61+ schemapatch:manifests=" $TEMP_DIR " ,generateEmbeddedObjectMeta=false \
62+ output:dir=" $CRD_PATH " \
63+ paths=" $API_PATH /$API_SUBDIR /..."
64+ rm -rf " $TEMP_DIR "
7665done
7766
7867GOFLAGS=" ${OLDGOFLAGS} "
0 commit comments