Skip to content

Commit e9c47f8

Browse files
LionelJouinjpbetz
andcommitted
Add codegen::register to hack/update-codegen.sh
Co-authored-by: Joe Betz <[email protected]> Signed-off-by: Lionel Jouin <[email protected]>
1 parent dc4fce6 commit e9c47f8

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

hack/update-codegen.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,60 @@ function codegen::conversions() {
456456
fi
457457
}
458458

459+
# Register generation
460+
#
461+
# Any package that wants register functions generated must include a
462+
# comment-tag in column 0 of one file of the form:
463+
# // +k8s:register-gen=package
464+
#
465+
function codegen::register() {
466+
# Build the tool.
467+
GOPROXY=off go install \
468+
k8s.io/code-generator/cmd/register-gen
469+
470+
# The result file, in each pkg, of register generation.
471+
local output_file="${GENERATED_FILE_PREFIX}register.go"
472+
473+
# All directories that request any form of register generation.
474+
if [[ "${DBG_CODEGEN}" == 1 ]]; then
475+
kube::log::status "DBG: finding all +k8s:register-gen tags"
476+
fi
477+
local tag_dirs=()
478+
kube::util::read-array tag_dirs < <( \
479+
grep -l --null '+k8s:register-gen=' "${ALL_K8S_TAG_FILES[@]}" \
480+
| while read -r -d $'\0' F; do dirname "${F}"; done \
481+
| sort -u)
482+
if [[ "${DBG_CODEGEN}" == 1 ]]; then
483+
kube::log::status "DBG: found ${#tag_dirs[@]} +k8s:register-gen tagged dirs"
484+
fi
485+
486+
local tag_pkgs=()
487+
for dir in "${tag_dirs[@]}"; do
488+
tag_pkgs+=("./$dir")
489+
done
490+
491+
kube::log::status "Generating register code for ${#tag_pkgs[@]} targets"
492+
if [[ "${DBG_CODEGEN}" == 1 ]]; then
493+
kube::log::status "DBG: running register-gen for:"
494+
for dir in "${tag_dirs[@]}"; do
495+
kube::log::status "DBG: $dir"
496+
done
497+
fi
498+
499+
git_find -z ':(glob)**'/"${output_file}" | xargs -0 rm -f
500+
501+
register-gen \
502+
-v "${KUBE_VERBOSE}" \
503+
--go-header-file "${BOILERPLATE_FILENAME}" \
504+
--output-file "${output_file}" \
505+
"${tag_pkgs[@]}" \
506+
"$@"
507+
508+
if [[ "${DBG_CODEGEN}" == 1 ]]; then
509+
kube::log::status "Generated register code"
510+
fi
511+
}
512+
459513
# $@: directories to exclude
460514
# example:
461515
# k8s_tag_files_except foo bat/qux

staging/src/k8s.io/code-generator/cmd/register-gen/output_tests/simpletype/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
// +k8s:register-gen=simpletype
18+
1719
// +groupName=simpletype.foo.bar
1820
package simpletype

0 commit comments

Comments
 (0)